feat: resolve UNKNOWN patient ID and support auto-registration and active monitor fallbacks
This commit is contained in:
@@ -262,6 +262,17 @@ async def process_vitals(vitals):
|
||||
device.last_seen = datetime.now(timezone.utc)
|
||||
|
||||
# 2. Patient tracking — store/update demographics from HL7
|
||||
if vitals.patient_id == "UNKNOWN":
|
||||
last_known_reading = (
|
||||
db.query(VitalReading)
|
||||
.filter(VitalReading.device_id == vitals.device_id)
|
||||
.filter(VitalReading.patient_id != "UNKNOWN")
|
||||
.order_by(VitalReading.timestamp.desc())
|
||||
.first()
|
||||
)
|
||||
if last_known_reading:
|
||||
vitals.patient_id = last_known_reading.patient_id
|
||||
|
||||
patient = db.query(Patient).filter(Patient.patient_id == vitals.patient_id).first()
|
||||
if not patient:
|
||||
patient = Patient(
|
||||
|
||||
Reference in New Issue
Block a user