Skip to content

Commit

Permalink
Finalize/surgery_home (#68)
Browse files Browse the repository at this point in the history
# Finalize SurgeryView UI and refactor HomeView

## ♻️ Current situation & Problem
The SurgeryView previously did not have room for the "chat" button in
the toolbar to bring up the LLM chat assistant. Also, the HomeView code
was extremely messy and used disable swiftlint commands to avoid
warnings.

## ⚙️ Release Notes 
Got rid of the "edit" button in SurgeryView. Added a "delete" button to
the InspectSurgeryView (it is not shown when adding a new surgery). Now,
if a user wants to delete a surgery, they can either swipe left on the
surgery in SurgeryView or click on it to edit and select the "delete"
button. SurgeryView now has a "chat" button in the toolbar to activate
the LLM assistant.

## 📚 Documentation
This is what the new views look like:
<img width="327" alt="Screenshot 2024-03-11 at 12 01 06 AM"
src="https://github.com/CS342/2024-Intake/assets/108841122/8b91723d-96bb-4aee-be94-9b34337458ab">
<img width="323" alt="Screenshot 2024-03-11 at 12 00 39 AM"
src="https://github.com/CS342/2024-Intake/assets/108841122/863224df-69f2-4b41-b70d-028d135ac4d4">
<img width="322" alt="Screenshot 2024-03-11 at 12 00 55 AM"
src="https://github.com/CS342/2024-Intake/assets/108841122/cfdec751-66a7-467a-8ef0-50375429ef6e">


## ✅ Testing
This code will be thoroughly tested along with the rest of the codebase.


## 📝 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):
- [X] 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).
  • Loading branch information
nriedman authored Mar 11, 2024
1 parent 081ea98 commit 06a8726
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 77 deletions.
125 changes: 68 additions & 57 deletions Intake/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ enum NavigationViews: String {
case general
}

struct StartButton: View {
@Binding var navigationPath: NavigationPath

var body: some View {
Button(action: {
navigationPath.append(NavigationViews.general)
}) {
Text("Start")
.font(.headline)
.fontWeight(.bold)
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
}
}
}

struct SettingsButton: View {
@Binding var showSettings: Bool

var body: some View {
Button(
action: {
showSettings.toggle()
},
label: {
Image(systemName: "gear")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 30, height: 30)
.foregroundColor(.blue)
.accessibilityLabel(Text("SETTINGS"))
}
)
}
}

struct HomeView: View {
static var accountEnabled: Bool {
!FeatureFlags.disableFirebase && !FeatureFlags.skipOnboarding
Expand All @@ -36,65 +74,43 @@ struct HomeView: View {

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

private var homeLogo: some View {
Image(systemName: "waveform.path.ecg")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 100, height: 100)
.foregroundColor(.blue)
.accessibilityLabel(Text("HOME_LOGO"))
}

private var homeTitle: some View {
Group {
Text("ReForm")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(.black)
Text("AI-assisted medical intake")
.font(.title2)
.foregroundColor(.gray)
}
}

var body: some View {
@Bindable var navigationPath = navigationPath
@Bindable var data = data

NavigationStack(path: $navigationPath.path) { // swiftlint:disable:this closure_body_length

// uncommment for pdf testing
// ExportView()

// comment out below for pdf testing
VStack { // swiftlint:disable:this closure_body_length
HStack {
Spacer()
Button(
action: {
showSettings.toggle()
},
label: {
Image(systemName: "gear")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 30, height: 30)
.foregroundColor(.blue)
.accessibilityLabel(Text("SETTINGS"))
}
)
.padding()
}

NavigationStack(path: $navigationPath.path) {
VStack {
Spacer()

Image(systemName: "waveform.path.ecg")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 100, height: 100)
.foregroundColor(.blue)
.accessibilityLabel(Text("HOME_LOGO"))
Text("ReForm")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(.black)
Text("AI-assisted medical intake")
.font(.title2)
.foregroundColor(.gray)

homeLogo
homeTitle
Spacer()

Button(action: {
navigationPath.path.append(NavigationViews.general)
}) {
Text("Start")
.font(.headline)
.fontWeight(.bold)
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
}
StartButton(navigationPath: $navigationPath.path)
}

.toolbar {
SettingsButton(showSettings: $showSettings)
}

.navigationDestination(for: NavigationViews.self) { view in
Expand All @@ -114,11 +130,6 @@ struct HomeView: View {
case .general: PatientInfo()
}
}


// comment out above for pdf testing


}
.sheet(isPresented: $presentingAccount) {
AccountSheet()
Expand Down
9 changes: 0 additions & 9 deletions Intake/IntakeDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,12 @@ class IntakeDelegate: SpeziAppDelegate {
)
}

// swiftlint:disable trailing_newline
private var healthKit: HealthKit {
HealthKit {
CollectSample(
HKQuantityType(.stepCount),
deliverySetting: .anchorQuery(.automatic)
)
/*
CollectSample(
HKCharacteristicType(.biologicalSex),
deliverySetting: .anchorQuery(saveAnchor: false)
)
*/
}
}
}
// swiftlint:enable trailing newline

12 changes: 9 additions & 3 deletions Intake/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,15 @@
},
"Date:" : {

},
"Delete" : {

},
"DELETE_REACTION" : {

},
"DELETE_SURGERY" : {

},
"DETAILS" : {

Expand Down Expand Up @@ -281,9 +287,6 @@
},
"FHIR_RESOURCES_CHAT_CANCEL" : {

},
"fix medication" : {

},
"Full name" : {

Expand Down Expand Up @@ -692,6 +695,9 @@
}
}
}
},
"Select + to add a surgery" : {

},
"SETTINGS" : {

Expand Down
37 changes: 29 additions & 8 deletions Intake/Surgery/SurgeryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct AddSurgery: View {

struct InspectSurgeryView: View {
@Binding var surgery: SurgeryItem
@Environment(DataStore.self) var data
@Environment(NavigationPathWrapper.self) var navigationPath
@Environment(\.dismiss) private var dismiss

var isNew: Bool

Expand All @@ -71,6 +74,23 @@ struct InspectSurgeryView: View {
}
}
.navigationBarTitle(isNew ? "New Surgery" : "Edit Surgery")
.navigationBarItems(trailing: !isNew ? deleteButton : nil)
}

private var deleteButton: some View {
Button(action: {
if let index = data.surgeries.firstIndex(of: surgery) {
data.surgeries.remove(at: index)
}
dismiss()
}) {
Text("Delete")
.font(.headline)
.foregroundColor(.blue)
.padding(8) // Add padding
.cornerRadius(8) // Round the corners
.accessibilityLabel(Text("DELETE_SURGERY"))
}
}
}

Expand All @@ -94,12 +114,9 @@ struct SurgeryView: View {
}
.navigationTitle("Surgical History")
.navigationBarItems(trailing: AddSurgery(surgeries: $data.surgeries))
// .navigationBarItems(trailing: NavigationLink(destination: SurgeryLLMAssistant(presentingAccount: .constant(false))) {
// Text("Chat")
// })
.toolbar {
EditButton()
}
.navigationBarItems(trailing: NavigationLink(destination: SurgeryLLMAssistant(presentingAccount: .constant(false))) {
Text("Chat")
})
} else {
ProgressView()
.task {
Expand All @@ -125,7 +142,11 @@ struct SurgeryView: View {
Form {
@Bindable var data = data
Section(header: Text("Please add your past surgeries")) {
surgeryElements
if data.surgeries.isEmpty {
Text("Select + to add a surgery")
} else {
surgeryElements
}
}
}
}
Expand Down Expand Up @@ -292,7 +313,7 @@ struct SurgeryView: View {
let LLMResponse = try await self.queryLLM(surgeryNames: surgeryNames)

let filteredNames = LLMResponse.components(separatedBy: ", ")
var filteredSurgeries = surgeries.filter { self.containsAnyWords(item: $0.surgeryName, words: filteredNames) }
let filteredSurgeries = surgeries.filter { self.containsAnyWords(item: $0.surgeryName, words: filteredNames) }

return self.cleanSurgeryNames(surgeries: filteredSurgeries, filteredNames: filteredNames)
}
Expand Down

0 comments on commit 06a8726

Please sign in to comment.