This repository contains the Pediatric Apple Watch Study Application application. The Pediatric Apple Watch Study Application uses the Spezi ecosystem and builds on top of the Stanford Spezi Template Application.
The Spezi Template Application uses a modularized structure using the Spezi modules enabled by the Swift Package Manager.
The application uses the FHIR standard to provide a shared standard to encode data exchanged between different modules.
Note
Do you want to learn more about the Stanford Spezi Template Application and how to use, extend, and modify this application? Check out the Stanford Spezi Template Application documentation
You can build and run the application using Xcode by opening up the PAWS.xcodeproj.
When signing in to the application for the first time, you will be required to enter a valid invitation code before a user account is created.
Use the upload_codes.py
script to generate new codes and upload them to a specified Firebase instance or a local file.
export FIRESTORE_EMULATOR_HOST="localhost:8080"
export GCLOUD_PROJECT=<project_id>
python -m scripts.upload_codes --outfile=<local_path> \
--count=<number_of_codes> --length=<code_length> \
--service_account=<service_account_key_file> [--dry]
PAWS uses Fastlane Snapshots to automatically screenshot specific screens in the app during UI tests. To generate new screenshots, you will likewise need to set the proper environment variables for your shell session.
firebase emulators:start --import=./firebase
Then, run fastlane snapshot
.
By default, results will end up in the .screenshots
folder, overwriting previous files.
Note
Snapshot will run UI tests and concurrently take screenshots on multiple device simulators. As such, multiple new PAWS accounts will be created, possibly in rapid succession, using the same hard-coded testing invitation codes.
The current workaround for simultaneous account registrations during fastlane snapshot
is to continually reset invitation codes to an unused state in Firestore by running a designated Python script on repeat (in a shell session with the same environment variables).
for i in {1..360}; do python -m scripts.upload_codes; sleep 10; done
The ECG Data Manager provides capabilities for reviewing and exploring the recorded ECG data. It relies on the spezi_data_pipeline package, which is a library engineered to improve workflows associated with data accessibility and analysis in healthcare environments. In addition to the functions and classes of the spezi_data_pipeline, the two notebooks, namely ECGReviewer.ipynb
and ECGExplore.ipynb
, offer an environment for interactive data visualization and analysis.
The ECG Data Manager includes:
utils.py
: Provides utility functions for data processing.visualization.py
: Contains functions for data visualization.ECGReviewer.ipynb
: An interactive notebook for loading, analyzing, and reviewing ECG data.ECGExplorer.ipynb
: An interactive notebook for loading, exploring, and filtering ECG data based on filters, such as age group, ECG recording classification, user, and date.
You can open and run the ECGReviewer.ipynb
and ECGExplorer.ipynb
notebooks in, e.g., Google Colab.
Once the notebook is open, execute the following cell to clone the PediatricAppleWatchStudy repository and navigate into the cloned directory:
# Clone GitHub repository for Spezi ECG Data Pipeline
git clone https://github.com/StanfordBDHG/PediatricAppleWatchStudy.git
cd PediatricAppleWatchStudy/ecg_data_manager
To run the notebooks, add them to Colab Enterprise within the same Google Cloud project as your Firebase setup. For other Python notebook environments, use the Firebase credentials and upload the serviceAccountKey_file.json
to the workspace directory to enable Firebase access. This file is essential for authentication and should be securely handled.
To start reviewing ECG data, execute the cells in your notebook.
This interactive tool allows you to plot ECG data, add diagnoses, evaluate the trace quality, and add notes.
To start exploring ECG data, execute the cells in your notebook.
This interactive tool allows you to plot ECG data, filter ECG recordings, and select specific users and timestamps.
The Google Cloud Setup at Stanford to deploy the project requires the following setup for Google Cloud Firebase and to execute the ECG review and exploration tools.
Each Firebase Project for development
, staging
, and production
GitHub environments need the following configurations:
- Firestore Database
- Firebase Authentication with Identity Platform (Anonymous Authentication, Username + Password, and Sign In With Apple Enabled)
- Firebase Storage
- Cloud Functions (also enable Cloud Build API, Google Cloud Run, and Eventarc API)
The CI setup requires a github-deployment@PROJECT_ID.iam.gserviceaccount.com
account that requires the following rules:
- Cloud Datastore Index Admin
- Cloud Functions Developer
- Firebase Admin
- Firebase Rules Admin
- Service Account User on PROJECT_ID@appspot.gserviceaccount.com
Set up a cloudfunctionsserviceaccount@PROJECT_ID.iam.gserviceaccount.com
to execute cloud functions. It needs the following rules:
- Cloud Datastore User
Created a storage bucket that is used to store the packaged dependencies & code for the Python notebooks in a versioned and isolated state. You need to enable Colab Enterprise.
To secure the data in the notebook, the network access should be retricted to needed Google Services only and using runners that only use a private network.
Run the following commands in the ECGReviewer
folder to package the dependencies and upload them, as well as the modules
folder to the cloud storage bucket if no outside internet access is enabled.
mkdir packages
pip download -r requirements.txt -d packages
tar -czvf packages.tar.gz packages/
Copy the ECGExporter
and ECGReviewer
notebooks in Colab Enterprise, uncomment, and adapt the storage bucket paths if the restricted network access is configured.
The project supports different GitHub environments (development
, staging
, and production
).
- The Firebase project ID needs to be saved as a GitHub variable with the name
FIREBASE_PROJECT_ID
for the different deployment environments. - The service account key needs to be added to the GitHub secrets as
GOOGLE_APPLICATION_CREDENTIALS_BASE64
in a base64 encoding to enable the beta deployment. - To report code coverage, a CodeCov token should be added as a
CODECOV_TOKEN
environment secret. - The Firebase Google plist needs to be stored as a base64 encoded secret named
GOOGLE_SERVICE_INFO_PLIST_BASE64
. - Store all secrets for a beta deployment of the iOS application as documented for the Stanford Spezi Template Application.
Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.
This project is licensed under the MIT License. See Licenses for more information.
For more information, check out our website at biodesigndigitalhealth.stanford.edu.