示例#1
0
class MasterRecordSchema(OrmModel):
    id: int
    nationalid: str
    nationalid_type: str
    last_updated: datetime.datetime
    date_of_birth: datetime.date
    gender: Optional[str]
    givenname: Optional[str]
    surname: Optional[str]
    status: int
    effective_date: datetime.datetime

    links = LinkSet({
        "self":
        UrlFor("master_record_detail", {"record_id": "<id>"}),
        "latestMessage":
        UrlFor("master_record_latest_message", {"record_id": "<id>"}),
        "statistics":
        UrlFor("master_record_statistics", {"record_id": "<id>"}),
        "related":
        UrlFor("master_record_related", {"record_id": "<id>"}),
        "messages":
        UrlFor("master_record_messages", {"record_id": "<id>"}),
        "linkrecords":
        UrlFor("master_record_linkrecords", {"record_id": "<id>"}),
        "persons":
        UrlFor("master_record_persons", {"record_id": "<id>"}),
        "workitems":
        UrlFor("master_record_workitems", {"record_id": "<id>"}),
        "patientrecords":
        UrlFor("master_record_patientrecords", {"record_id": "<id>"}),
        "audit":
        UrlFor("master_record_audit", {"record_id": "<id>"}),
    })
示例#2
0
class Person(HyperModel):
    name: str
    id: str
    items: List[ItemSummary]

    href = UrlFor("read_person", {"person_id": "<id>"})
    links = LinkSet(
        {
            "self": UrlFor("read_person", {"person_id": "<id>"}),
            "items": UrlFor("read_person_items", {"person_id": "<id>"}),
        }
    )

    hal_href = HALFor("read_person", {"person_id": "<id>"})
    hal_links = LinkSet(
        {
            "self": HALFor("read_person", {"person_id": "<id>"}),
            "items": HALFor("read_person_items", {"person_id": "<id>"}),
            "addItem": HALFor(
                "put_person_items",
                {"person_id": "<id>"},
                description="Add an item to this person and the items list",
            ),
        }
    )

    class Config:
        # Alias hal_links to _links as per the HAL standard
        fields = {"hal_links": "_links"}
示例#3
0
class FacilitySchema(OrmModel):
    id: str
    description: Optional[str]

    links = LinkSet({
        "self":
        UrlFor("facility", {"code": "<id>"}),
        "errorsHistory":
        UrlFor("facility_errrors_history", {"code": "<id>"}),
        "patientsLatestErrors":
        UrlFor("facility_patients_latest_errors", {"code": "<id>"}),
    })
示例#4
0
class MessageSchema(MinimalMessageSchema):
    message_id: int
    error: Optional[str]
    status: Optional[str]
    links = LinkSet({
        "self":
        UrlFor("error_detail", {"message_id": "<id>"}),
        "source":
        UrlFor("error_source", {"message_id": "<id>"}),
        "workitems":
        UrlFor("error_workitems", {"message_id": "<id>"}),
        "masterrecords":
        UrlFor("error_masterrecords", {"message_id": "<id>"}),
        "mirth":
        UrlFor(
            "mirth_channel_message",
            {
                "channel_id": "<channel_id>",
                "message_id": "<message_id>"
            },
        ),
    })

    channel_id: str
    channel: Optional[str]

    _channel_id_name_map: dict[str, str]

    @classmethod
    def set_channel_id_name_map(cls, cinm: dict[str, str]):
        """
        Set the Mirth Channel ID-Name map.
        This model inserts a channel name from its channel_id field,
        when given a map of IDs to names.

        Args:
            cinm (dict[str, str]): Mirth Channel ID-Name map
        """
        cls._channel_id_name_map = cinm

    @validator("channel")
    def channel_name(cls, _, values):  # pylint: disable=no-self-argument,no-self-use
        """
        Dynamically generates the channel name field
        by reading the class Mirth Channel ID-Name map.
        """
        # TODO: Replace with computed_fields once available: https://github.com/samuelcolvin/pydantic/pull/2625
        if hasattr(cls, "_channel_id_name_map"):
            channel_id = values.get("channel_id")
            if channel_id:
                return cls._channel_id_name_map.get(channel_id)
        return None
示例#5
0
class TrackableTaskSchema(JSONModel):
    id: UUID
    name: str
    visibility: VisibilityType
    owner: str
    status: StatusType
    error: Optional[str] = None

    created: datetime.datetime
    started: Optional[datetime.datetime] = None
    finished: Optional[datetime.datetime] = None

    links = LinkSet(
        {
            "self": UrlFor("get_task", {"task_id": "<id>"}),
        }
    )

    @classmethod
    def from_redis(cls, redis_dict: dict):
        """
        We can't store NoneType in Redis, so when loading
        from Redis we need to convert empty strings to None
        """
        normalized_dict: dict[str, Optional[str]] = {}
        for key, value in redis_dict.items():
            if value == "":
                normalized_dict[key] = None
            else:
                normalized_dict[key] = value
        return cls(**normalized_dict)
示例#6
0
class Person(HyperModel):
    name: str
    id: str
    items: List[ItemSummary]

    # Single link attribute
    href = UrlFor("read_person", {"person_id": "<id>"})

    # Link set attribute
    # For larger APIs, this tends to be more useful as it allows you to easily
    # generate a list of links for all the sub-resources of a resource
    links = LinkSet({
        "self":
        UrlFor("read_person", {"person_id": "<id>"}),
        "items":
        UrlFor("read_person_items", {"person_id": "<id>"}),
    })
示例#7
0
class MirthChannelMessageModel(ChannelMessageModel, OrmModel):  # type: ignore
    links = LinkSet(
        {
            "self": UrlFor(
                "mirth_channel_message",
                {"channel_id": "<channel_id>", "message_id": "<message_id>"},
            ),
        }
    )
示例#8
0
class WorkItemSchema(OrmModel):
    id: int

    type: int
    description: str
    status: int

    creation_date: datetime.datetime

    last_updated: datetime.datetime
    updated_by: Optional[str]

    attributes: Optional[Union[Json, dict]]
    update_description: Optional[str]

    person: Optional[PersonSchema]
    master_record: Optional[MasterRecordSchema]

    links = LinkSet({
        "self":
        UrlFor("workitem_detail", {"workitem_id": "<id>"}),
        "collection":
        UrlFor("workitem_collection", {"workitem_id": "<id>"}),
        "related":
        UrlFor("workitem_related", {"workitem_id": "<id>"}),
        "messages":
        UrlFor("workitem_messages", {"workitem_id": "<id>"}),
        "close":
        UrlFor("workitem_close", {"workitem_id": "<id>"}),
    })

    @validator("attributes")
    def normalise_attributes(cls, value):  # pylint: disable=no-self-argument,no-self-use
        """
        Convert attributes JSON keys into MasterRecord property keys
        """
        if not isinstance(value, dict):
            return value
        return {
            WORKITEM_ATTRIBUTE_MAP.get(key, key): attribute
            for key, attribute in value.items()
        }
示例#9
0
class PersonSchema(OrmModel):
    id: int
    originator: str
    localid: str
    localid_type: str
    date_of_birth: datetime.date
    gender: str
    date_of_death: Optional[datetime.date]
    givenname: Optional[str]
    surname: Optional[str]
    xref_entries: list[PidXRefSchema]

    links = LinkSet({
        "self":
        UrlFor("person_detail", {"person_id": "<id>"}),
        "patientrecord":
        UrlFor("patient_get", {"pid": "<localid>"}),
        "masterrecords":
        UrlFor("person_masterrecords", {"person_id": "<id>"}),
    })
示例#10
0
class DocumentSummarySchema(OrmModel):
    id: str
    pid: str
    documenttime: Optional[datetime.datetime]
    documentname: Optional[str]

    filetype: Optional[str]
    filename: Optional[str]

    enteredbydesc: Optional[str]
    enteredatcode: Optional[str]

    links = LinkSet(
        {
            "self": UrlFor("document_get", {"pid": "<pid>", "document_id": "<id>"}),
            "download": UrlFor(
                "document_download", {"pid": "<pid>", "document_id": "<id>"}
            ),
        }
    )
示例#11
0
class LabOrderShortSchema(OrmModel):
    id: str
    pid: str

    entered_at_description: Optional[str]
    entered_at: Optional[str]
    specimen_collected_time: Optional[datetime.datetime]

    links = LinkSet(
        {"self": UrlFor("laborder_get", {
            "pid": "<pid>",
            "order_id": "<id>"
        })})
示例#12
0
class ResultItemSchema(OrmModel):
    id: str
    pid: str

    order_id: str
    service_id: str
    service_id_description: Optional[str]
    value: Optional[str]
    value_units: Optional[str]
    result_type: Optional[str]
    observation_time: Optional[datetime.datetime]

    links = LinkSet({
        "self":
        UrlFor("resultitem_get", {
            "pid": "<pid>",
            "resultitem_id": "<id>"
        }),
        "laborder":
        UrlFor("laborder_get", {
            "pid": "<pid>",
            "order_id": "<order_id>"
        }),
    })
示例#13
0
class PatientRecordSummarySchema(OrmModel):
    """Schema for lists of PatientRecords"""

    pid: str
    sendingfacility: str
    sendingextract: str
    localpatientid: str
    ukrdcid: str

    program_memberships: list[ProgramMembershipSchema]
    patient: Optional[PatientSchema]

    links = LinkSet(
        {
            # Self-resources
            "self": UrlFor("patient_get", {"pid": "<pid>"}),
            "related": UrlFor("patient_related", {"pid": "<pid>"}),
            "delete": UrlFor("patient_delete", {"pid": "<pid>"}),
            # Internal resources
            "medications": UrlFor("patient_medications", {"pid": "<pid>"}),
            "treatments": UrlFor("patient_treatments", {"pid": "<pid>"}),
            "surveys": UrlFor("patient_surveys", {"pid": "<pid>"}),
            "documents": UrlFor("patient_documents", {"pid": "<pid>"}),
            # Complex internal resources
            "observations": UrlFor("patient_observations", {"pid": "<pid>"}),
            "observationCodes": UrlFor("patient_observation_codes", {"pid": "<pid>"}),
            "results": UrlFor("patient_resultitems", {"pid": "<pid>"}),
            "resultServices": UrlFor("patient_result_services", {"pid": "<pid>"}),
            "laborders": UrlFor("patient_laborders", {"pid": "<pid>"}),
            # Exports
            "exportPV": UrlFor("patient_export_pv", {"pid": "<pid>"}),
            "exportPVTests": UrlFor("patient_export_pv_tests", {"pid": "<pid>"}),
            "exportPVDocs": UrlFor("patient_export_pv_docs", {"pid": "<pid>"}),
            "exportRADAR": UrlFor("patient_export_radar", {"pid": "<pid>"}),
        }
    )
示例#14
0
class ItemSummary(HyperModel):
    name: str
    id: str
    # This is a dynamic link to the Item resource
    href = UrlFor("read_item", {"item_id": "<id>"})
示例#15
0
class MirthChannelModel(ChannelModel, OrmModel):  # type: ignore
    links = LinkSet(
        {
            "self": UrlFor("mirth_channel", {"channel_id": "<id>"}),
        }
    )
示例#16
0
class ItemSummary(HyperModel):
    name: str
    id: str

    href = UrlFor("read_item", {"item_id": "<id>"})