Skip to content

eCR ‐ FHIR Conversion Resources

emmastephenson edited this page Feb 15, 2024 · 2 revisions

Background

Our FHIR converter builds on the Microsoft FHIR Converter and adds custom logic to better handle eCR conversion. This custom logic is created in Liquid templates.

Acronyms to know

Acronym Meaning
CDA Clinical Document Architecture
C-CDA Consolidated Clinical Document Architecture
eICR Electronic Initial Case Report
RR Reportability Response

Resources

  • FHIR Conversion how-to (recording)
  • LAC Sample Data (zip file)
  • CDA implementation guide for eICR (HL7 resource - you want the "Download" option)

Python script to find strings in eCR data:

import zipfile
from pathlib import Path
import os
import glob
import shutil


def main():
    # Note: you need the final "/" in path, or files will be created as outputfilename instead of output/filename
    target_dir = "/path/to/your/target/directory/for/output/"

    # Find all the zip files

    # Replace with your own path to LAC_DATA folder (should be unzipped)
    folder = Path(__file__).parent.parent/"LAC_DATA"
    for filename in glob.glob(os.path.join(folder, '*.zip')):
        zip_ref = zipfile.ZipFile(filename)
        ecr = None
        rr = None
        try:
            ecr = zip_ref.open("CDA_eICR.xml")
            ecr_data = ecr.read().decode("utf-8")

            rr = zip_ref.open("CDA_RR.xml")
            rr_data = rr.read().decode("utf-8")
            
            searching_string = "string_to_search"

            if searching_string in ecr_data or searching_string in rr_data:
                id_num = filename.split("/")[-1]
                shutil.copy(filename, target_dir + id_num)
                print(filename + " was copied to new directory")
        except KeyError:
            print("No eICR/RR here")
            pass

    data_count = 0
    for bundle in glob.glob(os.path.join(target_dir, '*.zip')):
        data_count += 1
        with zipfile.ZipFile(bundle, 'r') as zip_ref:
            zip_ref.extractall(target_dir)
    print(data_count, "matches found")
        


main()
Clone this wiki locally