diff --git a/.gitignore b/.gitignore index 8709beb5..f5547d53 100644 --- a/.gitignore +++ b/.gitignore @@ -167,7 +167,8 @@ scrap/ .ruff_cache/ .python-version .cursor/ -.private/ +.local/ +.keys/ .idea/ # Personal AI context (keep local) diff --git a/cookbook/data/mimic_demo_patients/high_risk_bundle.json b/cookbook/data/mimic_demo_patients/high_risk_bundle.json new file mode 100644 index 00000000..ae2ca225 --- /dev/null +++ b/cookbook/data/mimic_demo_patients/high_risk_bundle.json @@ -0,0 +1,413 @@ +{ + "resourceType": "Bundle", + "type": "transaction", + "entry": [ + { + "fullUrl": "urn:uuid:f1f8064e-a37d-4c2b-8002-3efd94d43a26", + "resource": { + "id": "1cf9e585-806c-513b-80af-4ca565a28231", + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-patient" + ] + }, + "name": [ + { + "use": "official", + "family": "Patient_10015860" + } + ], + "gender": "male", + "birthDate": "2133-09-15", + "extension": [ + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2106-3", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "White" + } + }, + { + "url": "text", + "valueString": "White" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2186-5", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "Not Hispanic or Latino" + } + }, + { + "url": "text", + "valueString": "Not Hispanic or Latino" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex", + "valueCode": "M" + } + ], + "identifier": [ + { + "value": "10015860", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/patient" + } + ], + "resourceType": "Patient", + "communication": [ + { + "language": { + "coding": [ + { + "code": "en", + "system": "urn:ietf:bcp:47" + } + ] + } + } + ], + "maritalStatus": { + "coding": [ + { + "code": "S", + "system": "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus" + } + ] + }, + "managingOrganization": { + "reference": "Organization/ee172322-118b-5716-abbc-18e4c5437e15" + } + }, + "request": { + "method": "POST", + "url": "Patient" + } + }, + { + "fullUrl": "urn:uuid:7242a670-6b9d-4a67-a7a9-374658ac6b03", + "resource": { + "id": "1e00686c-4ed2-5acd-bc59-e8c305b95af7", + "code": { + "coding": [ + { + "code": "220045", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Heart Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2192-05-12T17:15:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f1f8064e-a37d-4c2b-8002-3efd94d43a26" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/36ad3455-d2af-514b-ac42-265954a07a0e" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "bpm", + "unit": "bpm", + "value": 108, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2192-05-12T16:49:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:c29b9720-0c2d-4c02-aeeb-7b515ce318b4", + "resource": { + "id": "8f10f571-8183-5b55-b659-107b69ab6fba", + "code": { + "coding": [ + { + "code": "223761", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Temperature Fahrenheit" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2192-05-12T09:46:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f1f8064e-a37d-4c2b-8002-3efd94d43a26" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/36ad3455-d2af-514b-ac42-265954a07a0e" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "\u00b0F", + "unit": "\u00b0F", + "value": 98.4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2192-05-12T09:46:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:4c37b18e-e4a6-4070-83af-c29224ba4fe1", + "resource": { + "id": "3a294f91-6d99-5a23-bc6b-c44d5f69c5db", + "code": { + "coding": [ + { + "code": "220210", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Respiratory Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2192-05-12T17:15:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f1f8064e-a37d-4c2b-8002-3efd94d43a26" + }, + "category": [ + { + "coding": [ + { + "code": "Respiratory", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/36ad3455-d2af-514b-ac42-265954a07a0e" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "insp/min", + "unit": "insp/min", + "value": 17, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2192-05-12T16:49:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:4e3d2d87-f47a-4eb3-bb09-a707f13b5e1e", + "resource": { + "id": "ff849940-4858-59d3-9da8-da8d43aaa808", + "code": { + "coding": [ + { + "code": "51301", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "White Blood Cells" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2188-08-06T08:15:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f1f8064e-a37d-4c2b-8002-3efd94d43a26" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/5f29e513-36c0-5435-a7ab-e6119d10fcc1" + }, + "encounter": { + "reference": "Encounter/dcd2507e-f200-5bfa-a719-c49d94f17fce" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "ROUTINE" + } + ], + "identifier": [ + { + "value": "196686", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "K/uL", + "unit": "K/uL", + "value": 17.8, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "K/uL", + "unit": "K/uL", + "value": 4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "K/uL", + "unit": "K/uL", + "value": 11, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2188-08-06T06:57:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:9e170dfc-714e-4afc-889f-9d15d6f5f6b5", + "resource": { + "id": "5bdf7562-d8cd-5611-9177-4cbafa9b8b19", + "code": { + "coding": [ + { + "code": "50912", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "Creatinine" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2188-08-06T08:54:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f1f8064e-a37d-4c2b-8002-3efd94d43a26" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/2a72c2e8-48b9-5d28-92c6-a0cf35c1ca7c" + }, + "encounter": { + "reference": "Encounter/dcd2507e-f200-5bfa-a719-c49d94f17fce" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "ROUTINE" + } + ], + "identifier": [ + { + "value": "196668", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 2, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 0.5, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 1.2, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2188-08-06T06:57:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + } + ] +} diff --git a/cookbook/data/mimic_demo_patients/high_risk_patient.json b/cookbook/data/mimic_demo_patients/high_risk_patient.json new file mode 100644 index 00000000..2d20486d --- /dev/null +++ b/cookbook/data/mimic_demo_patients/high_risk_patient.json @@ -0,0 +1,390 @@ +{ + "patient": { + "id": "f5efdf3f-5b53-5c9f-95a6-047275107c46", + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-patient" + ] + }, + "name": [ + { + "use": "official", + "family": "Patient_10002495" + } + ], + "gender": "male", + "birthDate": "2060-05-22", + "extension": [ + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "UNK", + "system": "http://terminology.hl7.org/CodeSystem/v3-NullFlavor", + "display": "unknown" + } + }, + { + "url": "text", + "valueString": "unknown" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex", + "valueCode": "M" + } + ], + "identifier": [ + { + "value": "10002495", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/patient" + } + ], + "resourceType": "Patient", + "communication": [ + { + "language": { + "coding": [ + { + "code": "en", + "system": "urn:ietf:bcp:47" + } + ] + } + } + ], + "maritalStatus": { + "coding": [ + { + "code": "M", + "system": "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus" + } + ] + }, + "managingOrganization": { + "reference": "Organization/ee172322-118b-5716-abbc-18e4c5437e15" + } + }, + "heart_rate": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "041a0657-63c0-5828-8301-6dd389649892", + "code": { + "coding": [ + { + "code": "220045", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Heart Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2141-05-23T21:50:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/f5efdf3f-5b53-5c9f-95a6-047275107c46" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/25e05468-7cbf-5a04-9209-79cb07703326" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "bpm", + "unit": "bpm", + "value": 113, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2141-05-23T17:55:00-04:00" + } + } + ] + }, + "temperature": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "69958710-586e-5a29-994c-0f93f9da43dd", + "code": { + "coding": [ + { + "code": "223761", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Temperature Fahrenheit" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2141-05-22T20:32:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/f5efdf3f-5b53-5c9f-95a6-047275107c46" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/25e05468-7cbf-5a04-9209-79cb07703326" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "\u00b0F", + "unit": "\u00b0F", + "value": 98.7, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2141-05-22T20:32:00-04:00" + } + } + ] + }, + "respiratory_rate": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "9f0d5f36-58c1-5e3c-a645-9ac6eed4eeca", + "code": { + "coding": [ + { + "code": "220210", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Respiratory Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2141-05-23T21:50:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/f5efdf3f-5b53-5c9f-95a6-047275107c46" + }, + "category": [ + { + "coding": [ + { + "code": "Respiratory", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/25e05468-7cbf-5a04-9209-79cb07703326" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "insp/min", + "unit": "insp/min", + "value": 25, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2141-05-23T17:55:00-04:00" + } + } + ] + }, + "wbc": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "943aa613-4410-5792-8286-eb0a7637de4b", + "code": { + "coding": [ + { + "code": "51301", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "White Blood Cells" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2141-05-23T15:28:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/f5efdf3f-5b53-5c9f-95a6-047275107c46" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/122994a4-a976-501c-813d-994c1ab5742d" + }, + "encounter": { + "reference": "Encounter/3e802913-a3f3-573f-90b3-a85dffdec47b" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "ROUTINE" + } + ], + "identifier": [ + { + "value": "32427", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "K/uL", + "unit": "K/uL", + "value": 28.5, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "K/uL", + "unit": "K/uL", + "value": 4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "K/uL", + "unit": "K/uL", + "value": 10, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2141-05-23T14:53:00-04:00" + } + } + ] + }, + "creatinine": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "9c9eab28-b23d-56ce-a2e0-e3fa0201cc9a", + "code": { + "coding": [ + { + "code": "50912", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "Creatinine" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2141-05-23T12:34:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/f5efdf3f-5b53-5c9f-95a6-047275107c46" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/c191d9dd-50e4-5d7c-bb05-cbe8b2e72772" + }, + "encounter": { + "reference": "Encounter/3e802913-a3f3-573f-90b3-a85dffdec47b" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "STAT" + } + ], + "identifier": [ + { + "value": "32407", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 1.6, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 0.5, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 1.2, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2141-05-23T10:52:00-04:00" + } + } + ] + } +} diff --git a/cookbook/data/mimic_demo_patients/low_risk_bundle.json b/cookbook/data/mimic_demo_patients/low_risk_bundle.json new file mode 100644 index 00000000..aa30f6ad --- /dev/null +++ b/cookbook/data/mimic_demo_patients/low_risk_bundle.json @@ -0,0 +1,413 @@ +{ + "resourceType": "Bundle", + "type": "transaction", + "entry": [ + { + "fullUrl": "urn:uuid:f6f0dd59-e75c-4562-9150-ea4a0b5321b3", + "resource": { + "id": "afa7c67f-82b9-5f51-bd04-8b7d7c4456c0", + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-patient" + ] + }, + "name": [ + { + "use": "official", + "family": "Patient_10016150" + } + ], + "gender": "male", + "birthDate": "2073-05-10", + "extension": [ + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2106-3", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "White" + } + }, + { + "url": "text", + "valueString": "White" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2186-5", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "Not Hispanic or Latino" + } + }, + { + "url": "text", + "valueString": "Not Hispanic or Latino" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex", + "valueCode": "M" + } + ], + "identifier": [ + { + "value": "10016150", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/patient" + } + ], + "resourceType": "Patient", + "communication": [ + { + "language": { + "coding": [ + { + "code": "en", + "system": "urn:ietf:bcp:47" + } + ] + } + } + ], + "maritalStatus": { + "coding": [ + { + "code": "S", + "system": "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus" + } + ] + }, + "managingOrganization": { + "reference": "Organization/ee172322-118b-5716-abbc-18e4c5437e15" + } + }, + "request": { + "method": "POST", + "url": "Patient" + } + }, + { + "fullUrl": "urn:uuid:bc20d95c-18b8-4fa8-9095-f05abec6aa78", + "resource": { + "id": "867fe01b-3930-5adf-a45d-f666fecbe864", + "code": { + "coding": [ + { + "code": "220045", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Heart Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2142-05-10T16:59:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f6f0dd59-e75c-4562-9150-ea4a0b5321b3" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/13987fde-e7cc-5dfb-b5e8-cdf2b709a1d4" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "bpm", + "unit": "bpm", + "value": 71, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2142-05-10T16:59:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:e4ce72da-4ab9-4619-adb6-07bc027c728a", + "resource": { + "id": "93664731-abf1-57e1-a3fb-693fa9b07479", + "code": { + "coding": [ + { + "code": "223761", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Temperature Fahrenheit" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2142-05-10T16:59:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f6f0dd59-e75c-4562-9150-ea4a0b5321b3" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/13987fde-e7cc-5dfb-b5e8-cdf2b709a1d4" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "\u00b0F", + "unit": "\u00b0F", + "value": 98.4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2142-05-10T16:59:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:8e23c576-644b-4908-9271-1935d06aff54", + "resource": { + "id": "e9532f81-3f62-5af3-a095-d027492f7e01", + "code": { + "coding": [ + { + "code": "220210", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Respiratory Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2142-05-10T16:59:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f6f0dd59-e75c-4562-9150-ea4a0b5321b3" + }, + "category": [ + { + "coding": [ + { + "code": "Respiratory", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/13987fde-e7cc-5dfb-b5e8-cdf2b709a1d4" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "insp/min", + "unit": "insp/min", + "value": 33, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2142-05-10T16:59:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:46fe4954-70f4-4652-9d40-15c9598ce545", + "resource": { + "id": "759f2c85-3345-5d7a-8bbb-252d4d7ac5b0", + "code": { + "coding": [ + { + "code": "51301", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "White Blood Cells" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2142-05-10T16:09:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f6f0dd59-e75c-4562-9150-ea4a0b5321b3" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/b0afc9eb-baad-5d87-a7d8-d6eaf699cf96" + }, + "encounter": { + "reference": "Encounter/ef3c0803-f981-59f7-a022-0d1223377142" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "STAT" + } + ], + "identifier": [ + { + "value": "202620", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "K/uL", + "unit": "K/uL", + "value": 5.4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "K/uL", + "unit": "K/uL", + "value": 4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "K/uL", + "unit": "K/uL", + "value": 11, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2142-05-10T15:37:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:7d4a5e58-ad87-43d3-bc7c-b89df25c2308", + "resource": { + "id": "7461ac2f-33f1-508b-9eef-bf5c23dd9b8d", + "code": { + "coding": [ + { + "code": "50912", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "Creatinine" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2142-05-14T10:23:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:f6f0dd59-e75c-4562-9150-ea4a0b5321b3" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/d936d365-0a43-52e0-b440-26db28d3bbf0" + }, + "encounter": { + "reference": "Encounter/ef3c0803-f981-59f7-a022-0d1223377142" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "ROUTINE" + } + ], + "identifier": [ + { + "value": "202713", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 0.9, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 0.5, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 1.2, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2142-05-14T08:30:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + } + ] +} diff --git a/cookbook/data/mimic_demo_patients/low_risk_patient.json b/cookbook/data/mimic_demo_patients/low_risk_patient.json new file mode 100644 index 00000000..5cb18e13 --- /dev/null +++ b/cookbook/data/mimic_demo_patients/low_risk_patient.json @@ -0,0 +1,407 @@ +{ + "patient": { + "id": "5f3dcdb5-bd27-58f5-b990-859b6bcc2d73", + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-patient" + ] + }, + "name": [ + { + "use": "official", + "family": "Patient_10038999" + } + ], + "gender": "male", + "birthDate": "2086-05-22", + "extension": [ + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2106-3", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "White" + } + }, + { + "url": "text", + "valueString": "White" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2186-5", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "Not Hispanic or Latino" + } + }, + { + "url": "text", + "valueString": "Not Hispanic or Latino" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex", + "valueCode": "M" + } + ], + "identifier": [ + { + "value": "10038999", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/patient" + } + ], + "resourceType": "Patient", + "communication": [ + { + "language": { + "coding": [ + { + "code": "en", + "system": "urn:ietf:bcp:47" + } + ] + } + } + ], + "maritalStatus": { + "coding": [ + { + "code": "S", + "system": "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus" + } + ] + }, + "managingOrganization": { + "reference": "Organization/ee172322-118b-5716-abbc-18e4c5437e15" + } + }, + "heart_rate": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "ccbb50b3-c1e2-5a78-8f40-fda91f209773", + "code": { + "coding": [ + { + "code": "220045", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Heart Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2131-05-22T22:38:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/5f3dcdb5-bd27-58f5-b990-859b6bcc2d73" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/24339e36-0b8e-5f30-91bc-d4b7d9919c3c" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "bpm", + "unit": "bpm", + "value": 110, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2131-05-22T22:38:00-04:00" + } + } + ] + }, + "temperature": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "3c53284d-5069-54bd-8496-3a739180babe", + "code": { + "coding": [ + { + "code": "223761", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Temperature Fahrenheit" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2131-05-22T22:38:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/5f3dcdb5-bd27-58f5-b990-859b6bcc2d73" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/24339e36-0b8e-5f30-91bc-d4b7d9919c3c" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "\u00b0F", + "unit": "\u00b0F", + "value": 98.8, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2131-05-22T22:38:00-04:00" + } + } + ] + }, + "respiratory_rate": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "9331ed77-b563-5abe-bf84-4ac7053b9fe9", + "code": { + "coding": [ + { + "code": "220210", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Respiratory Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2131-05-22T22:38:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/5f3dcdb5-bd27-58f5-b990-859b6bcc2d73" + }, + "category": [ + { + "coding": [ + { + "code": "Respiratory", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/24339e36-0b8e-5f30-91bc-d4b7d9919c3c" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "insp/min", + "unit": "insp/min", + "value": 20, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2131-05-22T22:38:00-04:00" + } + } + ] + }, + "wbc": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "0b9aaaa5-43c1-51a5-b1d2-a6156968513e", + "code": { + "coding": [ + { + "code": "51301", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "White Blood Cells" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2131-05-28T03:24:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/5f3dcdb5-bd27-58f5-b990-859b6bcc2d73" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/6025339e-8821-54a8-99dc-ae56d8c705d1" + }, + "encounter": { + "reference": "Encounter/7f95fc8e-1f36-54a6-96f9-798fd9c7e93b" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "STAT" + } + ], + "identifier": [ + { + "value": "455202", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "K/uL", + "unit": "K/uL", + "value": 8.6, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "K/uL", + "unit": "K/uL", + "value": 4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "K/uL", + "unit": "K/uL", + "value": 10, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2131-05-28T02:56:00-04:00" + } + } + ] + }, + "creatinine": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "e9ea65d0-b198-58c1-bcbe-e436150d6e4d", + "code": { + "coding": [ + { + "code": "50912", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "Creatinine" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2131-05-28T03:37:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/5f3dcdb5-bd27-58f5-b990-859b6bcc2d73" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/00d5feac-4fe1-5fdb-ac62-01bff201f55c" + }, + "encounter": { + "reference": "Encounter/7f95fc8e-1f36-54a6-96f9-798fd9c7e93b" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "STAT" + } + ], + "identifier": [ + { + "value": "455210", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 0.8, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 0.5, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 1.2, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2131-05-28T02:56:00-04:00" + } + } + ] + } +} diff --git a/cookbook/data/mimic_demo_patients/moderate_risk_bundle.json b/cookbook/data/mimic_demo_patients/moderate_risk_bundle.json new file mode 100644 index 00000000..869c0676 --- /dev/null +++ b/cookbook/data/mimic_demo_patients/moderate_risk_bundle.json @@ -0,0 +1,413 @@ +{ + "resourceType": "Bundle", + "type": "transaction", + "entry": [ + { + "fullUrl": "urn:uuid:a6f47e5c-2ee6-4a71-ae52-6cdb2edd5122", + "resource": { + "id": "72d56b49-a7ee-5b9a-a679-25d1c836d3c3", + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-patient" + ] + }, + "name": [ + { + "use": "official", + "family": "Patient_10018845" + } + ], + "gender": "male", + "birthDate": "2093-10-07", + "extension": [ + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2106-3", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "White" + } + }, + { + "url": "text", + "valueString": "White" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2186-5", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "Not Hispanic or Latino" + } + }, + { + "url": "text", + "valueString": "Not Hispanic or Latino" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex", + "valueCode": "M" + } + ], + "identifier": [ + { + "value": "10018845", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/patient" + } + ], + "resourceType": "Patient", + "communication": [ + { + "language": { + "coding": [ + { + "code": "en", + "system": "urn:ietf:bcp:47" + } + ] + } + } + ], + "maritalStatus": { + "coding": [ + { + "code": "M", + "system": "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus" + } + ] + }, + "deceasedDateTime": "2184-11-22", + "managingOrganization": { + "reference": "Organization/ee172322-118b-5716-abbc-18e4c5437e15" + } + }, + "request": { + "method": "POST", + "url": "Patient" + } + }, + { + "fullUrl": "urn:uuid:7b9f0473-b12c-49ea-9cec-0af73dccb83c", + "resource": { + "id": "ff7c1328-fe32-5574-b842-144ba3ac8fb0", + "code": { + "coding": [ + { + "code": "220045", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Heart Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2184-10-08T04:31:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:a6f47e5c-2ee6-4a71-ae52-6cdb2edd5122" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/625b0a9e-a378-5e68-b8d6-10c655f7579d" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "bpm", + "unit": "bpm", + "value": 58, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2184-10-08T04:31:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:9eebab6a-909d-424a-baa9-0a155a54f13a", + "resource": { + "id": "4664e5eb-efaa-5062-a594-f20c0b10d901", + "code": { + "coding": [ + { + "code": "223761", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Temperature Fahrenheit" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2184-10-08T04:31:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:a6f47e5c-2ee6-4a71-ae52-6cdb2edd5122" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/625b0a9e-a378-5e68-b8d6-10c655f7579d" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "\u00b0F", + "unit": "\u00b0F", + "value": 98, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2184-10-08T04:31:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:f1358348-72a0-411b-9413-d9261ae6b92a", + "resource": { + "id": "1ac7341b-9efc-5101-a4bf-b5fa5de755dd", + "code": { + "coding": [ + { + "code": "220210", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Respiratory Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2184-10-08T04:31:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:a6f47e5c-2ee6-4a71-ae52-6cdb2edd5122" + }, + "category": [ + { + "coding": [ + { + "code": "Respiratory", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/625b0a9e-a378-5e68-b8d6-10c655f7579d" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "insp/min", + "unit": "insp/min", + "value": 13, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2184-10-08T04:31:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:b868d1ac-4537-43a1-aafa-3438e8c6a28d", + "resource": { + "id": "41599527-6e37-53ce-b710-8d1d071d28eb", + "code": { + "coding": [ + { + "code": "51301", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "White Blood Cells" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2184-10-08T02:08:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:a6f47e5c-2ee6-4a71-ae52-6cdb2edd5122" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/f3e2cbca-c799-5acd-85f1-4c3fd56f7dd9" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "STAT" + } + ], + "identifier": [ + { + "value": "222110", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "K/uL", + "unit": "K/uL", + "value": 5.9, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "K/uL", + "unit": "K/uL", + "value": 4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "K/uL", + "unit": "K/uL", + "value": 11, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2184-10-08T00:50:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + }, + { + "fullUrl": "urn:uuid:8375eaf0-8196-485b-84a2-7a200610d2e4", + "resource": { + "id": "164745e6-16e5-5ded-95c2-3094a9cc0ac6", + "code": { + "coding": [ + { + "code": "50912", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "Creatinine" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "note": [ + { + "text": "VERIFIED - CONSISTENT WITH OTHER DATA." + } + ], + "issued": "2184-10-08T02:09:00-04:00", + "status": "final", + "subject": { + "reference": "urn:uuid:a6f47e5c-2ee6-4a71-ae52-6cdb2edd5122" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/7991a26f-45ad-5d40-b4b9-2a17467b13c9" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "STAT" + } + ], + "identifier": [ + { + "value": "222087", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 5, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 0.5, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 1.2, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2184-10-08T00:50:00-04:00" + }, + "request": { + "method": "POST", + "url": "Observation" + } + } + ] +} diff --git a/cookbook/data/mimic_demo_patients/moderate_risk_patient.json b/cookbook/data/mimic_demo_patients/moderate_risk_patient.json new file mode 100644 index 00000000..c8aaf1b3 --- /dev/null +++ b/cookbook/data/mimic_demo_patients/moderate_risk_patient.json @@ -0,0 +1,408 @@ +{ + "patient": { + "id": "22a3e422-663a-561c-b305-a0c04bf42235", + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-patient" + ] + }, + "name": [ + { + "use": "official", + "family": "Patient_10021666" + } + ], + "gender": "male", + "birthDate": "2085-03-12", + "extension": [ + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2106-3", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "White" + } + }, + { + "url": "text", + "valueString": "White" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity", + "extension": [ + { + "url": "ombCategory", + "valueCoding": { + "code": "2186-5", + "system": "urn:oid:2.16.840.1.113883.6.238", + "display": "Not Hispanic or Latino" + } + }, + { + "url": "text", + "valueString": "Not Hispanic or Latino" + } + ] + }, + { + "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex", + "valueCode": "M" + } + ], + "identifier": [ + { + "value": "10021666", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/patient" + } + ], + "resourceType": "Patient", + "communication": [ + { + "language": { + "coding": [ + { + "code": "en", + "system": "urn:ietf:bcp:47" + } + ] + } + } + ], + "maritalStatus": { + "coding": [ + { + "code": "M", + "system": "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus" + } + ] + }, + "deceasedDateTime": "2172-04-19", + "managingOrganization": { + "reference": "Organization/ee172322-118b-5716-abbc-18e4c5437e15" + } + }, + "heart_rate": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "01093aef-0cf5-5af0-b5c1-92ca3d7deaf2", + "code": { + "coding": [ + { + "code": "220045", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Heart Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2172-03-13T02:02:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/22a3e422-663a-561c-b305-a0c04bf42235" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/ffce7398-83de-5c56-833d-dfcb02d1abac" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "bpm", + "unit": "bpm", + "value": 70, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2172-03-13T01:56:00-04:00" + } + } + ] + }, + "temperature": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "476c79e7-cdba-5f17-8bee-f0f5bcbaa845", + "code": { + "coding": [ + { + "code": "223761", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Temperature Fahrenheit" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2172-03-13T02:02:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/22a3e422-663a-561c-b305-a0c04bf42235" + }, + "category": [ + { + "coding": [ + { + "code": "Routine Vital Signs", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/ffce7398-83de-5c56-833d-dfcb02d1abac" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "\u00b0F", + "unit": "\u00b0F", + "value": 99.4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2172-03-13T02:01:00-04:00" + } + } + ] + }, + "respiratory_rate": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "e22290e7-e08c-5e0d-9929-eba8ad24c97a", + "code": { + "coding": [ + { + "code": "220210", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-chartevents-d-items", + "display": "Respiratory Rate" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-chartevents" + ] + }, + "issued": "2172-03-13T02:02:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/22a3e422-663a-561c-b305-a0c04bf42235" + }, + "category": [ + { + "coding": [ + { + "code": "Respiratory", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-observation-category" + } + ] + } + ], + "encounter": { + "reference": "Encounter/ffce7398-83de-5c56-833d-dfcb02d1abac" + }, + "resourceType": "Observation", + "valueQuantity": { + "code": "insp/min", + "unit": "insp/min", + "value": 14, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "effectiveDateTime": "2172-03-13T01:56:00-04:00" + } + } + ] + }, + "wbc": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "b78e2882-469d-566f-bcfe-f47388cb72f0", + "code": { + "coding": [ + { + "code": "51301", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "White Blood Cells" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2172-03-15T13:18:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/22a3e422-663a-561c-b305-a0c04bf42235" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/3d1deb9c-3aa2-5bd7-a3c8-3f1766530dc2" + }, + "encounter": { + "reference": "Encounter/f96dcfb3-1c84-5040-b9b9-c227d21a21a1" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "ROUTINE" + } + ], + "identifier": [ + { + "value": "257293", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "K/uL", + "unit": "K/uL", + "value": 10.5, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "K/uL", + "unit": "K/uL", + "value": 4, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "K/uL", + "unit": "K/uL", + "value": 11, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2172-03-15T11:56:00-04:00" + } + } + ] + }, + "creatinine": { + "resourceType": "Bundle", + "type": "searchset", + "entry": [ + { + "resource": { + "id": "ab2d4a21-fd85-5263-b909-4d92d0c50dac", + "code": { + "coding": [ + { + "code": "50912", + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-d-labitems", + "display": "Creatinine" + } + ] + }, + "meta": { + "profile": [ + "http://mimic.mit.edu/fhir/mimic/StructureDefinition/mimic-observation-labevents" + ] + }, + "issued": "2172-03-15T14:02:00-04:00", + "status": "final", + "subject": { + "reference": "Patient/22a3e422-663a-561c-b305-a0c04bf42235" + }, + "category": [ + { + "coding": [ + { + "code": "laboratory", + "system": "http://terminology.hl7.org/CodeSystem/observation-category", + "display": "Laboratory" + } + ] + } + ], + "specimen": { + "reference": "Specimen/99911b05-1540-5236-9689-e9594cc8aeed" + }, + "encounter": { + "reference": "Encounter/f96dcfb3-1c84-5040-b9b9-c227d21a21a1" + }, + "extension": [ + { + "url": "http://mimic.mit.edu/fhir/mimic/StructureDefinition/lab-priority", + "valueString": "ROUTINE" + } + ], + "identifier": [ + { + "value": "257298", + "system": "http://mimic.mit.edu/fhir/mimic/identifier/observation-labevents" + } + ], + "resourceType": "Observation", + "valueQuantity": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 1.2, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "referenceRange": [ + { + "low": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 0.5, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + }, + "high": { + "code": "mg/dL", + "unit": "mg/dL", + "value": 1.2, + "system": "http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-units" + } + } + ], + "effectiveDateTime": "2172-03-15T11:56:00-04:00" + } + } + ] + } +} diff --git a/cookbook/sepsis_cds_hooks.py b/cookbook/sepsis_cds_hooks.py new file mode 100644 index 00000000..ff70be67 --- /dev/null +++ b/cookbook/sepsis_cds_hooks.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python3 +""" +Sepsis Risk Prediction via CDS Hooks + +Real-time sepsis alerts triggered when clinician opens a patient chart. +Uses pre-extracted MIMIC patient data for demos. + +Demo patients extracted from MIMIC-on-FHIR using: + python scripts/extract_mimic_demo_patients.py + +Requirements: + pip install healthchain joblib xgboost + +Run: + python cookbook/sepsis_cds_hooks.py +""" + +from pathlib import Path + +import joblib +from dotenv import load_dotenv + +from healthchain.gateway import HealthChainAPI, CDSHooksService +from healthchain.fhir import prefetch_to_bundle +from healthchain.io import Dataset +from healthchain.models import CDSRequest, CDSResponse +from healthchain.models.responses.cdsresponse import Card +from healthchain.pipeline import Pipeline + +load_dotenv() + +# Configuration +SCRIPT_DIR = Path(__file__).parent +MODEL_PATH = SCRIPT_DIR / "models" / "sepsis_model.pkl" +SCHEMA_PATH = ( + SCRIPT_DIR / ".." / "healthchain" / "configs" / "features" / "sepsis_vitals.yaml" +) +DEMO_PATIENTS_DIR = SCRIPT_DIR / "data" / "mimic_demo_patients" + +# Load model +model_data = joblib.load(MODEL_PATH) +model = model_data["model"] +feature_names = model_data["metadata"]["feature_names"] +threshold = model_data["metadata"]["metrics"].get("optimal_threshold", 0.5) + + +def create_pipeline() -> Pipeline[Dataset]: + """Build sepsis prediction pipeline.""" + pipeline = Pipeline[Dataset]() + + @pipeline.add_node + def impute_missing(dataset: Dataset) -> Dataset: + dataset.data = dataset.data.fillna(dataset.data.median(numeric_only=True)) + return dataset + + @pipeline.add_node + def run_inference(dataset: Dataset) -> Dataset: + features = dataset.data[feature_names] + probabilities = model.predict_proba(features)[:, 1] + dataset.metadata["probabilities"] = probabilities + return dataset + + return pipeline + + +def create_app(): + pipeline = create_pipeline() + cds = CDSHooksService() + + @cds.hook("patient-view", id="sepsis-risk") + def sepsis_alert(request: CDSRequest) -> CDSResponse: + prefetch = request.prefetch or {} + if not prefetch: + return CDSResponse(cards=[]) + + # Flatten keyed prefetch into single bundle + bundle = prefetch_to_bundle(prefetch) + + # FHIR → Dataset → Prediction + dataset = Dataset.from_fhir_bundle(bundle, schema=SCHEMA_PATH) + result = pipeline(dataset) + + # print("Result:") + # print(result.data.head(10)) + + probability = float(result.metadata["probabilities"][0]) + risk = ( + "high" if probability > 0.7 else "moderate" if probability > 0.4 else "low" + ) + + if risk in ["high", "moderate"]: + summary = f"Sepsis Risk: {risk.upper()} ({probability:.0%})" + indicator = "critical" if risk == "high" else "warning" + detail = ( + "**AI Guidance:**\n" + f"- Predicted risk: **{risk.upper()}** ({probability:.0%})\n" + "- Recommend sepsis workup and early intervention." + ) + title = "Sepsis Alert (AI Prediction)" + source = { + "label": "HealthChain Sepsis Predictor", + "url": "https://www.sccm.org/SurvivingSepsisCampaign/Guidelines/Adult-Patients", + } + return CDSResponse( + cards=[ + Card( + summary=summary, + indicator=indicator, + detail=detail, + source=source, + title=title, + ) + ] + ) + + return CDSResponse(cards=[]) + + app = HealthChainAPI(title="Sepsis CDS Hooks") + app.register_service(cds, path="/cds") + + return app + + +app = create_app() + + +if __name__ == "__main__": + import threading + import uvicorn + from time import sleep + from healthchain.sandbox import SandboxClient + + # Start server + def run_server(): + uvicorn.run(app, port=8000, log_level="warning") + + server = threading.Thread(target=run_server, daemon=True) + server.start() + sleep(2) + + # Test with pre-extracted demo patients (fast, realistic per-patient data) + client = SandboxClient( + url="http://localhost:8000/cds/cds-services/sepsis-risk", + workflow="patient-view", + ) + client.load_from_path(DEMO_PATIENTS_DIR, pattern="*_patient.json") + responses = client.send_requests() + client.save_results(save_request=True, save_response=True, directory="./output/") + + print(f"\nProcessed {len(responses)} requests") + for i, resp in enumerate(responses): + cards = resp.get("cards", []) + if cards: + print(f" Patient {i+1}: {cards[0].get('summary', 'No alert')}") + else: + print(f" Patient {i+1}: Low risk (no alert)") + + server.join() diff --git a/cookbook/sepsis_fhir_batch.py b/cookbook/sepsis_fhir_batch.py new file mode 100644 index 00000000..3c41dcb7 --- /dev/null +++ b/cookbook/sepsis_fhir_batch.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python3 +""" +Sepsis Batch Screening with FHIR Gateway + +Query patients from a FHIR server, batch run sepsis predictions, and write +RiskAssessment resources back. Demonstrates real FHIR server integration. + +Setup: + 1. Extract and upload demo patients: + python scripts/extract_mimic_demo_patients.py --minimal --upload + 2. Update DEMO_PATIENT_IDS below with the server-assigned IDs + 3. Set env vars: MEDPLUM_CLIENT_ID, MEDPLUM_CLIENT_SECRET, MEDPLUM_BASE_URL + +Run: + python cookbook/sepsis_fhir_batch.py +""" + +from pathlib import Path +from typing import List + +import joblib +import logging +from dotenv import load_dotenv +from fhir.resources.patient import Patient +from fhir.resources.observation import Observation +from fhir.resources.riskassessment import RiskAssessment + +from healthchain.gateway import HealthChainAPI, FHIRGateway +from healthchain.gateway.clients.fhir.base import FHIRAuthConfig +from healthchain.fhir import merge_bundles +from healthchain.io import Dataset +from healthchain.pipeline import Pipeline + +load_dotenv() + +logger = logging.getLogger(__name__) + +# Configuration +SCRIPT_DIR = Path(__file__).parent +MODEL_PATH = SCRIPT_DIR / "models" / "sepsis_model.pkl" +SCHEMA_PATH = ( + SCRIPT_DIR / ".." / "healthchain" / "configs" / "features" / "sepsis_vitals.yaml" +) + +# Load model +model_data = joblib.load(MODEL_PATH) +model = model_data["model"] +feature_names = model_data["metadata"]["feature_names"] +threshold = model_data["metadata"]["metrics"].get("optimal_threshold", 0.5) + +# FHIR sources (configure via environment) +MEDPLUM_URL = None +EPIC_URL = None + +try: + config = FHIRAuthConfig.from_env("MEDPLUM") + MEDPLUM_URL = config.to_connection_string() +except Exception: + logger.warning("Failed to load Medplum config") + +try: + config = FHIRAuthConfig.from_env("EPIC") + EPIC_URL = config.to_connection_string() +except Exception: + logger.warning("Failed to load Epic config") + + +def get_risk_summary(ra: RiskAssessment) -> tuple[str, float]: + """Extract risk level and probability from a RiskAssessment.""" + pred = ra.prediction[0] + return pred.qualitativeRisk.coding[0].code, pred.probabilityDecimal + + +def create_pipeline() -> Pipeline[Dataset]: + """Build sepsis prediction pipeline.""" + pipeline = Pipeline[Dataset]() + + @pipeline.add_node + def impute_missing(dataset: Dataset) -> Dataset: + dataset.data = dataset.data.fillna(dataset.data.median(numeric_only=True)) + return dataset + + @pipeline.add_node + def run_inference(dataset: Dataset) -> Dataset: + features = dataset.data[feature_names] + probabilities = model.predict_proba(features)[:, 1] + predictions = (probabilities >= threshold).astype(int) + dataset.metadata["predictions"] = predictions + dataset.metadata["probabilities"] = probabilities + return dataset + + return pipeline + + +def screen_patient( + gateway: FHIRGateway, pipeline: Pipeline, patient_id: str, source: str +) -> RiskAssessment | None: + """Screen a single patient for sepsis risk. Returns RiskAssessment or None.""" + # Query patient data from FHIR server + obs_bundle = gateway.search( + Observation, {"patient": patient_id, "_count": "100"}, source + ) + patient_bundle = gateway.search(Patient, {"_id": patient_id}, source) + + # Merge into single bundle + bundle = merge_bundles([patient_bundle, obs_bundle]) + + if not bundle.entry: + return None + + # FHIR → Dataset → Prediction + dataset = Dataset.from_fhir_bundle(bundle, schema=str(SCHEMA_PATH)) + + if len(dataset.data) == 0: + return None + + result = pipeline(dataset) + + # Create and save RiskAssessment + risk_assessments = result.to_risk_assessment( + outcome_code="A41.9", + outcome_display="Sepsis", + model_name="sepsis_xgboost_v1", + ) + + for ra in risk_assessments: + gateway.create(ra, source=source) + + return risk_assessments[0] if risk_assessments else None + + +def batch_screen( + gateway: FHIRGateway, patient_ids: List[str], source: str = "medplum" +) -> None: + """Screen multiple patients for sepsis risk.""" + pipeline = create_pipeline() + + for patient_id in patient_ids: + try: + ra = screen_patient(gateway, pipeline, patient_id, source) + if ra: + risk, prob = get_risk_summary(ra) + print( + f" {patient_id}: {risk.upper()} ({prob:.0%}) → RiskAssessment/{ra.id}" + ) + else: + print(f" {patient_id}: No data") + except Exception as e: + print(f" {patient_id}: Error - {e}") + + +def create_app(): + """Create FHIR gateway app with configured sources.""" + gateway = FHIRGateway() + + # Add configured sources + if MEDPLUM_URL: + gateway.add_source("medplum", MEDPLUM_URL) + logger.info("✓ Medplum configured") + if EPIC_URL: + gateway.add_source("epic", EPIC_URL) + logger.info("✓ Epic configured") + + app = HealthChainAPI(title="Sepsis Batch Screening") + app.register_gateway(gateway, path="/fhir") + + return app, gateway + + +app, gateway = create_app() + + +if __name__ == "__main__": + # Demo patient IDs from: python scripts/extract_mimic_demo_patients.py --minimal --upload + # (Update these with server-assigned IDs after upload) + DEMO_PATIENT_IDS = [ + "702e11e8-6d21-41dd-9b48-31715fdc0fb1", # high risk + "3b0da7e9-0379-455a-8d35-bedd3a6ee459", # moderate risk + "f490ceb4-6262-4f1e-8b72-5515e6c46741", # low risk + ] + + # Screen Medplum patients + if MEDPLUM_URL: + print("\n=== Screening patients from Medplum ===") + batch_screen(gateway, DEMO_PATIENT_IDS, source="medplum") + + # Demo Epic connectivity (data may not match sepsis features) + if EPIC_URL: + print("\n=== Epic Sandbox (demo connectivity) ===") + batch_screen(gateway, ["e0w0LEDCYtfckT6N.CkJKCw3"], source="epic") diff --git a/docs/cookbook/index.md b/docs/cookbook/index.md index e64b6d3c..165624b6 100644 --- a/docs/cookbook/index.md +++ b/docs/cookbook/index.md @@ -13,6 +13,9 @@ Dive into real-world, production-ready examples to learn how to build interopera ## 📚 How-To Guides +- 🔬 **[Deploy ML Models: Real-Time Alerts & Batch Screening](./ml_model_deployment.md)** + *Deploy the same ML model two ways: CDS Hooks for point-of-care sepsis alerts, and FHIR Gateway for population-level batch screening with RiskAssessment resources.* + - 🚦 **[Multi-Source Patient Data Aggregation](./multi_ehr_aggregation.md)** *Merge patient data from multiple FHIR sources (Epic, Cerner, etc.), deduplicate conditions, prove provenance, and robustly handle cross-vendor errors. Foundation for retrieval-augmented generation (RAG) and analytics workflows.* diff --git a/docs/cookbook/ml_model_deployment.md b/docs/cookbook/ml_model_deployment.md index 74fa87c1..9c878a15 100644 --- a/docs/cookbook/ml_model_deployment.md +++ b/docs/cookbook/ml_model_deployment.md @@ -1,64 +1,517 @@ -# Deploy ML Models as Healthcare APIs +# Deploy ML Models: Real-Time Alerts & Batch Screening -*This example is coming soon! 🚧* +You trained a model on CSVs. Now you need to deploy it against FHIR data from EHRs. This tutorial shows how to bridge that gap with two production patterns: **real-time CDS Hooks alerts** and **batch FHIR Gateway screening**—both using the same model and a simple YAML schema that maps FHIR resources to your training features. -
-| \n", + " | patient_ref | \n", + "heart_rate | \n", + "temperature | \n", + "respiratory_rate | \n", + "wbc | \n", + "lactate | \n", + "creatinine | \n", + "age | \n", + "gender_encoded | \n", + "
|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", + "Patient/0a8eebfd-a352-522e-89f0-1d4a13abdebc | \n", + "96.500000 | \n", + "98.966667 | \n", + "20.700000 | \n", + "5.815385 | \n", + "31.0 | \n", + "0.466667 | \n", + "52 | \n", + "0 | \n", + "
| 1 | \n", + "Patient/0c2243d2-987b-5cbd-8eb1-170a80647693 | \n", + "85.379310 | \n", + "98.135294 | \n", + "12.103448 | \n", + "7.737500 | \n", + "66.5 | \n", + "0.594937 | \n", + "57 | \n", + "1 | \n", + "
| 2 | \n", + "Patient/13df78e7-150e-5eb7-be5f-5f62b2baee87 | \n", + "104.307692 | \n", + "98.375000 | \n", + "15.961538 | \n", + "8.337500 | \n", + "NaN | \n", + "0.966667 | \n", + "66 | \n", + "1 | \n", + "
| 3 | \n", + "Patient/158f3a39-e3d7-5e7a-93aa-57af894aadd9 | \n", + "99.739130 | \n", + "98.390000 | \n", + "18.358696 | \n", + "11.509091 | \n", + "NaN | \n", + "0.628571 | \n", + "40 | \n", + "0 | \n", + "
| 4 | \n", + "Patient/1ab119a5-aac8-5002-9d2f-b8ff69623387 | \n", + "93.402985 | \n", + "98.824242 | \n", + "21.753731 | \n", + "15.578571 | \n", + "NaN | \n", + "0.646667 | \n", + "34 | \n", + "1 | \n", + "
| 5 | \n", + "Patient/1bb918ba-e04e-5e7a-87ca-dbcbbb4c72c3 | \n", + "78.181818 | \n", + "98.725000 | \n", + "16.961538 | \n", + "22.906250 | \n", + "NaN | \n", + "0.756667 | \n", + "38 | \n", + "0 | \n", + "
| 6 | \n", + "Patient/1cf9e585-806c-513b-80af-4ca565a28231 | \n", + "104.666667 | \n", + "98.810000 | \n", + "19.388889 | \n", + "12.520952 | \n", + "NaN | \n", + "3.847321 | \n", + "53 | \n", + "1 | \n", + "
| 7 | \n", + "Patient/22a3e422-663a-561c-b305-a0c04bf42235 | \n", + "69.050000 | \n", + "98.800000 | \n", + "16.900000 | \n", + "10.754545 | \n", + "NaN | \n", + "1.353846 | \n", + "87 | \n", + "1 | \n", + "
| 8 | \n", + "Patient/23069939-0c4c-517b-a3ec-baae0d4e3988 | \n", + "78.694444 | \n", + "98.325000 | \n", + "16.055556 | \n", + "9.383333 | \n", + "NaN | \n", + "0.860000 | \n", + "52 | \n", + "1 | \n", + "
| 9 | \n", + "Patient/23f959c1-6ac2-562b-9cbe-c111f338e27b | \n", + "87.184524 | \n", + "98.827091 | \n", + "17.251497 | \n", + "14.954054 | \n", + "NaN | \n", + "0.642105 | \n", + "51 | \n", + "1 | \n", + "