Patient Sync CLI is a lightweight command-line tool developed to simulate the synchronization and real-time monitoring of home-based patients' biometric readings.
Originally designed to simulate how a hospital monitoring system might operate, this tool processes readings from connected medical devices and evaluates critical alerts (such as high blood sugar, blood pressure, or abnormal heart rates) in real time.
It simulates the dispatch of alerts to external systems and provides a detailed results report.
- Load patient data and sensor readings dynamically.
- Evaluate clinical rules such as:
- High blood sugar
- High blood pressure
- Low/High heart rate
- Missing or outdated readings
- Simulate sending alerts to an external web service (configurable endpoint).
- Persist results into an audit file (
output/results.json
). - Mark readings as synchronized after processing.
- src/main/kotlin/com/joseiguti/patientsync/
- Application.kt
- services/
- FileLoader.kt
- PatientProcessor.kt
- ResultWriter.kt
- AlertService.kt
- models/
- Patient.kt
- Reading.kt
- Rule.kt
- src/main/resources/
- patients.json
- readings.txt
- rules.json
- config.json
- output/
- results.json
-
Make sure you have Java 17+ and Maven installed.
-
Clone the repository:
git clone https://github.com/your-repo/patient-sync.git
-
Navigate to the project directory:
cd patient-sync
-
Build the project:
mvn clean package
-
Run the CLI:
APP_ENV=dev java -jar target/patient-sync-0.0.1-SNAPSHOT.jar src/main/resources/readings.txt src/main/resources/patients.json
When a critical condition is detected, the system simulates sending a POST request to an external endpoint.
The endpoint URL is defined in src/main/resources/config.json
:
{
"endpointUrl": "https://example.com/alerts"
}
The payload sent contains:
patientId
alertType
(reading type)value
(measurement)
Success or failure of sending is randomized for testing purposes.
The readings.txt
file simulates a real-world scenario where patient monitoring devices (such as glucose meters, heart rate monitors, or blood pressure cuffs) directly write new readings to a shared file. Each reading is recorded as a JSON line, without forming a full JSON array structure, simulating real device behavior where data is streamed or appended over time.
Each entry includes:
patientId
: ID of the patient associated with the reading.code
: Type of reading (e.g.,blood_sugar
,heart_rate
,blood_pressure
).value
: Measurement value.date
: Date of reading.time
: Time of reading.sync
: Status flag indicating whether the reading has been processed.
Example of a single reading:
{
"patientId": 1,
"code": "heart_rate",
"value": 130.0,
"date": "2025-04-25",
"time": "09:00",
"sync": false
}
Each alert rule defines thresholds that determine critical patient conditions.
For instance:
- Heart Rate Alerts: If a heart rate reading is below 60 bpm or above 120 bpm, an alert will be generated.
- Blood Sugar Alerts: Triggered if blood sugar exceeds safe thresholds (e.g., over 140 mg/dL).
- Blood Pressure Alerts: Triggered for abnormally high readings.
All clinical rules are defined in the rules.json
file and can be easily customized or extended to add new medical checks without changing the core code.
The patients.json
file stores information about patients being monitored and allows multiple patients to be managed simultaneously. Each patient entry includes:
id
: Unique identifier.name
: First name.lastName
: Last name.birthDate
: Birth date [year, month, day].
Example:
[
{
"id": 1,
"name": "José",
"lastName": "Gutiérrez",
"birthDate": [1981, 4, 10]
},
{
"id": 2,
"name": "Ana",
"lastName": "Martínez",
"birthDate": [1990, 6, 21]
}
]
The system is designed to process multiple patients simultaneously and is flexible to adapt to different file formats if needed in the future.
{
"generatedAt": "2025-04-27T14:40:10",
"patients": [
{
"id": 1,
"name": "José",
"lastName": "Gutiérrez",
"birthDate": [1981, 4, 10],
"lastReadingDate": [2025, 4, 25],
"generatedAlerts": ["HighBloodSugar", "LowHeartRate"]
}
]
}
- Real HTTP integration for alert dispatch.
- Database persistence (MySQL/PostgreSQL).
- Automated scheduled processing.
- Enhanced clinical rule engine.