Skip to content

Data Models

CcdData

Bases: BaseModel

Data model for CCD (Continuity of Care Document) that can be converted to CDA.

ATTRIBUTE DESCRIPTION
concepts

Container for medical concepts (problems, allergies, medications) extracted from the document. Defaults to empty ConceptLists.

TYPE: ConceptLists

note

The clinical note text, either as a string or dictionary of sections. Defaults to None.

TYPE: Optional[Union[Dict, str]]

cda_xml

The raw CDA XML string representation of the document. Defaults to None.

TYPE: Optional[str]

Source code in healthchain/models/data/ccddata.py
class CcdData(BaseModel):
    """
    Data model for CCD (Continuity of Care Document) that can be converted to CDA.

    Attributes:
        concepts (ConceptLists): Container for medical concepts (problems, allergies, medications)
            extracted from the document. Defaults to empty ConceptLists.
        note (Optional[Union[Dict, str]]): The clinical note text, either as a string or
            dictionary of sections. Defaults to None.
        cda_xml (Optional[str]): The raw CDA XML string representation of the document.
            Defaults to None.
    """

    concepts: ConceptLists = ConceptLists()
    note: Optional[Union[Dict, str]] = None
    cda_xml: Optional[str] = None

CdsFhirData

Bases: BaseModel

Data model for CDS FHIR data, matching the expected fields in CDSRequests.

ATTRIBUTE DESCRIPTION
context

A dictionary containing contextual information for the CDS request.

TYPE: Dict

prefetch

A Bundle object containing prefetched FHIR resources.

TYPE: Bundle

METHOD DESCRIPTION
create

Dict, prefetch: Dict): Class method to create a CdsFhirData instance.

model_dump

Returns a dictionary representation of the model.

model_dump_json

Returns a JSON string representation of the model.

model_dump_prefetch

Returns a dictionary representation of the prefetch Bundle.

Source code in healthchain/models/data/cdsfhirdata.py
class CdsFhirData(BaseModel):
    """
    Data model for CDS FHIR data, matching the expected fields in CDSRequests.

    Attributes:
        context (Dict): A dictionary containing contextual information for the CDS request.
        prefetch (Bundle): A Bundle object containing prefetched FHIR resources.

    Methods:
        create(cls, context: Dict, prefetch: Dict): Class method to create a CdsFhirData instance.
        model_dump(*args, **kwargs): Returns a dictionary representation of the model.
        model_dump_json(*args, **kwargs): Returns a JSON string representation of the model.
        model_dump_prefetch(*args, **kwargs): Returns a dictionary representation of the prefetch Bundle.
    """

    context: Dict = Field(default={})
    prefetch: Bundle

    @classmethod
    def create(cls, context: Dict, prefetch: Dict):
        # deep copy to avoid modifying the original prefetch data
        prefetch_copy = copy.deepcopy(prefetch)
        bundle = Bundle(**prefetch_copy)
        return cls(context=context, prefetch=bundle)

    def model_dump(self, *args, **kwargs):
        kwargs.setdefault("exclude_unset", True)
        kwargs.setdefault("exclude_defaults", False)
        kwargs.setdefault("exclude_none", True)
        kwargs.setdefault("by_alias", True)

        return super().model_dump(*args, **kwargs)

    def model_dump_json(self, *args, **kwargs):
        kwargs.setdefault("exclude_unset", True)
        kwargs.setdefault("exclude_defaults", False)
        kwargs.setdefault("exclude_none", True)
        kwargs.setdefault("by_alias", True)

        return super().model_dump_json(*args, **kwargs)

    def model_dump_prefetch(self, *args, **kwargs):
        kwargs.setdefault("exclude_unset", True)
        kwargs.setdefault("exclude_defaults", False)
        kwargs.setdefault("exclude_none", True)
        kwargs.setdefault("by_alias", True)

        return self.prefetch.model_dump(*args, **kwargs)

AllergyConcept

Bases: Concept

Contains allergy specific fields

Defaults allergy type to propensity to adverse reactions in SNOMED CT

Source code in healthchain/models/data/concept.py
class AllergyConcept(Concept):
    """
    Contains allergy specific fields

    Defaults allergy type to propensity to adverse reactions in SNOMED CT
    """

    allergy_type: Optional[Concept] = Field(
        default=Concept(
            code="420134006",
            code_system="2.16.840.1.113883.6.96",
            code_system_name="SNOMED CT",
            display_name="Propensity to adverse reactions",
        )
    )
    severity: Optional[Concept] = None
    reaction: Optional[Concept] = None

Concept

Bases: BaseModel

A more lenient, system agnostic representation of a concept e.g. problems, medications, allergies that can be converted to CDA or FHIR

Source code in healthchain/models/data/concept.py
class Concept(BaseModel):
    """
    A more lenient, system agnostic representation of a concept e.g. problems, medications, allergies
    that can be converted to CDA or FHIR
    """

    _standard: Optional[Standard] = None
    code: Optional[str] = None
    code_system: Optional[str] = None
    code_system_name: Optional[str] = None
    display_name: Optional[str] = None

ConceptLists

Bases: BaseModel

Container for lists of medical concepts extracted from text.

Source code in healthchain/models/data/concept.py
class ConceptLists(BaseModel):
    """Container for lists of medical concepts extracted from text."""

    problems: List[ProblemConcept] = []
    allergies: List[AllergyConcept] = []
    medications: List[MedicationConcept] = []

    class Config:
        arbitrary_types_allowed = True

DataType

Bases: BaseModel

Base class for all data types

Source code in healthchain/models/data/concept.py
class DataType(BaseModel):
    """
    Base class for all data types
    """

    _source: Optional[Dict] = None

MedicationConcept

Bases: Concept

Contains medication specific fields

Source code in healthchain/models/data/concept.py
class MedicationConcept(Concept):
    """
    Contains medication specific fields
    """

    dosage: Optional[Quantity] = None
    route: Optional[Concept] = None
    frequency: Optional[TimeInterval] = None
    duration: Optional[Range] = None
    precondition: Optional[Dict] = None

ProblemConcept

Bases: Concept

Contains problem/condition specific fields

Source code in healthchain/models/data/concept.py
class ProblemConcept(Concept):
    """
    Contains problem/condition specific fields
    """

    onset_date: Optional[str] = None
    abatement_date: Optional[str] = None
    status: Optional[str] = None
    recorded_date: Optional[str] = None