Diagram comparing longitudinal vs encounter-level comorbidity detection using ICD-10 codes across five patient encounters.
Top panel (Longitudinal): The patient initially has uncomplicated diabetes (E11.9). Later an encounter includes E11.22 and K72.10, indicating complex diabetes and severe liver disease. Using longitudinal logic, these conditions persist in later encounters even when only E11.9 appears, preserving severity and correctly flagging severe liver disease.
Bottom panel (Encounter-level): Each encounter is evaluated independently. Diabetes changes from uncomplicated β complex β back to uncomplicated when E11.9 reappears, and severe liver disease is never flagged because its code does not repeat.
Message: Ignoring patient history can downgrade severity or fail to identify comorbidities.
Graphic showing how the medicalcoder R package controls comorbidity detection using the flag.method argument.
Left side: A sample dataset of patient encounters with variables patid, encid, icd10code, and poa, containing ICD-10 codes such as E11.9, K72.10, and E11.22.
Below the dataset are two example R code blocks calling medicalcoder::comorbidities():
flag.method = "current" (default), producing encounter-level comorbidity flags.
flag.method = "cumulative", producing patient-level flags that preserve comorbidities across encounters.
Right side: the medicalcoder hex logo and labels explaining that
current = encounter-level and cumulative = longitudinal history preserving.
The graphic illustrates that longitudinal comorbidity tracking in medicalcoder is controlled by a single argument.
Same ICD codes. Same patient. Different risk profiles.
Encounter-level comorbidity logic assumes ICD codes are re-reported every visit. They usually arenβt.
medicalcoder handles this
π¦install.packages("medicalcoder")
#rstats #HealthInformatics #EHR #ClinicalResearch #RiskAdjustment #PublicHealth