示例#1
0
 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
class Questionnaire(DomainResource):
    """ A structured set of questions.

    A structured set of questions intended to guide the collection of answers.
    The questions are ordered and grouped into coherent subsets, corresponding
    to the structure of the grouping of the underlying questions.
    """

    url = Column(primitives.URIField)
    # Globally unique logical identifier for questionnaire

    version = Column(primitives.StringField)
    # Logical identifier for this version of Questionnaire

    status = Column(primitives.CodeField, nullable=False)
    # draft | published | retired

    date = Column(primitives.DateTimeField)
    # Date this version was authored

    publisher = Column(primitives.StringField)
    # Organization/individual who designed the questionnaire

    title = Column(primitives.StringField)
    # Name for the questionnaire

    subjectType = Column(Array(primitives.CodeField))
    # Resource that can be subject of QuestionnaireResponse

    identifier = Column(Array(complex.IdentifierField()))
    # External identifiers for this questionnaire

    telecom = Column(Array(complex.ContactPointField()))
    # Contact information of the publisher

    useContext = Column(Array(complex.CodeableConceptField))
    # Questionnaire intends to support these contexts

    concept = Column(Array(complex.CodingField))
    # Concept that represents the overall questionnaire

    item = Column(Array(QuestionnaireItemField()))

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

    def __repr__(self):
        return "<OperationOutcome %r>" % self.id
示例#4
0
 def element_properties(self):
     elm = super().element_properties()
     elm.extend([
         Field("name", {
             "mini": 0,
             "maxi": 1
         }, primitives.StringField, None),
         # Name of a individual to contact.
         Field(
             "telecom",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.ContactPointField(),
             None,
         )
         # Contact details for individual or publisher.
     ])
     return elm
示例#5
0
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)
示例#6
0
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
示例#7
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>"
示例#8
0
 def element_properties(self):
     elm = super().element_properties()
     elm.extend([
         Field(
             "organization",
             {
                 "mini": 0,
                 "maxi": 1
             },
             complex.ReferenceField(),
             "Organization",
         ),
         # Organization where the roles are performed.
         Field("role", {
             "mini": 0,
             "maxi": 1
         }, complex.CodeableConceptField(), None),
         # Roles which this practitioner may perform.
         Field(
             "specialty",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.CodeableConceptField(),
             None,
         ),
         # Specific specialty of the practitioner.
         Field(
             "identifier",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.IdentifierField(),
             None,
         ),
         # Business Identifiers that are specific to a role / location
         Field(
             "telecom",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.ContactPointField(),
             None,
         ),
         # Contact details that are specific to the role/location/service
         Field("period", {
             "mini": 0,
             "maxi": 1
         }, complex.PeriodField(), None),
         # The period during which the practitioner is authorized
         # to perform in these role(s).
         Field(
             "location",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.ReferenceField(),
             "Location",
         ),
         # The location(s) at which this practitioner provides care.
         Field(
             "healthcareService",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.ReferenceField(),
             "HealthcareService",
         )
         # The list of healthcare services that this worker
         # provides for this role's Organization/Location(s).
     ])
     return elm
示例#9
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
示例#10
0
class HealthcareService(DomainResource):
    """ The details of a healthcare service available at a location.
    """

    active = Column(primitives.BooleanField)
    # Whether this healthcareservice is in active use

    serviceName = Column(primitives.StringField)
    # Description of service as presented to a consumer while searching.

    comment = Column(primitives.StringField)
    # Additional description and/or any specific issues not covered elsewhere.

    extraDetails = Column(primitives.StringField)
    # Extra details about the service that can't be placed in the other fields.

    eligibilityNote = Column(primitives.StringField)
    # Describes the eligibility conditions for the service.

    programName = Column(Array(primitives.StringField))
    # Program Names that categorize the service.

    publicKey = Column(primitives.StringField)
    # PKI Public keys to support secure communications.

    appointmentRequired = Column(primitives.BooleanField)
    # If an appointment is required for access to this service.

    availabilityExceptions = Column(primitives.StringField)
    # Description of availability exceptions.

    identifier = Column(Array(complex.IdentifierField()))
    # External identifiers for this item.

    providedBy = Column(complex.ReferenceField())
    # Organization that provides this service.

    serviceCategory = Column(complex.CodeableConceptField())
    # Broad category of service being performed or delivered.

    serviceType = Column(Array(complex.CodeableConceptField()))
    # Specific service delivered or performed.

    specialty = Column(Array(complex.CodeableConceptField()))
    # Specialties handled by the HealthcareService

    location = Column(Array(complex.ReferenceField()))
    # Location where service may be provided.

    photo = Column(complex.AttachmentField())
    # Facilitates quick identification of the service.

    telecom = Column(Array(complex.ContactPointField()))
    # Contacts related to the healthcare service.

    coverageArea = Column(Array(complex.ReferenceField()))
    # Location(s) service is inteded for/available to.

    serviceProvisionCode = Column(Array(complex.CodeableConceptField()))
    # Conditions under which service is available/offered.

    eligibility = Column(complex.CodeableConceptField())
    # Specific eligibility requirements required to use the service.

    characteristic = Column(Array(complex.CodeableConceptField()))
    # Collection of characteristics (attributes).

    referralMethod = Column(Array(complex.CodeableConceptField()))
    # Ways that the service accepts referrals.

    notAvailable = Column(Array(HealthcareServiceNotAvailableField()))
    # Not available during this time due to provided reason.

    availableTime = Column(Array(HealthcareServiceAvailableTimeField()))
    # Times the Service Site is available.

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

        return {
            "providedBy": "Organization",
            "location": "Location",
            "coverageArea": "Location",
        }

    @validates("serviceCategory")
    def validate_service_category(self, key, serviceCategory):
        msg = "service category code"
        self.code_fields_validator(serviceCategory, SERVICE_CATEGORY_URL, msg)

        return serviceCategory

    @validates("serviceType")
    def validate_service_type(self, key, serviceType):
        msg = "service type code"
        self.code_fields_validator(serviceType, SERVICE_TYPE_URL, msg)

        return serviceType

    @validates("speciality")
    def validate_speciality(self, key, speciality):
        msg = "service speciality code"
        self.code_fields_validator(speciality, C80_PRACTICE_CODES_URL, msg)

        return speciality

    @validates("serviceProvisionCode")
    def validate_service_provision_code(self, key, serviceProvisionCode):
        msg = "service provision code code"
        self.code_fields_validator(serviceProvisionCode,
                                   SERVICE_PROVISION_CONDITIONS_URL, msg)

        return serviceProvisionCode

    @validates("referralMethod")
    def validate_referral_method(self, key, referralMethod):
        msg = "service referral Method code"
        self.code_fields_validator(referralMethod, REFERRAL_METHOD_URL, msg)

        return referralMethod

    @validates("availableTime")
    def validate_available_time(self, key, availableTime):
        for data in availableTime:
            daysOfWeek = data.get("daysOfWeek")

            for code in daysOfWeek:
                url = DAYS_OF_WEEK + "?code=" + code
                self.validate_valuesets(code, url, "service available Time")

        return availableTime

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

    def __repr__(self):
        return "<HealthcareService %r>" % self.serviceName