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

Functionality Switch Social History #56

Closed
wants to merge 5 commits into from
Closed
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
43 changes: 23 additions & 20 deletions Intake/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@
},
"Additional Details" : {

},
"Additional details: %@" : {

},
"Additional Symptoms" : {

Expand All @@ -100,8 +97,8 @@
"Auto-fill Intake Form" : {

},
"Chat" : {

"Calculation" : {
},
"CHIEF_COMPLAINT_SYSTEM_PROMPT" : {
"extractionState" : "manual",
Expand Down Expand Up @@ -206,9 +203,12 @@
"DETAILS" : {

},
"Download your medical records from your health system." : {
"Do you currently or have you smoked in the past?" : {

},

"Download your medical records from your health system." : {

"End Date: %@" : {

},
Expand All @@ -217,6 +217,7 @@
},
"END_CALENDAR" : {


},
"Ex: Heavy bleeding on second day, fatigue..." : {

Expand Down Expand Up @@ -298,6 +299,12 @@
},
"It looks like an unexpected view was appended to the NavigationPath!" : {

},
"Last period's end date" : {

},
"Last period's start date" : {

},
"LICENSE_INFO_TITLE" : {
"localizations" : {
Expand Down Expand Up @@ -406,6 +413,9 @@
},
"Next" : {

},
"No" : {

},
"NOTIFICATION_PERMISSIONS_BUTTON" : {
"extractionState" : "stale",
Expand Down Expand Up @@ -565,18 +575,6 @@
}
}
}
},
"Select End Date" : {

},
"Select Start Date" : {

},
"Select your last period's end date" : {

},
"Select your last period's start date" : {

},
"SETTINGS" : {

Expand All @@ -599,6 +597,8 @@
"Start" : {

},


"Start Date: %@" : {

},
Expand All @@ -608,6 +608,7 @@
"Status" : {

},

"Submit" : {

},
Expand All @@ -631,9 +632,6 @@
},
"Surgical History" : {

},
"Symptoms: %@" : {

},
"TASK_CONTEXT_ACTION_QUESTIONNAIRE" : {
"localizations" : {
Expand Down Expand Up @@ -709,8 +707,13 @@
"What is your surgical history?" : {

},

"Yes" : {


"Your Responses" : {


}
},
"version" : "1.0"
Expand Down
164 changes: 22 additions & 142 deletions Intake/SocialHistory/MenstrualHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,152 +14,37 @@ import Foundation
import HealthKit
import SwiftUI


struct SectionHeader: View {
let title: String
let subtitle: String

var body: some View {
VStack(alignment: .leading) {
Text(title)
.font(.title)
.multilineTextAlignment(.leading)
.padding(.bottom, 2)

if !subtitle.isEmpty {
Text(subtitle)
.font(.subheadline)
.foregroundColor(.gray)
.multilineTextAlignment(.leading)
.padding(.bottom)
}
}
}
}

struct SocialHistoryQuestionView: View {
struct SectionHeader: View {
let title: String

var body: some View {
VStack(alignment: .leading) {
Text(title)
.font(.headline)
}
}
}

private var menstrualCycleButtons: some View {
VStack {
Button(action: {
isSelectingStartDate = true
}) {
HStack {
Text("Select your last period's start date")
Spacer() // Add Spacer here for white space
Image(systemName: "calendar")
.accessibilityLabel(Text("START_CALENDAR"))
}
}
.buttonStyle(BorderlessButtonStyle())

Spacer().frame(height: 16)

Button(action: {
isSelectingEndDate = true
}) {
HStack {
Text("Select your last period's end date")
Spacer()
Image(systemName: "calendar")
.accessibilityLabel(Text("END_CALENDAR"))
}
}
.buttonStyle(BorderlessButtonStyle())
}
}

private var menstrualCycleInformationSection: some View {
Group {
Section(header: Text("Menstrual Information").foregroundColor(.gray)) {
menstrualCycleButtons
}

Section(header: Text("Additional Symptoms")) {
TextField("Ex: Heavy bleeding on second day, fatigue...", text: $additionalDetails)
}
if shouldDisplayResponses {
Section(header: Text("Your Responses").foregroundColor(.gray)) {
VStack(alignment: .leading) {
Text("Start Date: \(formatDate(startDate))")
Text("End Date: \(formatDate(endDate))")
if !additionalDetails.isEmpty {
Text("Symptoms: \(additionalDetails)")
}
}
}
}
}
}

@State private var dateString: String = ""
@State private var additionalDetails: String = ""
@State private var isFemale = false
@State private var showMaleSlide = false
@State private var healthStore = HKHealthStore()

@State private var isSelectingStartDate = false
@State private var isSelectingEndDate = false
@State private var startDate = Date()
@State private var endDate = Date()
@State private var lastPeriodDate: Date?

@State private var healthStore = HKHealthStore()
@State private var isFemale = false
@State private var showMaleSlide = false
@Environment(NavigationPathWrapper.self) private var navigationPath

private var shouldDisplayResponses: Bool {
!additionalDetails.isEmpty || startDate != Date() || endDate != Date()
}


let numberFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.minimum = 0
return formatter
}()


var body: some View {
NavigationView { // swiftlint:disable:this closure_body_length
VStack { // swiftlint:disable:this closure_body_length
NavigationView {
VStack {
Form {
menstrualCycleInformationSection
Section(header: Text("Menstrual Information").foregroundColor(.gray)) {
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)) {
TextField("Ex: Heavy bleeding on second day, fatigue...", text: $additionalDetails)
}
}
.navigationTitle("Social History")
.onAppear {
fetchHealthKitData()
}
.sheet(isPresented: $isSelectingStartDate, content: {
VStack {
DatePicker("Select Start Date", selection: $startDate, displayedComponents: .date)
.datePickerStyle(GraphicalDatePickerStyle())

Button("Save") {
lastPeriodDate = startDate
isSelectingStartDate = false
}
}
})
.sheet(isPresented: $isSelectingEndDate, content: {
VStack {
DatePicker("Select End Date", selection: $endDate, displayedComponents: .date)
.datePickerStyle(GraphicalDatePickerStyle())

Button("Save") {
isSelectingEndDate = false
}
}
})
Spacer()

// Adding the Submit button outside the Form
Button(action: {
navigationPath.path.append(NavigationViews.smoking)
}) {
Expand All @@ -170,17 +55,12 @@ struct SocialHistoryQuestionView: View {
.background(Color.blue)
.cornerRadius(8)
}
.padding()
.padding(.horizontal)
.padding(.bottom)
}
}
}

private func formatDate(_ date: Date) -> String {
let formatter = DateFormatter()
formatter.dateStyle = .medium
return formatter.string(from: date)
}


private func fetchHealthKitData() {
let infoToRead = Set([HKObjectType.characteristicType(forIdentifier: .biologicalSex)].compactMap { $0 })

Expand Down
Loading
Loading