SQL on FHIR
2.1.0-pre - release
SQL on FHIR, published by SQL on FHIR Working Group. This guide is not an authorized publication; it is the continuous build for version 2.1.0-pre built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/FHIR/sql-on-fhir-v2/ and changes regularly. See the Directory of published versions
| Active as of 2026-02-24 |
<Library xmlns="http://hl7.org/fhir">
<id value="OmopFhirPatientJoin"/>
<meta>
<profile value="https://sql-on-fhir.org/ig/StructureDefinition/SQLQuery"/>
</meta>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: Library OmopFhirPatientJoin</b></p><a name="OmopFhirPatientJoin"> </a><a name="hcOmopFhirPatientJoin"> </a><div style="display: inline-block; background-color: #d9e0e7; padding: 6px; margin: 4px; border: 1px solid #8da1b4; border-radius: 5px; line-height: 60%"><p style="margin-bottom: 0px"/><p style="margin-bottom: 0px">Profile: <a href="StructureDefinition-SQLQuery.html">SQL Query Library</a></p></div><h2>Related Artifacts</h2><table class="grid"><tr><td>Depends On</td><td>omop_person</td><td>OMOP Person view</td><td><code>https://example.org/omop/ViewDefinition/Patient</code></td></tr><tr><td>Depends On</td><td>fhir_patient</td><td>FHIR Patient view</td><td><code>https://example.org/fhir/ViewDefinition/Patient</code></td></tr><tr><td>Depends On</td><td>diagnoses_view</td><td>Diagnosis facts view</td><td><code>https://example.org/ViewDefinition/diagnoses_view</code></td></tr></table><h2>Parameters</h2><table class="grid"><tr><td>source_system</td><td>in</td><td/><td/><td>string</td><td>Source system identifier for OMOP records</td></tr></table><h2>Contents</h2><p><code>application/sql</code></p><pre><code>SELECT
omop_person.person_id AS omop_person_id,
fhir_patient.id AS fhir_patient_id,
fhir_patient.name,
diagnoses_view.code AS diagnosis_code,
diagnoses_view.display AS diagnosis_display
FROM omop_person
JOIN fhir_patient
ON omop_person.person_id = fhir_patient.mrn
JOIN diagnoses_view
ON diagnoses_view.patient_id = fhir_patient.id
WHERE omop_person.source_system = :source_system</code></pre></div>
</text>
<url value="https://sql-on-fhir.org/ig/Library/OmopFhirPatientJoin"/>
<version value="2.1.0-pre"/>
<name value="OmopFhirPatientJoin"/>
<title value="OMOP/FHIR Patient Match with Diagnoses"/>
<status value="active"/>
<type>
<coding>
<system
value="https://sql-on-fhir.org/ig/CodeSystem/LibraryTypesCodes"/>
<code value="sql-query"/>
</coding>
</type>
<date value="2026-02-24T21:00:17+00:00"/>
<publisher value="SQL on FHIR Working Group"/>
<contact>
<name value="SQL on FHIR Working Group"/>
<telecom>
<system value="url"/>
<value value="https://sql-on-fhir.org"/>
</telecom>
</contact>
<description
value="Uses labels to disambiguate patient views from different sources and joins
patient diagnoses for downstream analytics.
```sql
SELECT
omop_person.person_id AS omop_person_id,
fhir_patient.id AS fhir_patient_id,
fhir_patient.name,
diagnoses_view.code AS diagnosis_code,
diagnoses_view.display AS diagnosis_display
FROM omop_person
JOIN fhir_patient
ON omop_person.person_id = fhir_patient.mrn
JOIN diagnoses_view
ON diagnoses_view.patient_id = fhir_patient.id
WHERE omop_person.source_system = :source_system
```"/>
<jurisdiction>
<coding>
<system value="http://unstats.un.org/unsd/methods/m49/m49.htm"/>
<code value="001"/>
<display value="World"/>
</coding>
</jurisdiction>
<relatedArtifact>
<type value="depends-on"/>
<label value="omop_person"/>
<display value="OMOP Person view"/>
<resource value="https://example.org/omop/ViewDefinition/Patient"/>
</relatedArtifact>
<relatedArtifact>
<type value="depends-on"/>
<label value="fhir_patient"/>
<display value="FHIR Patient view"/>
<resource value="https://example.org/fhir/ViewDefinition/Patient"/>
</relatedArtifact>
<relatedArtifact>
<type value="depends-on"/>
<label value="diagnoses_view"/>
<display value="Diagnosis facts view"/>
<resource value="https://example.org/ViewDefinition/diagnoses_view"/>
</relatedArtifact>
<parameter>
<name value="source_system"/>
<use value="in"/>
<documentation value="Source system identifier for OMOP records"/>
<type value="string"/>
</parameter>
<content>
<extension url="https://sql-on-fhir.org/ig/StructureDefinition/sql-text">
<valueString
value="SELECT
omop_person.person_id AS omop_person_id,
fhir_patient.id AS fhir_patient_id,
fhir_patient.name,
diagnoses_view.code AS diagnosis_code,
diagnoses_view.display AS diagnosis_display
FROM omop_person
JOIN fhir_patient
ON omop_person.person_id = fhir_patient.mrn
JOIN diagnoses_view
ON diagnoses_view.patient_id = fhir_patient.id
WHERE omop_person.source_system = :source_system"/>
</extension>
<contentType value="application/sql"/>
<data
value="U0VMRUNUCiAgb21vcF9wZXJzb24ucGVyc29uX2lkIEFTIG9tb3BfcGVyc29uX2lkLAogIGZoaXJfcGF0aWVudC5pZCBBUyBmaGlyX3BhdGllbnRfaWQsCiAgZmhpcl9wYXRpZW50Lm5hbWUsCiAgZGlhZ25vc2VzX3ZpZXcuY29kZSBBUyBkaWFnbm9zaXNfY29kZSwKICBkaWFnbm9zZXNfdmlldy5kaXNwbGF5IEFTIGRpYWdub3Npc19kaXNwbGF5CkZST00gb21vcF9wZXJzb24KSk9JTiBmaGlyX3BhdGllbnQKICBPTiBvbW9wX3BlcnNvbi5wZXJzb25faWQgPSBmaGlyX3BhdGllbnQubXJuCkpPSU4gZGlhZ25vc2VzX3ZpZXcKICBPTiBkaWFnbm9zZXNfdmlldy5wYXRpZW50X2lkID0gZmhpcl9wYXRpZW50LmlkCldIRVJFIG9tb3BfcGVyc29uLnNvdXJjZV9zeXN0ZW0gPSA6c291cmNlX3N5c3RlbQ=="/>
</content>
</Library>