generated from StanfordSpezi/SpeziTemplateApplication
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the Timeline to Appointments (#35)
# *Adding the Timeline to Appointments* ## ♻️ Current situation & Problem Adding a timeline for individuals with cognitive impairments in the appointments view <img width="241" alt="Screenshot 2024-02-27 at 9 09 23 AM" src="https://github.com/CS342/2024-PICS/assets/126360297/30435af9-13d9-48e4-b5fb-61555859cfc7"> ## ⚙️ Release Notes - Used Path to draw the lines - Blue dot indicates where the patient is in their journey - Updates based on date ## 📚 Documentation This is primarily a UI change for an additional visualization of the patient's timeline. ## ✅ Testing The tests all pass. ## 📝 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). --------- Co-authored-by: abhat01 <[email protected]>
- Loading branch information
1 parent
c98b2f5
commit 9cd44c0
Showing
6 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// | ||
// This source file is part of the PICS based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
import Foundation | ||
import SwiftUI | ||
|
||
struct CurrentLocation: Shape { | ||
let date1: Date | ||
let date2: Date | ||
let now: Date | ||
|
||
init(date1: Date, date2: Date, now: Date) { | ||
self.date1 = date1 | ||
self.date2 = date2 | ||
self.now = now | ||
} | ||
|
||
func path(in rect: CGRect) -> Path { | ||
var path = Path() | ||
|
||
let arrowWidth = rect.width | ||
let arrowHeight = rect.height / 2 | ||
|
||
let circleRadius: CGFloat = 7 | ||
let positions: [CGFloat] = [1, 2, 3, 4, 5].map { CGFloat($0) / 6 } | ||
|
||
for position in positions { | ||
let circleRect = CGRect( | ||
x: arrowWidth * position - circleRadius, | ||
y: arrowHeight / 2 - circleRadius, | ||
width: circleRadius * 2, | ||
height: circleRadius * 2 | ||
) | ||
if (now < date1 && position == 1 / 6) || | ||
(now == date1 && position == 2 / 6) || | ||
(now > date1 && now < date2 && position == 3 / 6) || | ||
(now == date2 && position == 4 / 6) || | ||
(now > date2 && position == 5 / 6 ) { | ||
path.addEllipse(in: circleRect) | ||
} | ||
} | ||
|
||
return path | ||
} | ||
} | ||
|
||
struct BidirectionalArrow: Shape { | ||
func path(in rect: CGRect) -> Path { | ||
var path = Path() | ||
|
||
let arrowWidth = rect.width | ||
let arrowHeight = rect.height / 2 | ||
|
||
// Draw the main arrow line | ||
path.move(to: CGPoint(x: 0, y: arrowHeight / 2)) | ||
path.addLine(to: CGPoint(x: arrowWidth, y: arrowHeight / 2)) | ||
|
||
|
||
let circleRadius: CGFloat = 5 | ||
|
||
let circleRect1 = CGRect( | ||
x: arrowWidth * 1 / 3 - circleRadius, | ||
y: arrowHeight / 2 - circleRadius, | ||
width: circleRadius * 2, | ||
height: circleRadius * 2 | ||
) | ||
path.addEllipse(in: circleRect1) | ||
|
||
let circleRect2 = CGRect( | ||
x: arrowWidth * 2 / 3 - circleRadius, | ||
y: arrowHeight / 2 - circleRadius, | ||
width: circleRadius * 2, | ||
height: circleRadius * 2 | ||
) | ||
path.addEllipse(in: circleRect2) | ||
|
||
// Draw the right arrowhead lines | ||
path.move(to: CGPoint(x: arrowWidth - arrowHeight / 2, y: arrowHeight / 4)) | ||
path.addLine(to: CGPoint(x: arrowWidth, y: arrowHeight / 2)) | ||
path.addLine(to: CGPoint(x: arrowWidth - arrowHeight / 2, y: arrowHeight * 3 / 4)) | ||
path.closeSubpath() | ||
|
||
// Draw the left arrowhead lines | ||
path.move(to: CGPoint(x: arrowHeight / 2, y: arrowHeight / 4)) | ||
path.addLine(to: CGPoint(x: 0, y: arrowHeight / 2)) | ||
path.addLine(to: CGPoint(x: arrowHeight / 2, y: arrowHeight * 3 / 4)) | ||
path.closeSubpath() | ||
|
||
return path | ||
} | ||
} | ||
|
||
|
||
struct TimelineView: View { | ||
let appt1: Date | ||
let appt2: Date | ||
|
||
var body: some View { | ||
let calendar = Calendar.current | ||
let currentDate = Date() | ||
|
||
let components1 = calendar.dateComponents([.year, .month, .day], from: appt1) | ||
let components2 = calendar.dateComponents([.year, .month, .day], from: appt2) | ||
let components3 = calendar.dateComponents([.year, .month, .day], from: currentDate) | ||
|
||
if let date1 = calendar.date(from: components1), let date2 = calendar.date(from: components2), let now = calendar.date(from: components3) { | ||
VStack { | ||
BidirectionalArrow() | ||
.fill(Color.black) | ||
.stroke(Color.black, lineWidth: 2) | ||
.frame(width: 361, height: 25) | ||
.overlay( | ||
CurrentLocation(date1: date1, date2: date2, now: now) | ||
.fill(Color.accentColor) | ||
) | ||
HStack(spacing: 0) { | ||
Spacer() | ||
Text(String(localized: "APPT1_TITLE")) | ||
.padding(.leading, 45) | ||
Spacer() | ||
Text("APPT2_TITLE") | ||
.padding(.trailing, 40) | ||
Spacer() | ||
} | ||
.font(.system(size: 12)) | ||
.foregroundColor(.black) | ||
} | ||
} else { | ||
Text("Failed to get dates") | ||
.foregroundColor(.red) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters