SPARQL Queries Against CDA Patient Documents

From W3C Wiki
Jump to: navigation, search

SPARQL Queries and Results

Calculate the count of female patients

  • SPARQL query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX hl7: <urn:hl7-org:v3#>

SELECT DISTINCT (COUNT(?patient) AS ?genderCount) WHERE {

 ?patient hl7:recordTarget ?recordTarget .
 ?recordTarget hl7:patientRole ?patientRole .
 ?patientRole hl7:patient ?patientInst .
 ?patientInst hl7:administrativeGenderCode ?administrativeGenderCode .
 ?administrativeGenderCode hl7:code ?genderCode .
 FILTER (?genderCode="F")
}

  • Results
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
    <variable name="genderCount"/>
  </head>
  <results>
    <result>
      <binding name="genderCount"><literal datatype="http://www.w3.org/2001/XMLSchema#integer">110</literal></binding>
    </result>
  </results>
</sparql>

Calculate the count of male patient

  • SPARQL query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX hl7: <urn:hl7-org:v3#>

SELECT DISTINCT (COUNT(?patient) AS ?genderCount) WHERE {

 ?patient hl7:recordTarget ?recordTarget .
 ?recordTarget hl7:patientRole ?patientRole .
 ?patientRole hl7:patient ?patientInst .
 ?patientInst hl7:administrativeGenderCode ?administrativeGenderCode .
 ?administrativeGenderCode hl7:code ?genderCode .
 FILTER (?genderCode="M")
}


  • Results
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
    <variable name="genderCount"/>
  </head>
  <results>
    <result>
      <binding name="genderCount"><literal datatype="http://www.w3.org/2001/XMLSchema#integer">105</literal></binding>
    </result>
  </results>
</sparql>

Extract all SNOMED CT Codes from CDA documents

  • SPARQL Query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX hl7: <urn:hl7-org:v3#>

SELECT DISTINCE ?displayName ?sctCode WHERE {

 ?section hl7:code ?code .
 ?code hl7:displayName ?displayName .
 ?code hl7:codeSystemName ?codeSystemName .
 FILTER (?codeSystemName="SNOMED CT")
 ?code hl7:codeSystem ?codeSystem .
 ?code hl7:code ?sctCode .
}

  • Results
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
    <variable name="displayName"/>
    <variable name="sctCode"/>
  </head>
  <results>
    <result>
      <binding name="displayName"><literal>drug allergy</literal></binding>
      <binding name="sctCode"><literal>416098002</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>Vital signs</literal></binding>
      <binding name="sctCode"><literal>46680005</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>Propensity to adverse reactions (disorder)</literal></binding>
      <binding name="sctCode"><literal>420134006</literal></binding>
    </result>
  </results>
</sparql>


Extract all LOINC Codes from CDA documents

  • SPARQL Query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX hl7: <urn:hl7-org:v3#>

SELECT DISTINCE ?displayName ?sctCode WHERE {

 ?section hl7:code ?code .
 ?code hl7:displayName ?displayName .
 ?code hl7:codeSystemName ?codeSystemName .
 FILTER (?codeSystemName="LOINC")
 ?code hl7:codeSystem ?codeSystem .
 ?code hl7:code ?sctCode .
}

  • Results
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
    <variable name="displayName"/>
    <variable name="codeSystemName"/>
    <variable name="sctCode"/>
  </head>
  <results>
    <result>
      <binding name="displayName"><literal>Vital signs</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>8716-3</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>Allergies</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>48765-2</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>Summarization of episode note</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>34133-9</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>History of encounters</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>46240-8</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>Problem List</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>11450-4</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>Results</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>30954-2</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>Problem list</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>11450-4</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>History of immunizations</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>11369-6</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>Treatment plan</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>18776-5</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>List of surgeries</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>47519-4</literal></binding>
    </result>
    <result>
      <binding name="displayName"><literal>History of medication use</literal></binding>
      <binding name="codeSystemName"><literal>LOINC</literal></binding>
      <binding name="sctCode"><literal>10160-0</literal></binding>
    </result>
  </results>
</sparql>