Skip to content

Commit

Permalink
Merge branch 'testing-nina' of https://github.com/CS342/2024-Intake i…
Browse files Browse the repository at this point in the history
…nto testing-nina
  • Loading branch information
ninaboord committed Mar 14, 2024
2 parents 8fe6ece + 7a96aba commit c7f8c61
Show file tree
Hide file tree
Showing 16 changed files with 247 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziMedication.git",
"state" : {
"revision" : "95ca9aebbd23f3842639d6e322785a0ff3620aac",
"version" : "0.4.0"
"revision" : "03d82c275be588970eda4d5ab335609a8260014b",
"version" : "0.4.1"
}
},
{
Expand Down
11 changes: 0 additions & 11 deletions Intake/Allergy Records/AllergyRecords.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ import SpeziLLM
import SpeziLLMOpenAI
import SwiftUI

struct AllergyItem: Identifiable, Equatable {
let id = UUID()
var allergy: String
var reaction: [ReactionItem]

static func == (lhs: AllergyItem, rhs: AllergyItem) -> Bool {
lhs.allergy == rhs.allergy
}
}


struct ChatButton: View {
// Use @Binding to create a two-way binding to the parent view's showingChat state
@Binding var showingChat: Bool
Expand Down
5 changes: 0 additions & 5 deletions Intake/Allergy Records/ReactionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import Foundation
import SpeziFHIR
import SwiftUI

struct ReactionItem: Identifiable {
var id = UUID()
var reaction: String
}

struct ReactionView: View {
@State private var reactionRecords: [ReactionItem]
@State private var name: String
Expand Down
79 changes: 55 additions & 24 deletions Intake/Export/ExportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ struct ExportView: View {
print("PDF data changed")
}
}

@ViewBuilder
// swiftlint:disable attributes
private var wrappedBody: some View {
VStack {
Text("MEDICAL HISTORY").fontWeight(.bold)
VStack(alignment: .leading) {
Text("MEDICAL HISTORY")
.fontWeight(.bold)

Spacer()
.frame(height: 20)
Expand All @@ -78,7 +80,7 @@ struct ExportView: View {
}
HStack {
Text("Sex:").fontWeight(.bold)
Text(data.generalData.name)
Text(data.generalData.sex)
}

Spacer()
Expand Down Expand Up @@ -106,7 +108,6 @@ struct ExportView: View {
ForEach(data.conditionData, id: \.id) { item in
HStack {
Text(item.condition)
Spacer()
Text(item.active ? "Active" : "Inactive")
.foregroundColor(.secondary)
}
Expand Down Expand Up @@ -142,7 +143,7 @@ struct ExportView: View {
ForEach(Array(data.medicationData), id: \.id) { item in
HStack {
Text(item.type.localizedDescription)
Text(item.dosage.localizedDescription)
Text(item.dosage.localizedDescription).foregroundColor(.secondary)
}
}
}
Expand All @@ -158,9 +159,9 @@ struct ExportView: View {
} else {
ForEach(data.allergyData, id: \.id) { item in
VStack(alignment: .leading) {
Text(item.allergy).fontWeight(.bold)
Text(item.allergy)
ForEach(item.reaction, id: \.id) { reactionItem in
Text(reactionItem.reaction)
Text(reactionItem.reaction).foregroundColor(.secondary)
}
}
}
Expand All @@ -169,30 +170,54 @@ struct ExportView: View {

Spacer()
.frame(height: 20)

VStack(alignment: .leading) {
if data.generalData.sex == "Female" {
Text("Menstrual History").fontWeight(.bold)
HStack {
Text("Last Menstrual Period:").fontWeight(.bold)
Text("\(formatDate(data.menstrualHistory.startDate)) - \(formatDate(data.menstrualHistory.endDate))")
}
HStack {
Text("Additional Symptoms:").fontWeight(.bold)
Text(data.menstrualHistory.additionalDetails)
}
}
}

VStack(alignment: .leading) {
Text("Review of Systems:").fontWeight(.bold)
Text("Smoking History").fontWeight(.bold)
HStack {
Text("Smoking Status:")
Text(data.smokingHistory.hasSmokedOrSmoking ? "Yes" : "No")
}
HStack {
Text("Currently Smoking:")
Text(data.smokingHistory.currentlySmoking ? "Yes" : "No")
}
HStack {
Text("Last Menstrural Period")
Text("Date")
Text("Smoked in the Past:")
Text(data.smokingHistory.smokedInThePast ? "Yes" : "No")
}

HStack {
Text("Smoking history")
Text("0 pack years")
Text("Additional Symptoms:")
Text(data.smokingHistory.additionalDetails)
}
}
}
}
// swiftlint:enable:closure_body_length
Spacer()
}
.if(isSharing, transform: { view in
view
.padding()
})
}

@MainActor
private func shareButtonTapped() async {
self.pdfData = await self.exportToPDF()
self.isSharing = true
self.pdfData = await self.exportToPDF()
}


Expand Down Expand Up @@ -222,7 +247,6 @@ struct ExportView: View {
}

pdf.beginPDFPage(nil)
pdf.translateBy(x: 50, y: -50)

context(pdf)

Expand All @@ -233,6 +257,20 @@ struct ExportView: View {
}
}
}

func formatDate(_ date: Date) -> String {
let formatter = DateFormatter()
formatter.dateStyle = .medium // Choose your style
formatter.timeStyle = .none
return formatter.string(from: date)
}

func todayDateString() -> String {
let today = Date()
let formatter = DateFormatter()
formatter.dateStyle = .long
return formatter.string(from: today)
}
}


Expand Down Expand Up @@ -260,13 +298,6 @@ struct ShareSheet: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) {}
}

func todayDateString() -> String {
let today = Date()
let formatter = DateFormatter()
formatter.dateStyle = .long
return formatter.string(from: today)
}

struct ExportView_Previews: PreviewProvider {
static var previews: some View {
ExportView()
Expand Down
85 changes: 83 additions & 2 deletions Intake/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct StartButton: View {
Button(action: {
navigationPath.append(NavigationViews.general)
}) {
Text("Start")
Text("Create New Form")
.font(.headline)
.fontWeight(.bold)
.foregroundColor(.white)
Expand All @@ -45,6 +45,57 @@ struct StartButton: View {
}
}

struct LoadLastButton: View {
@Binding var navigationPath: NavigationPath
@Binding var disabled: Bool
@Environment(DataStore.self) private var data

var body: some View {
Button(action: {
let fetchData = loadDataStore()
if let loadedData = fetchData {
data.allergyData = loadedData.allergyData
data.generalData = loadedData.generalData
data.surgeries = loadedData.surgeries
data.conditionData = loadedData.conditionData
data.menstrualHistory = loadedData.menstrualHistory
data.smokingHistory = loadedData.smokingHistory
data.chiefComplaint = loadedData.chiefComplaint
data.surgeriesLoaded = loadedData.surgeriesLoaded
data.medicationData = loadedData.medicationData
navigationPath.append(NavigationViews.pdfs)
}
}) {
Text("Load Latest Form")
.font(.headline)
.fontWeight(.bold)
.foregroundColor(Color.white)
.padding()
.background(disabled ? Color.blue.opacity(0.5) : Color.blue)
.cornerRadius(10)
}
.disabled(disabled)
}

func loadDataStore() -> DataStore? {
let decoder = JSONDecoder()
if let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
let pathWithFilename = documentDirectory.appendingPathComponent("DataStore3.json")
if let data = try? Data(contentsOf: pathWithFilename) {
do {
let dataStore = try decoder.decode(DataStore.self, from: data)
print("successfully loaded")
return dataStore
} catch {
print("Failed to load DataStore: \(error)")
}
}
}
return nil
}
}


struct SettingsButton: View {
@Binding var showSettings: Bool

Expand Down Expand Up @@ -72,7 +123,8 @@ struct HomeView: View {

@State private var presentingAccount = false
@State private var showSettings = false

@State var isButtonDisabled = true

@Environment(NavigationPathWrapper.self) private var navigationPath
@Environment(DataStore.self) private var data

Expand Down Expand Up @@ -107,7 +159,11 @@ struct HomeView: View {
homeLogo
homeTitle
Spacer()
LoadLastButton(navigationPath: $navigationPath.path, disabled: $isButtonDisabled)
.padding(.bottom, 10)
StartButton(navigationPath: $navigationPath.path)
.padding(.top, 10)
Spacer()
}

.toolbar {
Expand Down Expand Up @@ -143,6 +199,31 @@ struct HomeView: View {
AccountSheet()
}
.verifyRequiredAccountDetails(Self.accountEnabled)
.onAppear {
let fetchData = loadDataStore()
if fetchData != nil {
isButtonDisabled = false
} else {
isButtonDisabled = true
}
}
}

func loadDataStore() -> DataStore? {
let decoder = JSONDecoder()
if let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
let pathWithFilename = documentDirectory.appendingPathComponent("DataStore3.json")
if let data = try? Data(contentsOf: pathWithFilename) {
do {
let dataStore = try decoder.decode(DataStore.self, from: data)
print("successfully loaded")
return dataStore
} catch {
print("Failed to load DataStore: \(error)")
}
}
}
return nil
}
}

Expand Down
44 changes: 40 additions & 4 deletions Intake/Intake.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,64 @@ class NavigationPathWrapper {
var path = NavigationPath()
}

struct PatientData {
struct PatientData: Codable {
var name: String
var birthdate: String
var age: String
var sex: String
}

struct MenstrualHistoryItem: Equatable {
struct ReactionItem: Identifiable, Codable {
var id = UUID()
var reaction: String
}


struct AllergyItem: Identifiable, Equatable, Codable {
var id = UUID()
var allergy: String
var reaction: [ReactionItem]

static func == (lhs: AllergyItem, rhs: AllergyItem) -> Bool {
lhs.allergy == rhs.allergy
}
}

struct MedicalHistoryItem: Identifiable, Equatable, Codable {
var id = UUID()
var condition: String
var active: Bool
}


struct MenstrualHistoryItem: Codable {
var startDate: Date
var endDate: Date
var additionalDetails: String
}

struct SmokingHistoryItem {
struct SmokingHistoryItem: Codable {
var hasSmokedOrSmoking: Bool
var currentlySmoking: Bool
var smokedInThePast: Bool
var additionalDetails: String
}

struct SurgeryItem: Identifiable, Equatable, Codable {
var id = UUID()
var surgeryName: String = ""
var date: String = ""
var endDate: String = ""
var status: String = ""
var location: String = ""
var notes: [String] = []
var bodySites: [String] = []
var complications: [String] = []
}


@Observable
class DataStore {
class DataStore: Codable {
var allergyData: [AllergyItem] = []
var conditionData: [MedicalHistoryItem] = []
var medicationData: Set<IntakeMedicationInstance> = []
Expand Down
Loading

0 comments on commit c7f8c61

Please sign in to comment.