Skip to content
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
3 changes: 2 additions & 1 deletion Neuro App/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct HomeView: View {
.cornerRadius(10)
.shadow(radius: 2)

Text("Online Now:")
Text("Active Consultations:")
.font(.headline)
.padding(.top, 20)
.foregroundColor(Color.black)
Expand Down Expand Up @@ -225,6 +225,7 @@ struct OnlineUserCardView: View {
.padding(.trailing, 15)
}
.frame(maxWidth: .infinity)
.frame(maxWidth: .infinity, minHeight: 60)
.background(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .black : .white
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<entity name="NIHFormEntity" representedClassName="NIHFormEntity" syncable="YES" codeGenerationType="class">
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="dob" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="formID" optional="YES" attributeType="String"/>
<attribute name="patientName" optional="YES" attributeType="String"/>
<attribute name="selectedOptions" optional="YES" attributeType="Binary"/>
<attribute name="username" optional="YES" attributeType="String"/>
</entity>
</model>
4 changes: 2 additions & 2 deletions Neuro App/Neuro_AppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ struct Neuro_App: App {
var body: some Scene {
WindowGroup {
if authViewModel.isLoggedIn {
// ✅ User is logged in → go to HomeView

// User is logged in → go to HomeView
HomeView()
.environment(\.managedObjectContext, appDelegate.persistentContainer.viewContext)
.environmentObject(appDelegate.signalingClient!)
.environmentObject(authViewModel)
.navigationBarBackButtonHidden(true)
} else {
// Not logged in → show SignInView
// Not logged in → show SignInView
SignInView()
.environmentObject(authViewModel)
}
Expand Down
65 changes: 51 additions & 14 deletions Neuro App/NewNIHFormView.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import SwiftUI

struct NewNIHFormView: View {
var remoteForm: RemoteStrokeForm?
var initialSelectedOptions: [Int]

@Environment(\.presentationMode) var presentationMode
@Environment(\.managedObjectContext) private var viewContext
@StateObject private var viewModel = StrokeScaleFormViewModel()
@State private var patientName: String = ""
@Environment(\.presentationMode) var presentationMode
@State private var patientDOB: Date = Date()
@State private var patientName: String
@State private var patientDOB: Date
@State private var selectedOptions: [Int]
@State private var showDOBPicker: Bool = false

init(remoteForm: RemoteStrokeForm? = nil, initialSelectedOptions: [Int] = Array(repeating: -1, count: 15)) {
self.remoteForm = remoteForm
self.initialSelectedOptions = initialSelectedOptions

_patientName = State(initialValue: remoteForm?.name ?? "")
_patientDOB = State(initialValue: StrokeScaleFormManager.convertDOB(from: remoteForm?.dob ?? ""))
_selectedOptions = State(initialValue: {
if let resultStr = remoteForm?.results {
return resultStr.map { Int(String($0)) ?? 9 }
}
return Array(repeating: -1, count: 15)
}())
}

var body: some View {
VStack {
Text("New NIH Stroke Scale Form")
Text(remoteForm != nil ? "Update Form" : "New Form")
.font(.title)
.padding(.leading)
.padding(.trailing)
Expand Down Expand Up @@ -46,7 +64,11 @@ struct NewNIHFormView: View {
}) {
HStack {
Text("DOB: \(formattedDate(patientDOB))")
.foregroundColor(.white)
.foregroundColor(
Color(UIColor { trait in
trait.userInterfaceStyle == .dark ? .white : .black
})
)
.font(.headline)
Spacer()
Image(systemName: "calendar")
Expand Down Expand Up @@ -92,7 +114,7 @@ struct NewNIHFormView: View {
showDOBPicker = false
}
.font(.headline)
.foregroundColor(.white)
.foregroundColor(.black)
.padding()
.frame(maxWidth: .infinity)
.background(Color.purple.opacity(0.2))
Expand Down Expand Up @@ -121,13 +143,13 @@ struct NewNIHFormView: View {
HStack {
Button(action: {
saveForm()
presentationMode.wrappedValue.dismiss() // Dismiss after saving
}) {
Text("Save")
.font(.headline)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)

.background(Color.green)
.cornerRadius(10)
}
Expand All @@ -148,22 +170,37 @@ struct NewNIHFormView: View {
.padding(.bottom)
}
.background(Color.purple.opacity(0.2))
.onAppear {
for option in 0..<min(viewModel.questions.count, selectedOptions.count) {
viewModel.questions[option].selectedOption = selectedOptions[option]
}
}
}

private func saveForm() {
let selected = viewModel.questions.map { $0.selectedOption ?? 9 }
StrokeScaleFormManager.saveForm(
context: viewContext,
patientName: patientName,
dob: patientDOB,
selectedOptions: selected
)

if let form = remoteForm {
StrokeScaleFormManager.updateForm(
remoteForm: form,
patientName: patientName,
dob: patientDOB,
selectedOptions: selected
)
} else {
StrokeScaleFormManager.saveForm(
context: viewContext,
patientName: patientName,
dob: patientDOB,
selectedOptions: selected
)
}
}

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

}
Loading
Loading