Generating Patient Summaries from Clinical Reports

Synopsis

This query searches for relevant medical concepts from medical reports for a patient. It returns entities coded to Snomed concepts and organizes them by the UMLS type associated with the Snomed concept. When multiple occurrences of the same concept is detected (e.g. in multiple reports), the query returns the most recent mention.

This example shows the value of populating the documentmetadata table after data processing. The Output Database Client supports merging of select metadata fields during the database insert step after structured data is returned by the NLP API. By using this data integration feature, your can use the Output Database to develop queries that return datasets which can be immediately used to generate insights for clinical or research questions where specific patients or cohorts need to be identified.

Processing Requirements

Because we need to uniquely identify the patient for this query, the patient identifier (MRN or other proxy for patient id), must be stored in the Output Database documentmetadata table after processing. Depending on your existing data infrastructure, there are several ways to populate the Output Database with patient identifiers so that they can be correlated with the extracted data. This information should be stored in the documentmetadata subject_id field in addition to other report specific information such as chart date. For more information about populating the documentmetadata table with patient identifiers and other report metadata see Storing Extended Report Metadata and Ingesting Input Documents from JSON Files in the Output Database Client documentation.

This query assumes that at least the following emtellipro-db-client processing options were enabled:

  • --feature experiencer-relation, snomed-ontology
  • --store-sections-and-sentences

For this query, Clinical notes were processed with the following document type:

  • --category Clinical
  • --subcategory generic

Clinical Context

The Unified Medical Language System (UMLS) from the National Library of Medicine (NLM) is a metathesaurus - it takes multiple medical ontologies, and combines and cross-references them. Another feature of the UMLS is that it uses its own semantic type labeling for its many medical ontologies, labeling concepts with semantic types such as Disease or Syndrome or Acquired Abnormality. The NLP API provides these UMLS semantic types for entities in the ‘entity_type’ field of the NLP API output and they can be used to identify groups of clinically-relevant concepts.

This query uses a combination of the experiencer CTE seen earlier in this cookbook with SQL CASE functionality to further combine multiple UMLS semantic types into broad groupings of patient history items. By combining multiple UMLS semantic types, it broadly groups patient history medical concepts into 6 categories of useful clinical history items:

  • Abnormalities / Disorders
  • Neoplasia / Cancer
  • Injuries / Trauma
  • Findings / Symptoms
  • Mental / Behavioral Disorders
  • Procedures / Care Activities

This kind of query could then be used to build a clinical helper applications that would show a snapshot of a patient’s medical history, highlighting and organizing information to help clinicians quickly read up on a patient’s history.

SQL query

WITH explicitpatients_ers AS (SELECT er.id AS expid
FROM experiencerrelation er
JOIN entity e
ON er.experiencer_id = e.id -- NOTE: find experience(r) entities
JOIN foundentity fe
ON fe.id = e.entity_id AND e.type_='found'-- IMPORTANT: e.entity_id not e.id
JOIN foundentityconcept fec
ON fe.id = fec.found_entity_id
JOIN concept c
ON c.concept_id = fec.concept_id AND c.ontology = fec.concept_ontology
WHERE c.ontology = 'snomed' -- alternative ontology 'umls_nci' (UMLS metathesaurus)
AND e.type_ = 'found' -- IMPORTANT: this condition is required.
AND c.concept_id = '116154003'), -- SNOMED CT concept id for patient
implicitpatients_ers AS (SELECT er.id AS expid
FROM entity e
JOIN experiencerrelation er
ON er.experiencer_id = e.id -- NOTE: experience(r) entities
JOIN assumedentity ae
ON ae.id = e.entity_id
WHERE e.type_ = 'assumed'
AND ae.value = 'patient'),
patient_ers AS ( -- experiencer relations where subject is patient
SELECT expid
FROM implicitpatients_ers
UNION
SELECT expid
FROM explicitpatients_ers
),
summary AS (
SELECT row_number() OVER ( PARTITION BY c.description ORDER BY DATE(dm.chartdate) DESC ) AS rank,
DATE(dm.chartdate) AS chartdate,
CASE fet.type_name
WHEN 'Disease or Syndrome' THEN 'Abnormalities / Disorders'
WHEN 'Acquired Abnormality' THEN 'Abnormalities / Disorders'
WHEN 'Anatomical Abnormality' THEN 'Abnormalities / Disorders'
WHEN 'Congenital Abnormality' THEN 'Abnormalities / Disorders' --? Add
WHEN 'Pathologic Function' THEN 'Abnormalities / Disorders'
WHEN 'Cell or Molecular Dysfunction' THEN 'Abnormalities / Disorders'
WHEN 'Neoplastic Process' THEN 'Neoplasia / Cancer'
WHEN 'Injury or Poisoning' THEN 'Injuries / Trauma'
WHEN 'Sign or Symptom' THEN 'Findings / Symptoms'
WHEN 'Finding' THEN 'Findings / Symptoms'
WHEN 'Mental or Behavioral Dysfunction' THEN 'Mental / Behavioral Disorders'
WHEN 'Diagnostic Procedure' THEN 'Procedures / Care Activities'
WHEN 'Laboratory Procedure' THEN 'Procedures / Care Activities'
WHEN 'Laboratory or Test Result' THEN 'Procedures / Care Activities'
WHEN 'Therapeutic or Preventive Procedure' THEN 'Procedures / Care Activities'
WHEN 'Health Care Activity' THEN 'Procedures / Care Activities'
ELSE 'Unknown'
END AS heading,
c.description AS concept,
fe.text AS term
-- sl.text AS sentence
FROM patient_ers
JOIN experiencerrelation er
ON patient_ers.expid = er.id
JOIN entity e
ON er.experienced_id = e.id -- NOTE: experience(d) entities
JOIN foundentity fe
ON fe.id = e.entity_id AND e.type_ = 'found'
JOIN foundentityconcept fec ON fe.id = fec.found_entity_id
JOIN concept c ON c.concept_id = fec.concept_id AND c.ontology = fec.concept_ontology
JOIN foundentitytype fet ON fet.found_entity_id = fe.id
-- Uncomment to access patient/chart data if available in documentmetadata:
JOIN document d ON d.id = e.document_id
JOIN documentmetadata dm ON d.id = dm.document_id
JOIN foundentitylocation fel ON fe.id = fel.found_entity_id
JOIN location l ON fel.location_id = l.id AND (l.type_ = 'sentence')
JOIN sentencelocation sl ON sl.id = l.location_id
WHERE c.ontology = 'snomed'
AND fet.ontology = 'umls'
AND dm.subject_id = '11110003'
AND fe.polarity = 'asserted'
AND fe.uncertainty = 'certain'
AND fet.type_name IN ('Disease or Syndrome', 'Acquired Abnormality', 'Cell or Molecular Dysfunction',
'Anatomical Abnormality', 'Pathologic Function', 'Neoplastic Process',
'Injury or Poisoning',
'Sign or Symptom', 'Finding', 'Mental or Behavioral Dysfunction', 'Diagnostic Procedure',
'Laboratory Procedure', 'Therapeutic or Preventive Procedure', 'Laboratory or Test Result',
'Congenital Abnormality', 'Health Care Activity')
)
SELECT * FROM summary WHERE rank = 1 -- get latest mention of any concept
ORDER BY summary.heading, summary.chartdate DESC;
rankchartdateheadingconceptterm
12022-09-30Abnormalities / DisordersSubscapularis tendinitis (disorder)subscapularis tendinosis
12022-09-30Abnormalities / DisordersHypertrophic osteoarthropathy (disorder)hypertrophic osteoarthropathy
12022-09-30Abnormalities / DisordersTendinosis (disorder)tendinosis
12022-09-30Abnormalities / DisordersSupraspinatus tendinitis (disorder)supraspinatus tendinosis
12022-09-30Abnormalities / DisordersNarrowing (morphologic abnormality)narrowing
12022-09-30Abnormalities / DisordersDegenerative abnormality (morphologic abnormality)degenerative
12022-08-08Abnormalities / DisordersHypertensive disorder, systemic arterial (disorder)Hypertension
12022-08-08Abnormalities / DisordersOsteoporosis (disorder)Osteoporosis
12022-08-08Abnormalities / DisordersUlcer of mouth (disorder)sores in his mouth
12022-08-08Abnormalities / DisordersOsteoarthritis (disorder)Osteoarthritis
12022-08-08Abnormalities / DisordersLabile hypertension due to being in a clinical environment (disorder)office hypertension
12022-03-29Abnormalities / DisordersSynovial cyst of knee (disorder)Baker’s cyst
12022-03-29Abnormalities / DisordersEdema (finding)edema
12022-03-29Abnormalities / DisordersSoft tissue swelling (finding)subcutaneous edema
12022-03-29Abnormalities / DisordersEdema of bilateral lower limbs (finding)Lower extremity edema bilaterally
12022-03-13Abnormalities / DisordersHypercholesterolemia (disorder)Hypercholesterolemia
12022-03-13Abnormalities / DisordersAlzheimer’s disease (disorder)Alzheimer’s disease
12022-03-13Abnormalities / DisordersAortoiliac atherosclerosis (disorder)atherosclerotic disease of the aortoiliac vessels
12022-03-13Abnormalities / DisordersGastrointestinal hemorrhage (disorder)gastrointestinal bleed
12022-03-13Abnormalities / DisordersInfectious disease (disorder)INFECTIOUS DISEASE
12022-03-13Abnormalities / DisordersHypervolemia (finding)volume overloaded
12022-03-13Abnormalities / DisordersCalcification of coronary artery (disorder)coronary artery calcification
12022-03-13Abnormalities / DisordersSurgical incision wound (morphologic abnormality)operative incisions
12022-03-13Abnormalities / DisordersCardiac arrest (disorder)arrest
12022-03-13Abnormalities / DisordersUlcer of foot (disorder)foot ulcers
12022-03-13Abnormalities / DisordersCardiorespiratory arrest (disorder)cardiorespiratory arrest
12022-03-13Abnormalities / DisordersCellulitis of right foot (disorder)Right pedal cellulitis
12022-03-13Abnormalities / DisordersCellulitis of right lower limb (disorder)right lower extremity cellulitis
12022-03-13Abnormalities / DisordersAcute kidney injury (disorder)acute renal failure
12022-03-13Abnormalities / DisordersCongestive heart failure (disorder)Congestive heart failure
12022-03-13Abnormalities / DisordersSepsis caused by Gram negative bacteria (disorder)gram-negative urosepsis
12022-03-13Abnormalities / DisordersCyst of pancreas (disorder)pancreatic cyst
12022-03-13Abnormalities / DisordersTriple vessel disease of the heart (disorder)Coronary artery disease with diffuse 3-vessel disease
12022-03-13Abnormalities / DisordersRight ventricular failure (disorder)right-sided failure
12022-03-13Abnormalities / DisordersDiabetes mellitus type 2 (disorder)Type 2 diabetes mellitus
12022-03-13Abnormalities / DisordersRight dominant coronary system (disorder)right-dominant system
12022-03-13Abnormalities / DisordersPeripheral vascular disease (disorder)peripheral vascular disease;
12022-03-13Abnormalities / DisordersEssential hypertension (disorder)Essential hypertension
12022-03-13Abnormalities / DisordersDiverticulitis (disorder)diverticulitis
12022-03-13Abnormalities / DisordersDiverticulosis of colon (finding)colonic diverticulosis
12022-03-13Abnormalities / DisordersMultiple diverticula of intestine (finding)Diverticulosis
12022-03-13Abnormalities / DisordersOcclusion of distal portion of anterior descending branch of left coronary artery (disorder)occlusion of the distal LAD
12022-03-13Abnormalities / DisordersMyocardial infarction (disorder)Myocardial infarction
12022-03-03Abnormalities / DisordersGanglion cyst (morphologic abnormality)ganglion
12022-03-03Abnormalities / DisordersMorphologically abnormal structure (morphologic abnormality)defect
12022-03-03Abnormalities / DisordersGanglion of wrist (disorder)Wrist ganglion
12022-02-22Abnormalities / DisordersGastroesophageal reflux disease (disorder)gastroesophageal reflux disease
12022-02-22Abnormalities / DisordersSinus bradycardia (disorder)Sinus bradycardia
12022-02-22Abnormalities / DisordersRectal hemorrhage (disorder)rectal bleeding
12022-02-16Abnormalities / DisordersNodule (morphologic abnormality)nodules