using SYSTEM
As demographic data does not reside inside EHRs, there should be an upper structure usable in queries that combines EHRs with demographics. This is especially needed for those settings facilitating querying across multi-tenant’s data, or when EHRs are clustered on the server side.
The right structure to consider in queries, that acts as a namespace for the data is the SYSTEM. This is not yet an openEHR type, although is assumed in few places in openEHR specifications: EHR.system_id, VERSIONED_OBJECT.owner_id and in OBJECT_VERSION_ID.creating_system_id.
We consider the SYSTEM type will hav following attributes:
uid (UID)
name (DV_TEXT)
location (DV_URI)
details (ITEM_STRUCTURE)
A typical query using system may look like:
SELECT s/uid, s/name, e/ehr_id/value, c/context/start_time FROM SYSTEM s CONTAINS EHR e CONTAINS COMPOSITION c
When SYSTEM is omitted, the query engine query in all selected EHRs will use all available systems.
One aspect to consider is that SYSTEM does not contains actually EHR, but it is the EHR that referrers to owning system. For this matter, if we would like to consider a new keyword (syntax change), for instance WRAPS, we could have:
SELECT s/uid, s/name, e/ehr_id/value, c/context/start_time FROM SYSTEM s WRAPS EHR e CONTAINS COMPOSITION c
Introducing SYSTEM, will allow us to also use demographic data inside same system:
SELECT s/uid, s/name, e/ehr_id/value, c/context/start_time, p/uid/value, p/identities FROM SYSTEM s CONTAINS EHR e CONTAINS COMPOSITION c AND CONTAINS PERSON p WHERE p/uid/value = e/ehr_status/subject/external_ref/id/value
or with more complexity, using an fictive encrpt()
function that is able to match EHR with ACTOR in a environment using master patient indexes:
SELECT s/uid, s/name, e/ehr_id/value, c/context/start_time, p/uid/value, pid/item/value FROM SYSTEM s[uid/value=$system_uid] (CONTAINS EHR e CONTAINS COMPOSITION c [openEHR-EHR-COMPOSITION.encounter.v1] CONTAINS OBSERVATION obs [openEHR-EHR-OBSERVATION.blood_pressure.v1]) AND (CONTAINS PERSON p [openEHR-DEMOGRAPHIC-PERSON.person.v1] CONTAINS PARTY_IDENTITY pid [openEHR-DEMOGRAPHIC-PARTY_IDENTITY.person_name.v1]) WHERE e/ehr_status/subject/external_ref/id/value = encrypt(p/uid/value)