From 14e0ee79b92ced658b42fbea14a64d146ef8592e Mon Sep 17 00:00:00 2001 From: Zoya Garg <125168583+zoyagarg@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:01:09 -0700 Subject: [PATCH] PDF format + random changes (#77) # *Fixing the PDF* ## :recycle: Current situation & Problem * Include social history when appropriate * Reformat so it looks professional (all left, secondary colors) * Fix length issues * Reformat patient responses ## :gear: Release Notes *Add a bullet point list summary of the feature and possible migration guides if this is a breaking change so this section can be added to the release notes.* *Include code snippets that provide examples of the feature implemented or links to the documentation if it appends or changes the public interface.* ## :books: Documentation *Please ensure that you properly document any additions in conformance to [Spezi Documentation Guide](https://github.com/StanfordSpezi/.github/blob/main/DOCUMENTATIONGUIDE.md).* *You can use this section to describe your solution, but we encourage contributors to document your reasoning and changes using in-line documentation.* ## :white_check_mark: Testing *Please ensure that the PR meets the testing requirements set by CodeCov and that new functionality is appropriately tested.* *This section describes important information about the tests and why some elements might not be testable.* ## :pencil: Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md): - [ ] I agree to follow the [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md). --- Intake/Export/ExportView.swift | 79 ++++++++++++++------ Intake/Resources/Localizable.xcstrings | 20 ++--- Intake/ScrollablePDF.swift | 4 +- Intake/SocialHistory/MenstrualHistory.swift | 81 +++++++-------------- 4 files changed, 92 insertions(+), 92 deletions(-) diff --git a/Intake/Export/ExportView.swift b/Intake/Export/ExportView.swift index 7ab6d82..9741258 100644 --- a/Intake/Export/ExportView.swift +++ b/Intake/Export/ExportView.swift @@ -47,10 +47,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) @@ -75,7 +77,7 @@ struct ExportView: View { } HStack { Text("Sex:").fontWeight(.bold) - Text(data.generalData.name) + Text(data.generalData.sex) } Spacer() @@ -103,7 +105,6 @@ struct ExportView: View { ForEach(data.conditionData, id: \.id) { item in HStack { Text(item.condition) - Spacer() Text(item.active ? "Active" : "Inactive") .foregroundColor(.secondary) } @@ -139,7 +140,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) } } } @@ -155,9 +156,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) } } } @@ -166,30 +167,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() } @@ -222,7 +247,6 @@ struct ExportView: View { } pdf.beginPDFPage(nil) - pdf.translateBy(x: 50, y: -50) context(pdf) @@ -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) + } } @@ -261,13 +299,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() diff --git a/Intake/Resources/Localizable.xcstrings b/Intake/Resources/Localizable.xcstrings index e97d446..9d4c585 100644 --- a/Intake/Resources/Localizable.xcstrings +++ b/Intake/Resources/Localizable.xcstrings @@ -22,9 +22,6 @@ }, "%@ Reactions" : { - }, - "0 pack years" : { - }, "ACCOUNT_NEXT" : { "localizations" : { @@ -100,6 +97,9 @@ }, "Additional Symptoms" : { + }, + "Additional Symptoms:" : { + }, "Age" : { @@ -242,9 +242,6 @@ }, "Currently Smoking:" : { - }, - "Date" : { - }, "Date of Birth" : { @@ -370,7 +367,7 @@ "It looks like an unexpected view was appended to the NavigationPath!" : { }, - "Last Menstrural Period" : { + "Last Menstrual Period:" : { }, "Last period's end date" : { @@ -665,9 +662,6 @@ }, "Review of Systems" : { - }, - "Review of Systems:" : { - }, "Review summary of your medical history." : { @@ -733,15 +727,15 @@ }, "Smoked in the Past:" : { - }, - "Smoking history" : { - }, "Smoking History" : { }, "Smoking Status" : { + }, + "Smoking Status:" : { + }, "Social History" : { diff --git a/Intake/ScrollablePDF.swift b/Intake/ScrollablePDF.swift index 2da1fb6..a19586d 100644 --- a/Intake/ScrollablePDF.swift +++ b/Intake/ScrollablePDF.swift @@ -278,7 +278,9 @@ struct ScrollablePDF: View { SurgerySection() MedicationSection() AllergySection() - MenstrualSection() + if data.generalData.sex == "Female" { + MenstrualSection() + } SmokingSection() } .navigationTitle("Patient Form") diff --git a/Intake/SocialHistory/MenstrualHistory.swift b/Intake/SocialHistory/MenstrualHistory.swift index 8b89c69..110c288 100644 --- a/Intake/SocialHistory/MenstrualHistory.swift +++ b/Intake/SocialHistory/MenstrualHistory.swift @@ -27,65 +27,38 @@ struct SocialHistoryQuestionView: View { var body: some View { NavigationView { VStack { - Form { - Section(header: Text("Menstrual Information").foregroundColor(.gray)) { - @Bindable var data = data - DatePicker("Last period's start date", selection: $startDate, in: ...Date(), displayedComponents: .date) - .datePickerStyle(DefaultDatePickerStyle()) - - DatePicker("Last period's end date", selection: $endDate, in: ...Date(), displayedComponents: .date) - .datePickerStyle(DefaultDatePickerStyle()) + if data.generalData.sex == "Female" { + Form { + Section(header: Text("Menstrual Information").foregroundColor(.gray)) { + @Bindable var data = data + DatePicker("Last period's start date", selection: $startDate, in: ...Date(), displayedComponents: .date) + .datePickerStyle(DefaultDatePickerStyle()) + + DatePicker("Last period's end date", selection: $endDate, in: ...Date(), displayedComponents: .date) + .datePickerStyle(DefaultDatePickerStyle()) + } + + Section(header: Text("Additional Symptoms").foregroundColor(.gray)) { + @Bindable var data = data + TextField("Ex: Heavy bleeding on second day, fatigue...", text: $additionalDetails) + } } - Section(header: Text("Additional Symptoms").foregroundColor(.gray)) { - @Bindable var data = data - TextField("Ex: Heavy bleeding on second day, fatigue...", text: $additionalDetails) + .navigationTitle("Social History") + .task { + startDate = data.menstrualHistory.startDate + endDate = data.menstrualHistory.endDate + additionalDetails = data.menstrualHistory.additionalDetails } - } - .navigationTitle("Social History") - .task { - startDate = data.menstrualHistory.startDate - endDate = data.menstrualHistory.endDate - additionalDetails = data.menstrualHistory.additionalDetails - } - /*.task { - fetchHealthKitData() - }*/ - .onDisappear { - data.menstrualHistory = MenstrualHistoryItem(startDate: startDate, endDate: endDate, additionalDetails: additionalDetails) - } - SubmitButton(nextView: NavigationViews.smoking) - .padding() - } - } - } - /* Show View based on DataStore ! */ - /* - private func fetchHealthKitData() { - let infoToRead = Set([HKObjectType.characteristicType(forIdentifier: .biologicalSex)].compactMap { $0 }) - - Task { - do { - try await healthStore.requestAuthorization(toShare: [], read: infoToRead) - - if let bioSex = try? healthStore.biologicalSex() { - DispatchQueue.main.async { - self.isFemale = getIsFemaleBiologicalSex(biologicalSex: bioSex.biologicalSex) - self.showMaleSlide = !self.isFemale + /*.task { + fetchHealthKitData() + }*/ + .onDisappear { + data.menstrualHistory = MenstrualHistoryItem(startDate: startDate, endDate: endDate, additionalDetails: additionalDetails) } + SubmitButton(nextView: NavigationViews.smoking) + .padding() } - } catch { - print("HealthKit authorization failed: \(error.localizedDescription)") } } } - - private func getIsFemaleBiologicalSex(biologicalSex: HKBiologicalSex) -> Bool { - switch biologicalSex { - case .female: return true - case .male: return false - case .other: return true - case .notSet: return false - @unknown default: return false - } - }*/ }