Skip to content

Commit 888dc5f

Browse files
authored
Multiple Notifications Bug Fix (#54)
# Multiple Notifications Bug Fix ## ♻️ Current situation & Problem We were sending multiple notifications when the febrile neutropenia condition is met. ## ⚙️ Release Notes Now we only check when the added data is a temperature data. I have tested on my iphone, and it works!! ## 📝 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).
1 parent e0a771d commit 888dc5f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

NeutroFeverGuard/NeutroFeverGuardStandard.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ actor NeutroFeverGuardStandard: Standard,
3636

3737
func add(sample: HKSample) async {
3838
if FeatureFlags.disableFirebase {
39-
logger.debug("Received new HealthKit sample: \(sample)")
40-
if let condition = await checkForFebrileNeutropenia() {
41-
print("Send notification")
42-
notificationManager.sendLocalNotification(
43-
title: "Health Alert",
44-
body: "Risk detected: \(condition), please contact your care provider."
45-
)
39+
logger.info("Received new HealthKit sample: \(sample)")
40+
if let quantitySample = sample as? HKQuantitySample,
41+
quantitySample.quantityType == HKQuantityType.quantityType(forIdentifier: .bodyTemperature),
42+
let condition = await checkForFebrileNeutropenia() {
43+
print("Send notification")
44+
notificationManager.sendLocalNotification(
45+
title: "Health Alert",
46+
body: "Risk detected: \(condition), please contact your care provider."
47+
)
4648
} else {
4749
notificationManager.resetNotificationState() // Reset when condition resolves
4850
}
@@ -53,8 +55,10 @@ actor NeutroFeverGuardStandard: Standard,
5355
try await healthKitDocument(id: sample.id)
5456
.setData(from: sample.resource)
5557
// Check if the condition is met before sending a notification
56-
if let condition = await checkForFebrileNeutropenia() {
57-
print("Send notification")
58+
if let quantitySample = sample as? HKQuantitySample,
59+
quantitySample.quantityType == HKQuantityType.quantityType(forIdentifier: .bodyTemperature),
60+
let condition = await checkForFebrileNeutropenia() {
61+
logger.info("Send notification")
5862
notificationManager.sendLocalNotification(
5963
title: "Health Alert",
6064
body: "Risk detected: \(condition), please contact your care provider."

0 commit comments

Comments
 (0)