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

Symptom Upload & Local Storage of Uploaded ECG Recordings #48

Merged
merged 3 commits into from
Feb 21, 2024
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
6 changes: 5 additions & 1 deletion PAWS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
2F6025CB29BBE70F0045459E /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2F6025CA29BBE70F0045459E /* GoogleService-Info.plist */; };
2F65B44E2A3B8B0600A36932 /* NotificationPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */; };
2FA0BFED2ACC977500E0EF83 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 2FA0BFEC2ACC977500E0EF83 /* Localizable.xcstrings */; };
2FA25D492B8402A70016E4C7 /* HKElectrocardiogram+SupplementaryData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA25D482B8402A70016E4C7 /* HKElectrocardiogram+SupplementaryData.swift */; };
2FB099AF2A875DF100B20952 /* FirebaseAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 2FB099AE2A875DF100B20952 /* FirebaseAuth */; };
2FB099B12A875DF100B20952 /* FirebaseFirestore in Frameworks */ = {isa = PBXBuildFile; productRef = 2FB099B02A875DF100B20952 /* FirebaseFirestore */; };
2FB099B32A875DF100B20952 /* FirebaseFirestoreSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 2FB099B22A875DF100B20952 /* FirebaseFirestoreSwift */; };
Expand Down Expand Up @@ -100,6 +101,7 @@
2F6025CA29BBE70F0045459E /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationPermissions.swift; sourceTree = "<group>"; };
2FA0BFEC2ACC977500E0EF83 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
2FA25D482B8402A70016E4C7 /* HKElectrocardiogram+SupplementaryData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HKElectrocardiogram+SupplementaryData.swift"; sourceTree = "<group>"; };
2FAEC07F297F583900C11C42 /* PAWS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PAWS.entitlements; sourceTree = "<group>"; };
2FC94CD4298B0A1D009C8209 /* PAWS.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = PAWS.xctestplan; sourceTree = "<group>"; };
2FC975A72978F11A00BA99FE /* Home.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Home.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -216,6 +218,7 @@
2FCC1DBD2B6A1C9000C686BE /* ECGRecordingsList.swift */,
2FCC1DC42B6A1F0600C686BE /* ECGRecording.swift */,
2FCC1DC02B6A1D4C00C686BE /* ECGModule.swift */,
2FA25D482B8402A70016E4C7 /* HKElectrocardiogram+SupplementaryData.swift */,
);
path = ECGRecordings;
sourceTree = "<group>";
Expand Down Expand Up @@ -598,6 +601,7 @@
2F65B44E2A3B8B0600A36932 /* NotificationPermissions.swift in Sources */,
5661552E2AB854C000209B80 /* PackageHelper.swift in Sources */,
2FE5DC2629EDD38A004B9AB4 /* Contacts.swift in Sources */,
2FA25D492B8402A70016E4C7 /* HKElectrocardiogram+SupplementaryData.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1181,7 +1185,7 @@
repositoryURL = "https://github.com/StanfordSpezi/SpeziHealthKit.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.5.0;
minimumVersion = 0.5.1;
};
};
2FE5DC7329EDD8E6004B9AB4 /* XCRemoteSwiftPackageReference "SpeziFirebase" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk.git",
"state" : {
"revision" : "b880ec8ec927a838c51c12862c6222c30d7097d7",
"version" : "10.20.0"
"revision" : "f91c8167141d0279726c6f6d9d4a47c026785cbc",
"version" : "10.21.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "ceec9f28dea12b7cf3dabf18b5ed7621c88fd4aa",
"version" : "10.20.0"
"revision" : "cb8617fab75d181270a1d8f763f26b15c73e2e1e",
"version" : "10.21.0"
}
},
{
Expand Down Expand Up @@ -158,8 +158,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/Spezi",
"state" : {
"revision" : "c4bf0e99de40acfdd2baf0fa02769f06a4c3f0eb",
"version" : "1.1.0"
"revision" : "c8482d05efbd2ba93abefc309a86f7b77d10fca0",
"version" : "1.2.0"
}
},
{
Expand Down Expand Up @@ -194,17 +194,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziFoundation.git",
"state" : {
"revision" : "d1e6d4cddcf236038d21a73d671806d8ba51b01c",
"version" : "1.0.1"
"revision" : "0346857e2f1d6fd4b1d950d271be6c82df97107f",
"version" : "1.0.2"
}
},
{
"identity" : "spezihealthkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziHealthKit.git",
"state" : {
"revision" : "d882734a4ed31fce1bffd7b9977e2669080f21de",
"version" : "0.5.0"
"revision" : "b40695ffa4d1c9d58c5a0ee277640c2343fb5516",
"version" : "0.5.1"
}
},
{
Expand All @@ -221,8 +221,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziOnboarding",
"state" : {
"revision" : "8fb6d9f1a080661c0cc564a93b82ead3c8d44d4f",
"version" : "1.0.2"
"revision" : "91463ae190611bd14ef52b0657e8db3bf53c9ae8",
"version" : "1.1.0"
}
},
{
Expand All @@ -248,8 +248,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziViews.git",
"state" : {
"revision" : "2772604eaf655e7d3b7715dfd87031573bafd5a7",
"version" : "1.1.0"
"revision" : "d49f716e4a4d634604bb0dcd6d53df679b6c1358",
"version" : "1.3.0"
}
},
{
Expand All @@ -266,8 +266,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192",
"version" : "1.0.6"
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
}
},
{
Expand Down Expand Up @@ -329,8 +329,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/XCTestExtensions.git",
"state" : {
"revision" : "fb7fcee97c574b950e03b0a53874e26db27db2fe",
"version" : "0.4.8"
"revision" : "e29d29dcc70748e13925396673c6c01ce60607ad",
"version" : "0.4.9"
}
},
{
Expand All @@ -347,8 +347,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/XCTRuntimeAssertions",
"state" : {
"revision" : "bb2a287c2544aa846e53670d1ece35e5949567be",
"version" : "1.0.0"
"revision" : "51da3403f128b120705571ce61e0fe190f8889e6",
"version" : "1.0.1"
}
},
{
Expand Down
13 changes: 12 additions & 1 deletion PAWS/Contacts/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@

var body: some View {
NavigationStack {
ContactsList(contacts: contacts)
ScrollView {
VStack(spacing: 16) {
ForEach(contacts, id: \.name) { contact in
PAWSCard {
ContactView(contact: contact)
.buttonStyle(.plain) // ensure the whole list row doesn't render as a button
.padding()
}
}
}
.padding(.vertical)
}

Check warning on line 97 in PAWS/Contacts/Contacts.swift

View check run for this annotation

Codecov / codecov/patch

PAWS/Contacts/Contacts.swift#L86-L97

Added lines #L86 - L97 were not covered by tests
.navigationTitle(String(localized: "CONTACTS_NAVIGATION_TITLE"))
.toolbar {
if AccountButton.shouldDisplay {
Expand Down
72 changes: 71 additions & 1 deletion PAWS/ECGRecordings/ECGModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,83 @@

import HealthKit
import Spezi
import SpeziLocalStorage


@Observable
class ECGModule: Module, DefaultInitializable, EnvironmentAccessible {
var hkElectrocardiograms: [HKElectrocardiogram] = []
enum StorageKey {
static let uploadedElectrocardiograms = "ECGModule.uploadedElectrocardiograms"
}


@ObservationIgnored @Dependency var localStorage: LocalStorage

private(set) var electrocardiograms: [HKElectrocardiogram] = []
private var uploadedElectrocardiograms: Set<HKElectrocardiogram.ID> = []


/// Creates an instance of a ``MockWebService``.
required init() { }


func configure() {
uploadedElectrocardiograms = (try? localStorage.read(storageKey: StorageKey.uploadedElectrocardiograms)) ?? []
}


func isUploaded(_ electrocardiogram: HKElectrocardiogram) -> Bool {
uploadedElectrocardiograms.contains(where: { $0 == electrocardiogram.uuid })
}

Check warning on line 38 in PAWS/ECGRecordings/ECGModule.swift

View check run for this annotation

Codecov / codecov/patch

PAWS/ECGRecordings/ECGModule.swift#L36-L38

Added lines #L36 - L38 were not covered by tests

func markAsUploaded(_ electrocardiogram: HKElectrocardiogram) {
uploadedElectrocardiograms.insert(electrocardiogram.uuid)
try? localStorage.store(uploadedElectrocardiograms, storageKey: StorageKey.uploadedElectrocardiograms)
}

Check warning on line 43 in PAWS/ECGRecordings/ECGModule.swift

View check run for this annotation

Codecov / codecov/patch

PAWS/ECGRecordings/ECGModule.swift#L40-L43

Added lines #L40 - L43 were not covered by tests

func insert(electrocardiogram: HKElectrocardiogram) {
electrocardiograms.removeAll(where: { $0.uuid == electrocardiogram.id })
electrocardiograms.append(electrocardiogram)
electrocardiograms.sort(by: { $0.endDate > $1.endDate })
}

Check warning on line 49 in PAWS/ECGRecordings/ECGModule.swift

View check run for this annotation

Codecov / codecov/patch

PAWS/ECGRecordings/ECGModule.swift#L45-L49

Added lines #L45 - L49 were not covered by tests

func remove(electrocardiogram id: HKElectrocardiogram.ID) {
electrocardiograms.removeAll(where: { $0.uuid == id })
uploadedElectrocardiograms.remove(id)
try? localStorage.store(uploadedElectrocardiograms, storageKey: StorageKey.uploadedElectrocardiograms)
}

Check warning on line 55 in PAWS/ECGRecordings/ECGModule.swift

View check run for this annotation

Codecov / codecov/patch

PAWS/ECGRecordings/ECGModule.swift#L51-L55

Added lines #L51 - L55 were not covered by tests

func electrocardiogram(
correlatedWith correlatedCategorySample: HKCategorySample,
from healthStore: HKHealthStore
) async throws -> HKElectrocardiogram? {
electrocardiogramLoop: for electrocardiogram in electrocardiograms {
guard electrocardiogram.symptomsStatus == .present else {
continue electrocardiogramLoop
}

let predicate = HKQuery.predicateForObjectsAssociated(electrocardiogram: electrocardiogram)

for sampleType in HKElectrocardiogram.correlatedSymptomTypes {
let queryDescriptor = HKSampleQueryDescriptor(
predicates: [
.sample(type: sampleType, predicate: predicate)
],
sortDescriptors: [
SortDescriptor(\.endDate, order: .reverse)
]
)

sampleLoop: for sample in try await queryDescriptor.result(for: healthStore) {
guard let categorySample = sample as? HKCategorySample, categorySample.id == correlatedCategorySample.id else {
continue sampleLoop
}

return electrocardiogram
}
}
}

return nil
}

Check warning on line 89 in PAWS/ECGRecordings/ECGModule.swift

View check run for this annotation

Codecov / codecov/patch

PAWS/ECGRecordings/ECGModule.swift#L60-L89

Added lines #L60 - L89 were not covered by tests
}
Loading
Loading