コード例 #1
0
ファイル: organization.py プロジェクト: bglar/gawana-fhir
 def element_properties(self):
     elm = super().element_properties()
     elm.extend([
         Field(
             "purpose",
             {
                 "mini": 0,
                 "maxi": 1
             },
             complex.CodeableConceptField(),
             None,
         ),
         # The type of contact.
         Field("name", {
             "mini": 0,
             "maxi": 1
         }, complex.HumanNameField(), None),
         # A name associated with the contact.
         Field("address", {
             "mini": 0,
             "maxi": 1
         }, complex.AddressField(), None),
         # Visiting or postal addresses for the contact.
         Field(
             "telecom",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.ContactPointField(),
             None,
         )
         # Contact details (telephone, email, etc.)  for a contact.
     ])
     return elm
コード例 #2
0
 def element_properties(self):
     elm = super().element_properties()
     elm.extend([
         Field(
             "relationship",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.CodeableConceptField(),
             None,
         ),
         # The kind of relationship
         Field("name", {
             "mini": 0,
             "maxi": 1
         }, complex.HumanNameField(), None),
         # A name associated with the contact person
         Field(
             "telecom",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.ContactPointField(),
             None,
         ),
         # A contact detail for the person
         Field("address", {
             "mini": 0,
             "maxi": 1
         }, complex.AddressField(), None),
         # Address for the contact person
         Field("gender", {
             "mini": 0,
             "maxi": 1
         }, primitives.CodeField, None),
         # male | female | other | unknown
         Field(
             "organization",
             {
                 "mini": 0,
                 "maxi": 1
             },
             complex.ReferenceField(),
             "Organization",
         ),
         # Organization that is associated with the contact
         Field("period", {
             "mini": 0,
             "maxi": 1
         }, complex.PeriodField(), None),
         # The period during which this contact person or organization
         # is valid to be contacted relating to this patient
     ])
     return elm
コード例 #3
0
ファイル: organization.py プロジェクト: bglar/gawana-fhir
class Organization(DomainResource):
    """ A grouping of people or organizations with a common purpose.

    A formally or informally recognized grouping of people or organizations
    formed for the purpose of achieving some form of collective action.
    Includes companies, institutions, corporations, departments, community
    groups, healthcare practice groups, etc.
    """

    active = Column(primitives.BooleanField)
    # Whether the organization's record is still in active use.

    name = Column(primitives.StringField)
    # Name used for the organization.

    alias = Column(Array(primitives.StringField))
    # A list of alternate names that the organization is known as,
    # or was known as in the past

    identifier = Column(Array(complex.IdentifierField()))
    # Identifies this organization  across multiple systems.

    type = Column(complex.CodeableConceptField())
    # Kind of organization.

    partOf = Column(complex.ReferenceField())
    # The organization of which this organization forms a part.

    telecom = Column(Array(complex.ContactPointField()))
    # A contact detail for the organization.

    address = Column(Array(complex.AddressField()))
    # An address for the organization.

    endpoint = Column(Array(complex.ReferenceField()))
    # Technical endpoints providing access to services operated
    # for the organization

    contact = Column(Array(OrganizationContactField()))
    # Contact for the organization for a certain purpose.

    @declared_attr
    def references(self):
        """
        :return:
        Dict. values in the dict should be a | separated string of
        reference resources"""

        return {"partOf": "Organization", "endpoint": "Endpoint"}

    @validates("partOf", "endpoint")
    def reference_fields(self, key, field):
        """Validates multiple reference fields.

        To add more fields: @validates('field1', 'field2', 'field3')
        And replace the code block before the return statement with:
            ```
            for field_name, reference in self.references.items():
                if key == field_name:
                    self.validate_references(reference, field)
            ```
        """
        for field_name, reference in self.references.items():
            if key == field_name:
                self.validate_references(reference, field)

        return field

    @validates("type")
    def validate_organization_type(self, key, type):
        msg = "organization type code"
        self.code_fields_validator(type, ORGANIZATION_TYPE_URL, msg)

        return type

    @validates("telecom")
    def validate_telecom(self, key, telecom):
        if telecom:
            for tel in telecom:
                code_val = tel.get("use")
                if code_val == "home":
                    raise ValueError("The telecom of an organization "
                                     "can never be of use `home`")

        return telecom

    @validates("address")
    def validate_address(self, key, address):
        if address:
            for ad in address:
                code_val = ad.get("use")
                if code_val == "home":
                    raise ValueError("An address of an organization can "
                                     "never be of use `home`")

        return address

    @validates("contact")
    def validates_contact(self, key, contact):
        if contact:
            pass

    def _resource_summary(self):
        summary_fields = ["id", "meta", "identifier", "name", "type"]
        return {"repr": "%r" % self.name, "fields": summary_fields}

    def __repr__(self):
        return "<%r %r>" % (self.__class__.__name__, self.name)
コード例 #4
0
ファイル: location.py プロジェクト: bglar/gawana-fhir
class Location(DomainResource):
    """ Details and position information for a physical place.

    Details and position information for a physical place where services are
    provided  and resources and participants may be stored, found, contained or
    accommodated.
    """

    identifier = Column(Array(complex.IdentifierField()))
    # Unique code or number identifying the location to its users.

    status = Column(primitives.CodeField)
    # active | suspended | inactive.

    name = Column(primitives.StringField)
    # Name of the location as used by humans.

    description = Column(primitives.StringField)
    # Description of the location.

    mode = Column(primitives.CodeField)
    # instance | kind.

    alias = Column(Array(primitives.StringField))
    # A list of alternate names that the location is known as,
    # or was known as in the past

    type = Column(complex.CodeableConceptField())
    # Type of function performed.

    telecom = Column(Array(complex.ContactPointField()))
    # Contact details of the location.

    address = Column(complex.AddressField())
    # Physical location.

    physicalType = Column(complex.CodeableConceptField())
    # Physical form of the location.

    position = Column(LocationPositionField())
    # The absolute geographic location.

    managingOrganization = Column(complex.ReferenceField())
    # Organization responsible for provisioning and upkeep.

    partOf = Column(complex.ReferenceField())
    # Another Location this one is physically part of.

    endpoint = Column(Array(complex.ReferenceField()))
    # Technical endpoints providing access to services
    # operated for the location

    @declared_attr
    def references(self):
        """
        :return:
        Dict. values in the dict should be a | separated string of
        reference resources"""

        return {"managingOrganization": "Organization", "partOf": "Location"}

    @validates("managingOrganization", "partOf")
    def reference_fields(self, key, field):
        """Validates multiple reference fields.

        To add more fields: @validates('field1', 'field2', 'field3')
        And replace the code block before the return statement with:
            ```
            for field_name, reference in self.references.items():
                if key == field_name:
                    self.validate_references(reference, field)
            ```
        """

        for field_name, reference in self.references.items():
            if key == field_name:
                self.validate_references(reference, field)

        return field

    @validates("status")
    def validate_location_status(self, key, status):
        msg = "location status"
        self.code_fields_validator(status, LOCATION_STATUS_URL, msg)

        return status

    @validates("mode")
    def validate_location_mode(self, key, mode):
        msg = "location mode"
        self.code_fields_validator(mode, LOCATION_MODE_URL, msg)

        return mode

    @validates("type")
    def validate_location_type(self, key, type):
        msg = "location type code"
        self.code_fields_validator(type,
                                   SERVICE_DELIVERY_LOCATION_ROLE_TYPE_URL,
                                   msg)

        return type

    @validates("physicalType")
    def validate_physical_type(self, key, physicalType):
        msg = "location physical type code"
        self.code_fields_validator(physicalType, LOCATION_PHYSICAL_TYPE_URI,
                                   msg)

        return physicalType

    def _resource_summary(self):
        summary_fields = ["id", "meta", "identifier", "name"]
        return {"repr": "%r" % self.name, "fields": summary_fields}

    def __repr__(self):
        return "<Location %r>" % self.name
コード例 #5
0
class Patient(DomainResource):
    """ Information about an individual or animal receiving health care
    services.

    Demographics and other administrative information about an individual or
    animal receiving care or other health-related services.
    """

    active = Column(primitives.BooleanField)
    # Whether this patient's record is in active use

    gender = Column(primitives.CodeField)
    # male | female | other | unknown

    birthDate = Column(primitives.DateField)
    # The date of birth for the individual

    deceasedBoolean = Column(primitives.BooleanField)
    # Indicates if the individual is deceased or not

    deceasedDateTime = Column(primitives.DateTimeField)
    # Indicates if the individual is deceased or not

    multipleBirthBoolean = Column(primitives.BooleanField)
    # Whether patient is part of a multiple birth

    multipleBirthInteger = Column(primitives.IntegerField)
    # Whether patient is part of a multiple birth

    identifier = Column(Array(complex.IdentifierField()))
    # An identifier for this patient

    name = Column(Array(complex.HumanNameField()))
    # A name associated with the patient

    telecom = Column(Array(complex.ContactPointField()))
    # A contact detail for the individual

    address = Column(Array(complex.AddressField()))
    # Addresses for the individual

    maritalStatus = Column(complex.CodeableConceptField())
    # Marital (civil) status of a patient

    photo = Column(Array(complex.AttachmentField()))
    # Image of the patient

    contact = Column(Array(PatientContactField()))
    # A contact party (e.g. guardian, partner, friend) for the patient

    animal = Column(PatientAnimalField())
    # This patient is known to be an animal (non-human)

    communication = Column(Array(PatientCommunicationField()))
    # A list of Languages which may be used to communicate with the
    # patient about his or her health

    careProvider = Column(Array(complex.ReferenceField()))
    # Patient's nominated primary care provider

    managingOrganization = Column(complex.ReferenceField())
    # Organization that is the custodian of the patient record

    generalPractitioner = Column(Array(complex.ReferenceField()))
    # Patient's nominated primary care provider

    link = Column(Array(PatientLinkField()))
    # Link to another patient resource that concerns the same actual person

    @declared_attr
    def references(self):
        """
        :return:
        Dict. values in the dict should be a | separated string of
        reference resources"""

        return {
            "careProvider": "Organization|Practitioner",
            "managingOrganization": "Organization",
            "generalPractitioner": "Organization|Practitioner",
        }

    @validates("careProvider", "managingOrganization", "generalPractitioner")
    def reference_fields(self, key, field):
        """Validates multiple reference fields.

        To add more fields: @validates('field1', 'field2', 'field3')
        And replace the code block before the return statement with:
            ```
            for field_name, reference in self.references.items():
                if key == field_name:
                    self.validate_references(reference, field)
            ```
        """

        for field_name, reference in self.references.items():
            if key == field_name:
                self.validate_references(reference, field)

        return field

    @validates("gender")
    def validate_patient_gender(self, key, gender):
        msg = "patient gender"
        self.code_fields_validator(gender, ADMINISTRATIVE_GENDER_URL, msg)

        return gender

    @validates("maritalStatus")
    def validate_marital_status(self, key, maritalStatus):
        msg = "patient marital status code"
        self.code_fields_validator(maritalStatus, MARITAL_STATUS_URL, msg)

        return maritalStatus

    @validates("contact")
    def validate_patient_contact(self, key, contact):
        if contact:
            for data in contact:
                relationships = data.get("relationship")
                gender = data.get("gender")

                msg1 = "patient contact gender"
                self.code_fields_validator(gender, ADMINISTRATIVE_GENDER_URL,
                                           msg1)

                msg2 = "patient contact relationship"
                self.code_fields_validator(relationships,
                                           PATIENT_CONTACT_RELATIONSHIP_URL,
                                           msg2)

        return contact

    @validates("animal")
    def validate_animal(self, key, animal):
        if animal:
            species = animal.get("species")
            msg1 = "patient animal species"
            self.code_fields_validator(species, ANIMAL_SPECIES_URL, msg1)

            breed = animal.get("breed")
            msg2 = "patient animal breed"
            self.code_fields_validator(breed, ANIMAL_BREEDS_URL, msg2)

            gender_status = animal.get("genderStatus")
            msg3 = "patient animal gender status"
            self.code_fields_validator(gender_status, GENDER_STATUS_URL, msg3)

        return animal

    @validates("communication")
    def validate_communication(self, key, communication):
        if communication:
            for data in communication:
                language = data.get("language")
                msg = "patient communication language"
                self.code_fields_validator(language, LANGUAGE_URI, msg)

        return communication

    @validates("link")
    def validate_link(self, key, link):
        if link:
            for data in link:
                link_type = data.get("type")
                msg = "patient link type"
                self.code_fields_validator(link_type, LINK_TYPE_URL, msg)

        return link

    def _resource_summary(self):
        summary_fields = ["id", "meta", "identifier", "name"]

        try:
            patient_text = self.name
        except AttributeError:
            patient_text = None
        return {"repr": "%r" % patient_text, "fields": summary_fields}

    def __repr__(self):
        if self.name:
            return "<Patient %r>" % self.name
        else:
            return "<Patient None>"
コード例 #6
0
class Practitioner(DomainResource):
    """ A person with a  formal responsibility in the provisioning of
    healthcare or related services.

    A person who is directly or indirectly involved in the provisioning of
    healthcare.
    """

    gender = Column(primitives.CodeField)
    # male | female | other | unknown.

    birthDate = Column(primitives.DateField)
    # The date  on which the practitioner was born.

    active = Column(primitives.BooleanField)
    # Whether this practitioner's record is in active use.

    name = Column(Array(complex.HumanNameField()))
    # A name associated with the person.

    identifier = Column(Array(complex.IdentifierField()))
    # A identifier for the person as this agent.

    telecom = Column(Array(complex.ContactPointField()))
    # A contact detail for the practitioner.

    address = Column(Array(complex.AddressField()))
    # Where practitioner can be found/visited.

    photo = Column(Array(complex.AttachmentField()))
    # Image of the person.

    communication = Column(Array(complex.CodeableConceptField()))
    # A language the practitioner is able to use in patient communication.

    role = Column(Array(PractitionerPractitionerRoleField()))
    # Roles/organizations the practitioner is associated with.

    qualification = Column(Array(PractitionerQualificationField()))
    # Qualifications obtained by training and certification.

    @validates("gender")
    def validate_practitioner_gender(self, key, gender):
        url = ADMINISTRATIVE_GENDER_URL + "?code=" + gender
        self.validate_valuesets(gender, url, "practitioner gender")

        return gender

    @validates("role")
    def validate_practitioner_role(self, key, role):
        for data in role:
            role = data.get("role")
            specialities = data.get("speciality")

            msg1 = "practitioner qualification"
            self.code_fields_validator(specialities,
                                       PRACTITIONER_SPECIALITY_URL, msg1)

            msg2 = "practitioner qualification"
            self.code_fields_validator(role, PRACTITIONER_ROLE_URL, msg2)

        return role

    @validates("qualification")
    def validate_qualification(self, key, qualification):
        for data in qualification:
            code = data.get("code")
            msg = "practitioner qualification"
            self.code_fields_validator(code, ANZSCO_OCCUPATIONS_URL, msg)

        return qualification

    @validates("communication")
    def validate_communication(self, key, communication):
        msg = "practitioner communication"
        self.code_fields_validator(communication, LANGUAGE_URI, msg)

        return communication

    def _resource_summary(self):
        summary_fields = ["id", "meta", "identifier", "name"]
        return {"repr": "%r" % self.name, "fields": summary_fields}

    def __repr__(self):
        return "<Practitioner %r>" % self.name