FHIR out from the catalog, the FHIR door, ConceptMap routes; round-trip, new-label and Synthea gates

This commit is contained in:
Roberto Treviño
2026-11-25 16:17:23 -06:00
parent 0dd5c035bc
commit 806302ee5d
8 changed files with 441 additions and 47 deletions
+12 -10
View File
@@ -118,11 +118,11 @@ def follow_up(bundles: list[dict], start: str, cutoff: str) -> list[dict]:
for x in report.get("result", []))} # fmt: skip
cytologies = sorted(
(r for r in reports if _code(r["code"]) == "cervical-cytology"
(r for r in reports if _code(r["code"]) == "cervical_cytology"
and start <= r["effectiveDateTime"] <= cutoff),
key=lambda r: r["effectiveDateTime"]) # fmt: skip
hpv = [r for r in cytologies if "hpv" in results(r)]
biopsies = sorted((r for r in reports if _code(r["code"]) == "cervical-biopsy"
hpv = [r for r in cytologies if "cervical_cytology.hpv" in results(r)]
biopsies = sorted((r for r in reports if _code(r["code"]) == "cervical_biopsy"
and _ext(r, "report-date")),
key=lambda r: _ext(r, "report-date")["valueDate"]) # fmt: skip
status = _ext(patient, "follow-up-status")["valueCoding"]["code"]
@@ -132,20 +132,22 @@ def follow_up(bundles: list[dict], start: str, cutoff: str) -> list[dict]:
last, found = cytologies[-1], results(cytologies[-1])
row["cytology"] = {"date": last["effectiveDateTime"], **{
k: _code(found[c]["valueCodeableConcept"]) if c in found else None
for k, c in (("result", "cytology-result"),
("adequacy", "cytology-adequacy"))}} # fmt: skip
for k, c in (("result", "cervical_cytology.result"),
("adequacy", "cervical_cytology.adequacy"))}} # fmt: skip
days = _ext(last, "days-to-diagnosis")
row["days_to_diagnosis"] = days and days["valueInteger"]
if hpv:
found = results(hpv[-1])
types = [found[k]["valueBoolean"] for k in ("hpv-16", "hpv-18") if k in found]
typed = ("cervical_cytology.hpv_16", "cervical_cytology.hpv_18")
types = [found[k]["valueBoolean"] for k in typed if k in found]
row["hpv"] = {"date": hpv[-1]["effectiveDateTime"],
"positive": found["hpv"]["valueBoolean"],
"positive": found["cervical_cytology.hpv"]["valueBoolean"],
"types_16_18": any(types) if types else None} # fmt: skip
if biopsies:
last = biopsies[-1]
last, found = biopsies[-1], results(biopsies[-1])
grade = found.get("cervical_biopsy.histology")
histology = grade and _code(grade["valueCodeableConcept"])
row["biopsy"] = {"date": _ext(last, "report-date")["valueDate"],
"histology": _code(last["conclusionCode"][0])
if last.get("conclusionCode") else None} # fmt: skip
"histology": histology} # fmt: skip
rows.append(row)
return rows