Colorectal Cancer Screening and Management (CRCSM) Clinical Decision Support (CDS) Implementation Guide
0.1.0 - ci-build

Colorectal Cancer Screening and Management (CRCSM) Clinical Decision Support (CDS) Implementation Guide - Local Development build (v0.1.0) built by the FHIR (HL7® FHIR® Standard) Build Tools. See the Directory of published versions

Library: PertinentHistory

Official URL: http://cancerscreeningcds.github.io/crcsm-cds/Library/PertinentHistory Version: 0.1.0
Draft as of 2025-02-28 Computable Name: PertinentHistory
Id: PertinentHistory
Version: 0.1.0
Url: PertinentHistory
Status: draft
Type:

system: http://terminology.hl7.org/CodeSystem/library-type

code: logic-library

Date: 2025-02-28 21:24:30+0000
Publisher: MITRE
Related Artifacts:

Dependencies

  • http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1
  • http://cancerscreeningcds.github.io/crcsm-cds/Library/CDSConnectCommonsforFHIRv401|1.0.0
  • http://cancerscreeningcds.github.io/crcsm-cds/Library/CSMCommonFunctions|1.0.0
  • http://cancerscreeningcds.github.io/crcsm-cds/Library/CRCSMCommonFunctions|1.0.0
  • http://cancerscreeningcds.github.io/crcsm-cds/Library/FHIRHelpers|4.0.1
  • http://cancerscreeningcds.github.io/crcsm-cds/Library/DataElements|1.0.0
  • http://cancerscreeningcds.github.io/crcsm-cds/Library/ScreeningDue|1.0.0
  • http://cancerscreeningcds.github.io/crcsm-cds/Library/ScreeningIncomplete|1.0.0
  • http://cancerscreeningcds.github.io/crcsm-cds/Library/ScreeningDueEvents|1.0.0
  • http://cancerscreeningcds.github.io/crcsm-cds/Library/ScreeningIncompleteEvents|1.0.0
  • ConditionVerificationStatus
  • SNOMED CT (all versions)
  • International Classification of Diseases, 10th Revision, Clinical Modification (ICD-10-CM)
  • Screening Observation Code System
  • Logical Observation Identifiers, Names and Codes (LOINC)
  • Recommendation Flag Code System
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.108.12.1001
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1078.879
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1019
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.11.1020
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.108.11.1145
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.356
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.118.11.1097
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.359
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.336
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.330
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.361
Parameters:
NameTypeMinMaxIn/Out
ObservationLookbackPeriodQuantity01In
ScreeningHistoryLookbackQuantity01In
PatientPatient01Out
UsualPatientNameHumanName0*Out
OfficialPatientNameHumanName0*Out
PatientNamestring01Out
BirthSexTextstring01Out
GenderTextstring01Out
CommunicationLanguageCodestring01Out
CommunicationLanguageTextstring01Out
LanguageCodestring01Out
LanguageTextAbbreviatedstring01Out
LanguageTextstring01Out
RaceExtensionValuesResource0*Out
RaceTextstring01Out
EthnicityExtensionValuesResource0*Out
EthnicityTextstring01Out
PertinentConditionsCondition0*Out
PertinentConditionsSummaryResource0*Out
PertinentFamilyMemberHistoryResource0*Out
PertinentFamilyMemberHistorySummaryResource0*Out
PertinentObservationsObservation0*Out
PertinentObservationsSummaryResource0*Out
PertinentProceduresProcedure0*Out
PertinentProceduresSummaryResource0*Out
FOBTDiagnosticReportsSummaryResource0*Out
sDNAFITDiagnosticReportsSummaryResource0*Out
ColonoscopyDiagnosticReportsSummaryResource0*Out
CTColonographyDiagnosticReportsSummaryResource0*Out
FlexSigDiagnosticReportsSummaryResource0*Out
DiagnosticReportsSummaryResource0*Out
PertinentEncountersEncounter0*Out
PertinentEncountersSummaryResource0*Out
PertinentEpisodesOfCareEpisodeOfCare0*Out
PertinentEpisodesOfCareSummaryResource0*Out
DueOrOverdueScreeningSummaryResource0*Out
IncompleteScreeningOrdersSummaryResource0*Out
PertinentRequestsSummaryResource0*Out
PertinentHistoryResource01Out
Data Requirements:
TypeProfileMSCode Filter
Patient http://hl7.org/fhir/StructureDefinition/Patient ; code filter:
path: use

code: usual

Patient http://hl7.org/fhir/StructureDefinition/Patient ; code filter:
path: use

code: official

Patient http://hl7.org/fhir/StructureDefinition/Patient ;;;;;;;
Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.108.12.1001
Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code

system: http://snomed.info/sct

code: 716318002

display: Lynch syndrome (disorder)

Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code
Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code

system: http://snomed.info/sct

code: 423471004

display: MYH-associated polyposis (disorder)

Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code

system: http://snomed.info/sct

code: 763536006

display: Hyperplastic polyposis syndrome (disorder)

Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code

system: http://snomed.info/sct

code: 9273005

display: Juvenile polyposis syndrome (disorder)

Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code

system: http://snomed.info/sct

code: 54411001

display: Peutz-Jeghers syndrome (disorder)

Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code

system: http://snomed.info/sct

code: 58037000

display: Cowden syndrome (disorder)

Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1078.879
Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1078.879
Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code

system: http://snomed.info/sct

code: 68496003

display: Polyp of colon (disorder)

Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code

system: http://snomed.info/sct

code: 312824007

display: Family history of cancer of colon (situation)

Condition http://hl7.org/fhir/StructureDefinition/Condition ;;;;;;; code filter:
path: code

system: http://snomed.info/sct

code: 429969003

display: Family history of polyp of colon (situation)

FamilyMemberHistory http://hl7.org/fhir/StructureDefinition/FamilyMemberHistory ;
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;;;;;;;; code filter:
path: code

system: http://cancerscreeningcds.github.io/crcsm-cds/CodeSystem/screening-observation-code-system

code: ColorectalSymptoms

display: New or worsening colorectal symptoms

Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;;;;;;;; code filter:
path: code

system: http://cancerscreeningcds.github.io/crcsm-cds/CodeSystem/screening-observation-code-system

code: ReducedLifeExpectancyIndicator

display: Reduced life expectancy indicator

Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;;;;;;;; code filter:
path: code
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;;;;;;;;
Procedure http://hl7.org/fhir/StructureDefinition/Procedure ;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1019
DiagnosticReport http://hl7.org/fhir/StructureDefinition/DiagnosticReport ;;;;;;; code filter:
path: code
DiagnosticReport http://hl7.org/fhir/StructureDefinition/DiagnosticReport ;;;;;;;
Encounter http://hl7.org/fhir/StructureDefinition/Encounter ;;;;;;;
EpisodeOfCare http://hl7.org/fhir/StructureDefinition/EpisodeOfCare ;;;;;;;
CarePlan http://hl7.org/fhir/StructureDefinition/CarePlan ;;;;;;;;;;;;;; code filter:
path: status

code: active

ServiceRequest http://hl7.org/fhir/StructureDefinition/ServiceRequest ;;;; code filter:
path: intent

code: plan

ServiceRequest http://hl7.org/fhir/StructureDefinition/ServiceRequest ;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.361
ServiceRequest http://hl7.org/fhir/StructureDefinition/ServiceRequest ;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.361 code filter:
path: status

code: active

Content: text/cql
library PertinentHistory version '1.0.0'

using FHIR version '4.0.1'

include CDSConnectCommonsforFHIRv401 version '1.0.0' called C3F
include CSMCommonFunctions version '1.0.0' called Common
include CRCSMCommonFunctions version '1.0.0' called CRCSMCommon
include FHIRHelpers version '4.0.1' called FHIRHelpers
include DataElements version '1.0.0' called DataElements
include ScreeningDue version '1.0.0'
include ScreeningIncomplete version '1.0.0'

context Patient

define PertinentHistory:
{
  patientInfo: {
    name: PatientName,
    id: Patient.identifier,
    isPregnant: DataElements.Pregnant,
    dateOfBirth: Patient.birthDate,
    sexAtBirth: BirthSexText,
    age: AgeInYears(),
    gender: GenderText,
    primaryLanguage: LanguageText,
    race: RaceText + '; ' + EthnicityText
  },
  patientHistory: {
    conditions: PertinentConditionsSummary,
    familyMemberHistory: PertinentFamilyMemberHistorySummary,
    observations: PertinentObservationsSummary,
    procedures: PertinentProceduresSummary,
    diagnosticReports: DiagnosticReportsSummary,
    encounters: PertinentEncountersSummary,
    episodeOfCares: PertinentEpisodesOfCareSummary,
    requests: PertinentRequestsSummary
  }
}

//------------------------------------------------------------------------------
// PERTINENT DEMOGRAPHICS
//------------------------------------------------------------------------------

define PatientName:
  if Exists(UsualPatientName) then
    FormatPatientName(First(UsualPatientName))
  else if Exists(OfficialPatientName) then
    FormatPatientName(First(OfficialPatientName))
  else
    FormatPatientName(First(Patient.name))

define UsualPatientName:
  Patient.name N
    where N.use = 'usual'
    return N

define OfficialPatientName:
  Patient.name N
    where N.use = 'official'
    return N

define function FormatPatientName(name FHIR.HumanName):
  First(name.given) + ' ' + name.family

define BirthSexText:
  if DataElements.BirthSexCode = 'F' then 'Female'
  else if DataElements.BirthSexCode = 'M' then 'Male'
  else 'Unknown'  

define GenderText:
  if Exists(DataElements.GenderIdentityExtension) 
  then DataElements.GenderIdentityExtension[0].value.coding[0].code.value
  else Patient.gender.value  

define LanguageText:
  case
    when LanguageTextAbbreviated = 'en' then 'English'
    when LanguageTextAbbreviated = 'es' then 'Spanish'
    when LanguageTextAbbreviated = 'zh' then 'Chinese'
    when LanguageTextAbbreviated = 'fr' then 'French'
    when LanguageTextAbbreviated = 'tl' then 'Tagalog'
    when LanguageTextAbbreviated = 'vi' then 'Vietnamese'
    else 'Unknown'
  end  

define LanguageTextAbbreviated:
  Coalesce( {CommunicationLanguageCode, CommunicationLanguageText, LanguageCode} )

define CommunicationLanguageCode:
  Patient.communication.language.coding.code.value[0]

define CommunicationLanguageText:
  Patient.communication.language.text.value[0]

define LanguageCode:
  Patient.language.value

define RaceText:
  Coalesce(Coalesce(RaceExtensionValues))

define RaceExtensionValues:
  (Patient.extension) E 
    where E.url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-race'
    return (E.extension) X where X.url = 'text' return FHIRHelpers.ToString(X.value as FHIR.string)

define EthnicityText:
  Coalesce(Coalesce(EthnicityExtensionValues))

define EthnicityExtensionValues:
  (Patient.extension) E
    where E.url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity'
    return (E.extension) X where X.url = 'text' return FHIRHelpers.ToString(X.value as FHIR.string)  

//------------------------------------------------------------------------------
// PERTINENT CONDITIONS
//------------------------------------------------------------------------------

define PertinentConditions:
  DataElements.ColorectalCancerDiagnoses union
  DataElements.ColorectalCancerConditions union
  DataElements.LynchSyndromeConditions union
  DataElements.FamilialAdenomatousPolyposisConditions union
  DataElements.AttenuatedFamilialAdenomatousPolyposisConditions union
  DataElements.MUTYHAssociatedPolyposisConditions union
  DataElements.SerratedPolyposisConditions union
  DataElements.JuvenilePolyposisConditions union
  DataElements.PeutzJegherSyndromeConditions union
  DataElements.CowdenSyndromeConditions union
  DataElements.UlcerativeColitisConditions union
  DataElements.CrohnsDiseaseConditions union
  DataElements.PotentiallyPrecancerousPolypsConditions 

define PertinentConditionsSummary:
  (PertinentConditions) C
  return {
    name: Common.ConceptText(C.code),
    value: C.clinicalStatus.coding[0].code.value,
    date: Common.DateTimeText(
      Coalesce(
        C.onset as FHIR.dateTime,
        C.recordedDate
      )
    ),
    reference: 'Condition/' + C.id,
    edited: HasBeenLocallyEdited(C)
  }
  sort by (date as String) desc

//------------------------------------------------------------------------------
// PERTINENT FAMILY MEMBER HISTORY
//------------------------------------------------------------------------------  

define PertinentFamilyMemberHistory:
  DataElements.FamilyHxCRCConditions union
  DataElements.FamilyHxPrecancerousPolypConditions union 
  DataElements.FamilyHxDiagnosisOfCRC union
  DataElements.FamilyHxDiagnosisOfHistoryOfCRC union
  DataElements.FamilyHxDiagnosisOfPrecancerousPolyp

define PertinentFamilyMemberHistorySummary:
  (PertinentFamilyMemberHistory) FMH
    return
      FMH.conditions C return {
        name: Common.ConceptText(FMH.familyMemberHistory.relationship),
        value: Common.ConceptText(C.code),
        onset: Onset(C),
        reference: 'FamilyMemberHistory/' + FMH.familyMemberHistory.id,
        edited: HasBeenLocallyEdited(FMH.familyMemberHistory)
  }
  
//------------------------------------------------------------------------------
// PERTINENT OBSERVATIONS
//------------------------------------------------------------------------------

define PertinentObservations:
  (DataElements.NewOrWorseningColorectalSymptomsObservations union
  DataElements.ReducedLifeExpectancyObservations)
  except {null}

define PertinentObservationsSummary:
  (PertinentObservations) Obs
  return {
    name: Common.ConceptText(Obs.code),
    value: Common.ConceptText(Obs.value),
    date: Common.ObservationDateString(Obs),
    reference: 'Observation/' + Obs.id,
    edited: HasBeenLocallyEdited(Obs)
  }
  sort by (date as String) desc

//------------------------------------------------------------------------------
// PERTINENT PROCEDURES
//------------------------------------------------------------------------------

define PertinentProcedures:
  DataElements.TotalColectomyProcedures 

define PertinentProceduresSummary:
  (PertinentProcedures) P
  return {
    name: Common.ConceptText(P.code),
    value: P.status.value,
    date: Common.ProcedureDateString(P),
    reference: 'Procedure/' + P.id,
    edited: HasBeenLocallyEdited(P)
  } sort by date desc  

//------------------------------------------------------------------------------
// PERTINENT DIAGNOSTIC REPORTS
//------------------------------------------------------------------------------

define DiagnosticReportsSummary:
  (
    FOBTDiagnosticReportsSummary
    union sDNAFITDiagnosticReportsSummary
    union ColonoscopyDiagnosticReportsSummary
    union CTColonographyDiagnosticReportsSummary
    union FlexSigDiagnosticReportsSummary
  ) D
  sort by date desc

define FOBTDiagnosticReportsSummary:
  FormatReports(DataElements.FOBTDiagnosticReports, DataElements.FOBTObservations, 'Fecal Occult Blood Test')

define sDNAFITDiagnosticReportsSummary:
  FormatReports(DataElements.StoolDNAFITDiagnosticReports, DataElements.StoolDNAFITObservations, 'Stool DNA FIT Test')

define ColonoscopyDiagnosticReportsSummary:
  FormatReports(DataElements.ColonoscopyDiagnosticReports, DataElements.ColonoscopyObservations, 'Colonoscopy')

define CTColonographyDiagnosticReportsSummary:
  FormatReports(DataElements.CTColonographyDiagnosticReports, DataElements.CTColonographyObservations, 'CT Colonography')

define FlexSigDiagnosticReportsSummary:
  FormatReports(DataElements.FlexSigDiagnosticReports, DataElements.FlexSigObservations, 'Flexible Sigmoidoscopy')


//TODO: These are in Breast, could consider equivalents needed for colorectal - like polypectomy?
//define BiopsyDiagnosticReportsSummary:
//  FormatReports(DataElements.BiopsyDiagnosticReports, DataElements.BiopsyObservations, 'Breast Biopsy')  

//define IncompleteBiopsyDiagnosticReportsSummary:
//  FormatReports(ScreeningTestIncomplete.IncompleteScreeningPathology, DataElements.BiopsyObservations, 'Breast Biopsy')    

//------------------------------------------------------------------------------
// PERTINENT ENCOUNTERS
//------------------------------------------------------------------------------

define PertinentEncounters:
  DataElements.AllColorectalSymptomEncounters

define PertinentEncountersSummary:
  (PertinentEncounters) E
  return {
    name: Common.ConceptText(E.reasonCode[0]),
    value: E.status,
    date: Common.DateTimeText((E.period as FHIR.Period)."start") +
      ' to ' +
      Common.DateTimeText((E.period as FHIR.Period)."end"),
    reference: 'Encounter/' + E.id
  }

//------------------------------------------------------------------------------
// PERTINENT EPISODES OF CARE
//------------------------------------------------------------------------------
  define PertinentEpisodesOfCare:
    DataElements.PregnancyEpisodesOfCare

define PertinentEpisodesOfCareSummary:
  (PertinentEpisodesOfCare) E
  return {
    name: Common.ConceptText(E.type[0]),
    value: E.status.value,
    date:
      displayStartDate(Common.PeriodObject(E.period)."Start") +
      ' to ' +
      displayEndDate(Common.PeriodObject(E.period)."End"),
    reference: 'EpisodeOfCare/' + E.id,
    edited: HasBeenLocallyEdited(E)
  }
  sort by (date as String) desc


//------------------------------------------------------------------------------
// PERTINENT REQUESTS
//------------------------------------------------------------------------------  

define DueOrOverdueScreeningSummary:
  (ScreeningDue.DueOrOverdue) R
    return
  {
    name: Common.ConceptText(R.code),
    intent: R.intent, 
    occurrence: R.nextDue,
    flag: R.flag.display,
    plannedRepeat: R.plannedRepeat
  }  

define IncompleteScreeningOrdersSummary:
  (ScreeningIncomplete.IncompleteScreeningOrders) R
    return
  {
    name: Common.ConceptText(R.code),
    intent: R.intent, 
    occurence: R.occurrence as FHIR.dateTime,
    flag: null,
    plannedRepeat: null
  }      

define PertinentRequestsSummary:
  DueOrOverdueScreeningSummary union
    IncompleteScreeningOrdersSummary

//------------------------------------------------------------------------------
// FUNCTIONS
//------------------------------------------------------------------------------

define function HasBeenLocallyEdited(R FHIR.DomainResource):
  R.extension ext
    where
      ext.url = 'http://cancerscreeningcds.github.io/crcsm-cds/StructureDefinition/crcsm-edited'
      and ext.value as FHIR.boolean = true

define function Onset(c FHIR.FamilyMemberHistory.Condition):
  Coalesce( List{
    Common.QuantityText(c.onset as FHIR.Age),
    Common.PeriodObject(c.onset as FHIR.Period),
    Common.RangeObject(c.onset as FHIR.Range),
    (c.onset as FHIR.string).value
  })      

define function FormatReports(DrList List<DiagnosticReport>, ObsList List<Observation>, ReportType String):
  (DrList) D
  let CollatedCodes: CRCSMCommon.CollateConclusionCodes(D,ObsList)
  return {
    name: ReportType,
    longName: Common.ConceptText(D.code),
    value: CollatedCodes, //TODO: what to return for report value??
    date: Common.DiagnosticReportDateString(D),
    reference: 'DiagnosticReport/' + D.id,
    edited: HasBeenLocallyEdited(D)
  }      

define function displayStartDate(startDate String):
  if startDate is not null then
    startDate
  else
    'no start date available'

define function displayEndDate(endDate String):
  if endDate is not null then
    endDate
  else
    'no end date available'
Content: application/elm+xml
Encoded data (350444 characters)
Content: application/elm+json
Encoded data (658844 characters)