library "mrna_myo_enhanced" version '1.0.0' using FHIR version '4.0.0' include "FHIRHelpers" version '4.0.0' called FHIRHelpers include "mrna_myo_value_sets" version '1.0.0' called value_sets codesystem "SNOMEDCT": 'http://snomed.info/sct' // parameter to inject an index date found via the spreadsheets from health systems. parameter "hs_index_date" Date // Functions for filtering a set of clinical resources define fluent function during( Observations List, Period Interval): Observations O where O.effective.value during Period define fluent function during( Conditions List,Period Interval): Conditions C where (C.onset as FHIR.dateTime).value during Period define fluent function during( Procedures List, Period Interval): Procedures P where P.performed during Period define fluent function during(Immunizations List, Period Interval): Immunizations I where I.occurrence during Period define fluent function during(DiagnosticReports List, Period Interval): DiagnosticReports D where D.effective.value during Period // Define value sets define vaccine_mrna: value_sets.vaccine_mrna define myocarditis_dxnonspecific: Concept {codes: (value_sets.myocarditis_dxnonspecific.codes union value_sets.myopericarditis_dxnonspecific.codes)} define myocarditis_dxspecific: Concept {codes: (value_sets.myocarditis_dxspecific.codes union value_sets.myopericarditis_dxspecific.codes)} define myocarditis_dxchronic: Concept {codes: (value_sets.myocarditis_dxchronic.codes union value_sets.myopericarditis_dxchronic.codes)} define myocarditis_all: Concept {codes: ((myocarditis_dxnonspecific.codes union myocarditis_dxspecific.codes) union myocarditis_dxchronic.codes)} define myocarditis_dxspecific_dxchronic: Concept {codes: (myocarditis_dxchronic.codes union myocarditis_dxspecific.codes)} define lab_troponinI: value_sets.lab_troponinI define lab_troponinT: value_sets.lab_troponinT define lab_CKMB: value_sets.lab_CKMB define present_value: Concept { Code '52101004' from "SNOMEDCT" display 'Present (qualifier value)' } // symptom codes define chest_pain: Concept { Code '102587001' from "SNOMEDCT" display 'Acute chest pain (finding)' } define palpitations: Concept { Code '80313002' from "SNOMEDCT" display 'Palpitations (finding)' } define dyspnea: Concept { Code '267036007' from "SNOMEDCT" display 'Dyspnea (finding)' } define diaphoresis: Concept { Code '52613005' from "SNOMEDCT" display 'Excessive sweating (finding)' } define sudden_death: Concept { Code '418362005' from "SNOMEDCT" display 'Dead - sudden death (finding)' } define fatigue: Concept { Code '84229001' from "SNOMEDCT" display 'Fatigue (finding)' } define abdominal_pain: Concept { Code '21522001' from "SNOMEDCT" display 'Abdominal pain (finding)' } define dizziness: Concept { Code '271594007' from "SNOMEDCT" display 'Syncope (finding)', Code '404640003' from "SNOMEDCT" display 'Dizziness (finding)' } define edema: Concept { Code '267038008' from "SNOMEDCT" display 'Edema (finding)' } define cough: Concept { Code '49727002' from "SNOMEDCT" display 'Cough (finding)' } // ecg abnormality codes define arrhythmias: Concept { Code '698247007:246456000={26593000,62459000},246090004={17366009,44103008}' from "SNOMEDCT" display 'Cardiac arrhythmia with Episodicity = Paroxysmal or Chronic persistent, Associated finding = Atrial arrhythmia or Ventricular arrhythmia' } define conduction_defects: Concept { Code '44808001:116676008={270492004,195042002,27885002,6374002}' from "SNOMEDCT" display 'Conduction disorder of heart with Associated morphology = First-degree atrioventricular block, Second-degree atrioventricular block, Complete atrioventricular block, Bundle branch block' } define ectopy: Concept { Code '164881000:260864003=70232002,418775008=266706003' from "SNOMEDCT" display 'Electrocardiogram : ectopic beats (finding) with Frequency = Frequent, Finding method = Continuous electrocardiogram monitoring' } // echo abnormality codes define ventricular_abnormalities: Concept { Code '404684003:246090004={248553006,248566001},116676008={41511000119106,416181002}' from "SNOMEDCT" display 'Clinical finding with Associated finding = Abnormal left ventricular function or Abnormal right ventricular function, Associated morphology = Focal or Diffuse' } define motion_abnormalities: Concept { Code '429058004:363698007=74281007,116676008=41511000119106' from "SNOMEDCT" display 'New wall motion abnormality with Finding site = Myocardium structure, Associated morphology = Focal' } define systolic_diastolic_abnormality: Concept { Code '404684003:246090004={371037005,3545003}' from "SNOMEDCT" display 'Clinical finding with Associated finding = Systolic dysfunction or Diastolic dysfunction' } define ventricular_dilation: Concept { Code '404684003:363698007=21814001,116676008=107658001' from "SNOMEDCT" display 'Clinical finding with Finding site = Cardiac ventricular structure, Associated morphology = Dilatation' } define wall_thickness_change: Concept { Code '404684003:363698007=74281007,116676008=14028006 ' from "SNOMEDCT" display 'Clinical finding with Finding site = Myocardium structure, Associated morphology = Abnormal thickness' } // cmr abnormality codes define edema_patchy: Concept { Code '267038008:418775008=113091000,116676008=255609007' from "SNOMEDCT" display 'Edema with Finding method = Magnetic resonance imaging (T2-weighted), Associated morphology = Partial (patchy)' } define gadolinium_enhancement: Concept { Code '365853002:408731000124104=38542003,418775008=113091000,363589002=14529005,246090004=74281007,263927000=385658008' from "SNOMEDCT" display 'Imaging finding with Temporal context = Late, Finding method = Magnetic resonance imaging, Using substance = Gadolinium, Associated finding = Myocardium structure, Clinical course = Recovery' } // biopsy inflammation code define inflammatory_myocardium_biopsy: Concept { Code '409774005:363698007=74281007,703065002=119377007' from "SNOMEDCT" display 'Inflammatory morphology:Finding site=Myocardium structure,Specimen source=Myocardial specimen' } // Start AE Logic context Patient // Use health system determined index date. define index_date: date from hs_index_date // Get mRNA immunization and procedure resources define mrna_imm_list: [Immunization: vaccine_mrna] I where I.status = 'completed' define mrna_proc_list: [Procedure: vaccine_mrna] P where P.status = 'completed' // Get list of dates define mrna_imm_dt_list: mrna_imm_list I return date from Coalesce((I.occurrence as FHIR.dateTime).value, ToDateTime((I.occurrence as FHIR.string).value)) sort asc define mrna_proc_dt_list: mrna_proc_list P return date from Coalesce((P.performed as FHIR.dateTime).value, (P.performed as FHIR.Period)."start".value, ToDateTime((P.performed as FHIR.string).value)) //By default a query returns a list of distinct results define mrna_dt_list: mrna_imm_dt_list union mrna_proc_dt_list // Query for immunizations that occurred on the index date or the day after define mrna_imm_on_index_date: mrna_imm_list I where (date from Coalesce((I.occurrence as FHIR.dateTime).value, ToDateTime((I.occurrence as FHIR.string).value)) in Interval[index_date, index_date + 1 day]) // Query for procedures that occurred on the index date or the day after define mrna_proc_on_index_date: mrna_proc_list P where (date from Coalesce((P.performed as FHIR.dateTime).value, (P.performed as FHIR.Period)."start".value, ToDateTime((P.performed as FHIR.string).value)) in Interval[index_date, index_date + 1 day]) define exposure: mrna_imm_on_index_date.vaccineCode.coding.code union mrna_proc_on_index_date.code.coding.code define mRNAImmunization_Evidence: Tuple { definition: 'Patient\'s mRNA immunization exposures', featureType: 'biologic_exposure', evidence: mrna_imm_on_index_date union mrna_proc_on_index_date } // Clean window for observability define clean_window_start: index_date - 365 days // diagnosis window for evidence define diagnosis_window_end: index_date + 42 days define outcome_evidence_interval: Interval[index_date, diagnosis_window_end] define function HasDataObservability(Conditions List, StartDate DateTime, EndDate DateTime): exists (Conditions C1 where C1.recordedDate < StartDate) and exists (Conditions C2 where C2.recordedDate > EndDate) define data_observability: HasDataObservability([Condition], clean_window_start, diagnosis_window_end) define test: [Condition: myocarditis_all] C // Check for excluded diagnoses define no_prior_myocarditis: not exists([Condition: myocarditis_all] C where C.recordedDate is not null and (C.recordedDate as FHIR.dateTime) during Interval[clean_window_start, index_date] ) define no_excluded_myocarditis_in_evidence_window: not exists([Condition: myocarditis_dxspecific_dxchronic] C where C.recordedDate is not null and (C.recordedDate as FHIR.dateTime) during outcome_evidence_interval ) // generic list of confirmatory statuses define positive_status: {'final', 'amended', 'corrected', 'registered', 'preliminary', 'completed'} // Check for lab evidence define elevated_troponinI_threshold: 0.015 define elevated_troponinT_threshold: 0.01 define elevated_CKMB_threshold: 5 // >3.8 ng/mL for men, >2.5 ng/mL for women, >6.3 suggestive for MI define troponinI_observation: [Observation: lab_troponinI] define biomarker_troponin_i: exists (troponinI_observation TropI where TropI.effective.value during outcome_evidence_interval and (TropI.value as FHIR.Quantity).value > elevated_troponinI_threshold and TropI.value.unit = 'ng/mL' and TropI.status in positive_status ) define troponinT_observation: [Observation: lab_troponinT] define biomarker_troponin_t: exists (troponinT_observation TropT where TropT.effective.value during outcome_evidence_interval and (TropT.value as FHIR.Quantity).value > elevated_troponinT_threshold and TropT.value.unit = 'ng/mL' and TropT.status in positive_status ) define CKMB_observation: [Observation: lab_CKMB] define biomarker_ckmb: exists (CKMB_observation CKMB where CKMB.effective.value during outcome_evidence_interval and (CKMB.value as FHIR.Quantity).value > elevated_CKMB_threshold and CKMB.value.unit = 'ng/mL' and CKMB.status in positive_status ) // Find valid observations in evidence window. define valid_observations: [Observation] O where exists (O.value.coding Co where Co.code in present_value.codes.code) and (O.effective.value during outcome_evidence_interval or O.effective.start.value during outcome_evidence_interval) and O.status in positive_status // Biopsy evidence define biopsy_inflammation: exists (valid_observations O where exists (O.code.coding C where C.code in inflammatory_myocardium_biopsy.codes.code) ) // ECHO evidence define echo_ventricular_abnormalities: exists (valid_observations O where exists (O.code.coding C where C.code in ventricular_abnormalities.codes.code) ) define echo_motion_abnormalities: exists (valid_observations O where exists (O.code.coding C where C.code in motion_abnormalities.codes.code) ) define echo_systolic_diastolic_abnormality: exists (valid_observations O where exists (O.code.coding C where C.code in systolic_diastolic_abnormality.codes.code) ) define echo_ventricular_dilation: exists (valid_observations O where exists (O.code.coding C where C.code in ventricular_dilation.codes.code) ) define echo_wall_thickness_change: exists (valid_observations O where exists (O.code.coding C where C.code in wall_thickness_change.codes.code) ) define abnormal_ECHO: echo_ventricular_abnormalities or echo_motion_abnormalities or echo_systolic_diastolic_abnormality or echo_ventricular_dilation or echo_wall_thickness_change // cMRI evidence define cmr_edema: exists (valid_observations O where exists (O.code.coding C where C.code in edema_patchy.codes.code) ) define cmr_gadolinium_enhancement: exists (valid_observations O where exists (O.code.coding C where C.code in gadolinium_enhancement.codes.code) ) define abnormal_cMRI: cmr_edema or cmr_gadolinium_enhancement // ECG evidence define ecg_arrhythmias: exists (valid_observations O where exists (O.code.coding C where C.code in arrhythmias.codes.code) ) define ecg_conduction_defects: exists (valid_observations O where exists (O.code.coding C where C.code in conduction_defects.codes.code) ) define ecg_ectopy: exists (valid_observations O where exists (O.code.coding C where C.code in ectopy.codes.code) ) define abnormal_EKG: ecg_arrhythmias or ecg_conduction_defects or ecg_ectopy // Cardiac symptoms define symptom_chest_pain: exists (valid_observations O where exists (O.code.coding C where C.code in chest_pain.codes.code) ) define symptom_palpitations: exists (valid_observations O where exists (O.code.coding C where C.code in palpitations.codes.code) ) define symptom_dyspnea: exists (valid_observations O where exists (O.code.coding C where C.code in dyspnea.codes.code) ) define symptom_diaphoresis: exists (valid_observations O where exists (O.code.coding C where C.code in diaphoresis.codes.code) ) define symptom_sudden_death: exists (valid_observations O where exists (O.code.coding C where C.code in sudden_death.codes.code) ) define cardiac_symptom_count: (if symptom_chest_pain then 1 else 0) + (if symptom_palpitations then 1 else 0) + (if symptom_dyspnea then 1 else 0) + (if symptom_diaphoresis then 1 else 0) + (if symptom_sudden_death then 1 else 0) // nonspecific symptoms define symptom_fatigue: exists (valid_observations O where exists (O.code.coding C where C.code in fatigue.codes.code) ) define symptom_abdominal_pain: exists (valid_observations O where exists (O.code.coding C where C.code in abdominal_pain.codes.code) ) define symptom_dizziness: exists (valid_observations O where exists (O.code.coding C where C.code in dizziness.codes.code) ) define symptom_edema: exists (valid_observations O where exists (O.code.coding C where C.code in edema.codes.code) ) define symptom_cough: exists (valid_observations O where exists (O.code.coding C where C.code in cough.codes.code) ) define non_cardiac_symptom_count: (if symptom_fatigue then 1 else 0) + (if symptom_abdominal_pain then 1 else 0) + (if symptom_dizziness then 1 else 0) + (if symptom_edema then 1 else 0) + (if symptom_cough then 1 else 0) // Make final determinations define exposure_determination: Length(exposure) > 0 define outcome_level1_determination: if ( (biopsy_inflammation) or ( (biomarker_troponin_i or biomarker_troponin_t) and (abnormal_cMRI or abnormal_ECHO) ) ) then true else false define outcome_level2_determination: if ( (cardiac_symptom_count >=1 or non_cardiac_symptom_count >= 2) and ( (biomarker_troponin_i or biomarker_troponin_t or biomarker_ckmb) or (abnormal_cMRI or abnormal_ECHO or abnormal_EKG) ) ) then true else false define "outcome_determination": if "outcome_level1_determination" then 'Definitive' else if "outcome_level2_determination" then 'Probable' else 'Possible (Insuff.evidence)' // InPopulation is analogous to 'exposure associated with outcome' define InPopulation: if ( data_observability and exposure_determination and no_prior_myocarditis and no_excluded_myocarditis_in_evidence_window and (outcome_level1_determination or outcome_level2_determination) ) then true else false