Exemplo n.º 1
0
 def element_properties(self):
     elm = super().element_properties()
     elm.extend([
         Field("description", {
             "mini": 0,
             "maxi": 1
         }, primitives.StringField, None),
         # Human explanation of the value set.
         Field("strength", {
             "mini": 1,
             "maxi": 1
         }, primitives.CodeField, None),
         # required | extensible | preferred | example.
         Field(
             "valueSetReference",
             {
                 "mini": 0,
                 "maxi": 1
             },
             complex.ReferenceField(),
             "Valuesets",
         ),
         # Source of value set.
         Field("valueSetUri", {
             "mini": 0,
             "maxi": 1
         }, primitives.URIField, None),
         # Source of value set.
     ])
     return elm
Exemplo n.º 2
0
 def element_properties(self):
     elm = super().element_properties()
     elm.extend([
         Field(
             "identifier",
             {
                 "mini": 0,
                 "maxi": -1
             },
             complex.IdentifierField(),
             None,
         ),
         # An identifier for this qualification for the practitioner.
         Field("code", {
             "mini": 1,
             "maxi": 1
         }, complex.CodeableConceptField(), None),
         # Coded representation of the qualification.
         Field("period", {
             "mini": 0,
             "maxi": 1
         }, complex.PeriodField(), None),
         # Period during which the qualification is valid.
         Field(
             "issuer",
             {
                 "mini": 0,
                 "maxi": 1
             },
             complex.ReferenceField(),
             "Organization",
         )
         # Organization that regulates and issues the qualification.
     ])
     return elm
Exemplo n.º 3
0
 def element_properties(self):
     elm = super().element_properties()
     elm.extend(
         [
             Field("etag", {"mini": 0, "maxi": 1}, primitives.StringField, None),
             # The etag for the resource (if relevant).
             Field(
                 "lastModified",
                 {"mini": 0, "maxi": 1},
                 primitives.InstantField,
                 None,
             ),
             # Server's date time modified.
             Field("location", {"mini": 0, "maxi": 1}, primitives.URIField, None),
             # """ The location, if the operation returns a location.
             Field("status", {"mini": 1, "maxi": 1}, primitives.CodeField, None),
             # Status return code for entry.
             Field(
                 "outcome",
                 {"mini": 1, "maxi": 1},
                 complex.ReferenceField(),
                 ["OperationOutcome"],
             ),
         ]
     )
     return elm
Exemplo n.º 4
0
 def element_properties(self):
     elm = super().element_properties()
     elm.extend(
         [
             Field("fullUrl", {"mini": 0, "maxi": 1}, primitives.URIField, None),
             # Absolute URL for resource (server address, or UUID/OID).
             Field("link", {"mini": 0, "maxi": -1}, BundleLinkField(), None),
             # Links related to this entry.
             Field(
                 "request", {"mini": 0, "maxi": 1}, BundleEntryRequestField(), None
             ),
             # Transaction Related Information.
             Field(
                 "response", {"mini": 0, "maxi": 1}, BundleEntryResponseField(), None
             ),
             # Transaction Related Information.
             Field("search", {"mini": 0, "maxi": 1}, BundleEntrySearchField(), None),
             # Search related information.
             Field(
                 "resource", {"mini": 0, "maxi": 1}, complex.ReferenceField(), "all"
             ),
             # A resource in the bundle.
             # TODO is this the best approach for this field?
             # It is a Resource field in the spec, but here we save the
             # reference and use reference resolution when accessing a Bundle.
         ]
     )
     return elm
Exemplo n.º 5
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
Exemplo n.º 6
0
 def element_properties(self):
     elm = super().element_properties()
     elm.extend([
         Field("other", {
             "mini": 1,
             "maxi": 1
         }, complex.ReferenceField(), "Patient"),
         # The other patient resource that the link refers to
         Field("type", {
             "mini": 1,
             "maxi": 1
         }, primitives.CodeField, None),
         # replace | refer | seealso - type of link
     ])
     return elm
Exemplo n.º 7
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)
Exemplo n.º 8
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
Exemplo n.º 9
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>"
Exemplo n.º 10
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
Exemplo n.º 11
0
 def element_properties(self):
     elm = super().element_properties()
     elm.extend([
         Field("linkId", {
             "mini": 0,
             "maxi": 1
         }, primitives.StringField, None),
         # To link questionnaire with questionnaire response
         Field("concept", {
             "mini": 0,
             "maxi": -1
         }, complex.CodingField(), None),
         # Concept that represents this item within in a questionnaire
         Field("prefix", {
             "mini": 0,
             "maxi": 1
         }, primitives.StringField, None),
         # E.g. "1(a)", "2.5.3"
         Field("text", {
             "mini": 0,
             "maxi": 1
         }, primitives.StringField, None),
         # Primary text for the item
         Field("type", {
             "mini": 1,
             "maxi": 1
         }, primitives.StringField, None),
         # group | display | boolean | decimal | integer | date | dateTime
         Field("required", {
             "mini": 0,
             "maxi": 1
         }, primitives.StringField, None),
         # Whether the item must be included in data results
         Field("repeats", {
             "mini": 0,
             "maxi": 1
         }, primitives.StringField, None),
         # Whether the item may repeat
         Field("readOnly", {
             "mini": 0,
             "maxi": 1
         }, primitives.StringField, None),
         # Don't allow human editing
         Field("maxLength", {
             "mini": 0,
             "maxi": 1
         }, primitives.IntegerField, None),
         # No more than this many characters
         Field(
             "options",
             {
                 "mini": 0,
                 "maxi": 1
             },
             complex.ReferenceField(),
             ["ValueSet"],
         ),
         # Valueset containing permitted answers
         Field(
             "enableWhen",
             {
                 "mini": 0,
                 "maxi": -1
             },
             QuestionnaireItemEnableWhenField(),
             None,
         ),
         # Value question must have
         Field(
             "option",
             {
                 "mini": 0,
                 "maxi": -1
             },
             QuestionnaireItemOptionField(),
             None,
         ),
         # Permitted answer
         Field("initial", {
             "mini": 0,
             "maxi": 1
         }, OpenType(), None),
         # Initial presumed answer for question
         Field("item", {
             "mini": 0,
             "maxi": -1
         }, complex.ReferenceField, ["Self"]),
         # Permitted answers
     ])
     return elm
Exemplo n.º 12
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