Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF format + random changes #77

Merged
merged 5 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 55 additions & 24 deletions Intake/Export/ExportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
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)

Check warning on line 55 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L53-L55

Added lines #L53 - L55 were not covered by tests

Spacer()
.frame(height: 20)
Expand All @@ -75,7 +77,7 @@
}
HStack {
Text("Sex:").fontWeight(.bold)
Text(data.generalData.name)
Text(data.generalData.sex)

Check warning on line 80 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L80

Added line #L80 was not covered by tests
}

Spacer()
Expand Down Expand Up @@ -103,7 +105,6 @@
ForEach(data.conditionData, id: \.id) { item in
HStack {
Text(item.condition)
Spacer()
Text(item.active ? "Active" : "Inactive")
.foregroundColor(.secondary)
}
Expand Down Expand Up @@ -139,7 +140,7 @@
ForEach(Array(data.medicationData), id: \.id) { item in
HStack {
Text(item.type.localizedDescription)
Text(item.dosage.localizedDescription)
Text(item.dosage.localizedDescription).foregroundColor(.secondary)

Check warning on line 143 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L143

Added line #L143 was not covered by tests
}
}
}
Expand All @@ -155,9 +156,9 @@
} else {
ForEach(data.allergyData, id: \.id) { item in
VStack(alignment: .leading) {
Text(item.allergy).fontWeight(.bold)
Text(item.allergy)

Check warning on line 159 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L159

Added line #L159 was not covered by tests
ForEach(item.reaction, id: \.id) { reactionItem in
Text(reactionItem.reaction)
Text(reactionItem.reaction).foregroundColor(.secondary)

Check warning on line 161 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L161

Added line #L161 was not covered by tests
}
}
}
Expand All @@ -166,30 +167,54 @@

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)
}
}
}

Check warning on line 183 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L170-L183

Added lines #L170 - L183 were not covered by tests

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")
}

Check warning on line 194 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L186-L194

Added lines #L186 - L194 were not covered by tests
HStack {
Text("Last Menstrural Period")
Text("Date")
Text("Smoked in the Past:")
Text(data.smokingHistory.smokedInThePast ? "Yes" : "No")

Check warning on line 197 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L196-L197

Added lines #L196 - L197 were not covered by tests
}

HStack {
Text("Smoking history")
Text("0 pack years")
Text("Additional Symptoms:")
Text(data.smokingHistory.additionalDetails)

Check warning on line 201 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L200-L201

Added lines #L200 - L201 were not covered by tests
}
}
}
}
// swiftlint:enable:closure_body_length
Spacer()
}
.if(isSharing, transform: { view in
view
.padding()
})

Check warning on line 211 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L208-L211

Added lines #L208 - L211 were not covered by tests
}

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

Check warning on line 217 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L217

Added line #L217 was not covered by tests
}


Expand Down Expand Up @@ -222,7 +247,6 @@
}

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

context(pdf)

Expand All @@ -233,6 +257,20 @@
}
}
}

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

Check warning on line 266 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L261-L266

Added lines #L261 - L266 were not covered by tests

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

Check warning on line 273 in Intake/Export/ExportView.swift

View check run for this annotation

Codecov / codecov/patch

Intake/Export/ExportView.swift#L268-L273

Added lines #L268 - L273 were not covered by tests
}


Expand Down Expand Up @@ -261,13 +299,6 @@
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
20 changes: 7 additions & 13 deletions Intake/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
},
"%@ Reactions" : {

},
"0 pack years" : {

},
"ACCOUNT_NEXT" : {
"localizations" : {
Expand Down Expand Up @@ -100,6 +97,9 @@
},
"Additional Symptoms" : {

},
"Additional Symptoms:" : {

},
"Age" : {

Expand Down Expand Up @@ -242,9 +242,6 @@
},
"Currently Smoking:" : {

},
"Date" : {

},
"Date of Birth" : {

Expand Down Expand Up @@ -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" : {
Expand Down Expand Up @@ -665,9 +662,6 @@
},
"Review of Systems" : {

},
"Review of Systems:" : {

},
"Review summary of your medical history." : {

Expand Down Expand Up @@ -733,15 +727,15 @@
},
"Smoked in the Past:" : {

},
"Smoking history" : {

},
"Smoking History" : {

},
"Smoking Status" : {

},
"Smoking Status:" : {

},
"Social History" : {

Expand Down
4 changes: 3 additions & 1 deletion Intake/ScrollablePDF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@
SurgerySection()
MedicationSection()
AllergySection()
MenstrualSection()
if data.generalData.sex == "Female" {
MenstrualSection()
}

Check warning on line 283 in Intake/ScrollablePDF.swift

View check run for this annotation

Codecov / codecov/patch

Intake/ScrollablePDF.swift#L281-L283

Added lines #L281 - L283 were not covered by tests
SmokingSection()
}
.navigationTitle("Patient Form")
Expand Down
81 changes: 27 additions & 54 deletions Intake/SocialHistory/MenstrualHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,38 @@
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)
}

Check warning on line 44 in Intake/SocialHistory/MenstrualHistory.swift

View check run for this annotation

Codecov / codecov/patch

Intake/SocialHistory/MenstrualHistory.swift#L30-L44

Added lines #L30 - L44 were not covered by tests
}
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

Check warning on line 50 in Intake/SocialHistory/MenstrualHistory.swift

View check run for this annotation

Codecov / codecov/patch

Intake/SocialHistory/MenstrualHistory.swift#L46-L50

Added lines #L46 - L50 were not covered by tests
}
}
.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)

Check warning on line 56 in Intake/SocialHistory/MenstrualHistory.swift

View check run for this annotation

Codecov / codecov/patch

Intake/SocialHistory/MenstrualHistory.swift#L52-L56

Added lines #L52 - L56 were not covered by tests
}
SubmitButton(nextView: NavigationViews.smoking)
.padding()

Check warning on line 59 in Intake/SocialHistory/MenstrualHistory.swift

View check run for this annotation

Codecov / codecov/patch

Intake/SocialHistory/MenstrualHistory.swift#L58-L59

Added lines #L58 - L59 were not covered by tests
}
} 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
}
}*/
}
Loading