Exemple #1
0
    def validate_fhir_duration(self):
        self.validate_fhir_quantity()
        if self.values.code:
            url = UNITS_OF_TIME_URL + "?code=" + self.values.code
            validate_valuesets(self.values.code, url, "duration units")

        return self.values
Exemple #2
0
 def validate_fhir_organizationcontact(self):
     if self.values.purpose:
         codings = self.values.purpose.coding
         for coding in codings:
             url = CONTACT_ENTITY_TYPE_URL + "?code=" + coding.code
             validate_valuesets(coding.code, url,
                                "organization contact type")
Exemple #3
0
    def validate_fhir_age(self):
        self.validate_fhir_quantity()
        if self.values.code:
            url = AGE_UNITS_URL + "?code=" + self.values.code
            validate_valuesets(self.values.code, url, "age units")

        return self.values
Exemple #4
0
    def validate_fhir_quantity(self):
        self.validate_fhir_simplequantity()
        if self.values.comparator:
            url = QUANTITY_COMPARATOR_URL + "?code=" + self.values.comparator
            validate_valuesets(self.values.comparator, url,
                               "quantity comparator")

        return self.values
Exemple #5
0
    def validate_fhir_narrative(self):
        url = NARRATIVE_STATUS_URL + "?code=" + self.values.status
        validate_valuesets(self.values.status, url, "narrative status")

        xhtml_validator.reset()
        xhtml_validator.feed(self.values.div)
        xhtml_validator.close()

        return self.values
Exemple #6
0
    def validate_fhir_contactpoint(self):
        if self.values.system:
            url = CONTACT_POINT_SYSTEM_URL + "?code=" + self.values.system
            validate_valuesets(self.values.system, url, "contactpoint system")

        if self.values.use:
            url = CONTACT_POINT_USE_URL + "?code=" + self.values.use
            validate_valuesets(self.values.use, url, "contactpoint use")

        return self.values
Exemple #7
0
    def validate_fhir_identifier(self):
        if self.values.type and self.values.type.coding:
            url = IDENTIFIER_TYPE_URL + "?code="
            for i, val in enumerate(self.values.type.coding):
                get_url = url + self.values.type.coding[i].code
                validate_valuesets(self.values.type.coding[i].code, get_url,
                                   "identifier type")

        if self.values.use:
            url = IDENTIFIER_USE_URL + "?code=" + self.values.use
            validate_valuesets(self.values.use, url, "identifier use")

        return self.values
Exemple #8
0
    def validate_fhir_signature(self):
        url = SIGNATURE_TYPE_URL + "?code="

        for val in self.values.type:
            get_url = url + val.code
            validate_valuesets(val.code, get_url, "signature code")

        if not (self.values.contentType in SIGNATURE_MIME_TYPES):
            raise ValueError("The signature content type should be "
                             f"one of {SIGNATURE_MIME_TYPES}")

        try:
            jwt.decode(self.values.blob, verify=False)
        except Exception:
            raise jwt.exceptions.DecodeError(
                "The blob provided is not a valid jwt encoded signature")

        return self.values
Exemple #9
0
    def validate_fhir_address(self):
        if self.values.type:
            url = ADDRESS_TYPE_URL + "?code=" + self.values.type
            validate_valuesets(self.values.type, url, "address type")

        if self.values.use:
            url = ADDRESS_USE_URL + "?code=" + self.values.use
            validate_valuesets(self.values.use, url, "address use")

        if self.values.country:
            country_code = self.values.country

            # Check that the code is a recommended ISO 3166 3letter code
            try:
                countries.get(alpha3=country_code)
            except Exception:
                msg = ("This country code is not recommended. "
                       "Please use an ISO 3166 3letter country code")
                warnings.warn(msg, UserWarning)

        return self.values
Exemple #10
0
    def validate_fhir_humanname(self):
        valid_text = []

        def check_for_white_spaces(name, value):
            if re.search(r"(\s)+", value):
                raise TypeError("%s in name must not have a whitespace" % name)

            valid_text.append(value)

        if self.values.prefix:
            for val in self.values.prefix:
                check_for_white_spaces("prefix", val)

        if self.values.family:
            for val in self.values.family:
                check_for_white_spaces("family", val)

        if self.values.given:
            for val in self.values.given:
                check_for_white_spaces("given", val)

        if self.values.suffix:
            for val in self.values.suffix:
                check_for_white_spaces("suffix", val)

        if self.values.text:
            words = self.values.text.split()
            for word in words:
                if word not in valid_text:
                    raise TypeError(
                        "text must be composed of the other name attributes")

        if self.values.use:
            url = HUMANNAME_USE_URL + "?code=" + self.values.use
            validate_valuesets(self.values.use, url, "humanname use")

        return self.values
Exemple #11
0
    def validate_fhir_timing(self):
        errors = []
        if self.values.repeat:
            if self.values.repeat.duration and not (
                    self.values.repeat.durationUnits):
                errors.append(
                    "durationUnits must be present for the duration provided")

            if self.values.repeat.periodMax:
                if not self.values.repeat.period:
                    errors.append(
                        "If there is a periodMax, there must be a period")
                if self.values.repeat.periodMax < 0:
                    errors.append("periodMax SHALL be a non-negative value")

            if self.values.repeat.period:
                if not self.values.repeat.periodUnits:
                    errors.append(
                        "periodUnits must be present for the period provided")
                if self.values.repeat.period < 0:
                    errors.append("period SHALL be a non-negative value")

            if self.values.repeat.frequency and self.values.repeat.when:
                errors.append("Either frequency or when can exist, not both")

            if self.values.repeat.durationMax:
                if not self.values.repeat.duration:
                    errors.append(
                        "If there is a durationMax, there must be a duration")
                if self.values.repeat.durationMax < 0:
                    errors.append("durationMax SHALL be a non-negative value")

            if self.values.repeat.duration and (self.values.repeat.duration <
                                                0):
                errors.append("duration SHALL be a non-negative value")

            if self.values.repeat.durationUnits:
                url = UNITS_OF_TIME_URL + "?code=" + (
                    self.values.repeat.durationUnits)
                validate_valuesets(self.values.repeat.durationUnits, url,
                                   "timing durationUnits")

            if self.values.repeat.periodUnits:
                url = UNITS_OF_TIME_URL + "?code=" + (
                    self.values.repeat.periodUnits)
                validate_valuesets(self.values.repeat.periodUnits, url,
                                   "timing periodUnits")

            if self.values.repeat.when:
                url = EVENT_TIMING_URL + "?code=" + self.values.repeat.when
                validate_valuesets(self.values.repeat.when, url, "timing when")

        if self.values.code and self.values.code.coding:
            url = TIMING_ABBREVIATION_URL + "?code="
            for i, val in enumerate(self.values.code.coding):
                get_url = url + self.values.code.coding[i].code
                validate_valuesets(self.values.code.coding[i].code, get_url,
                                   "timing code")

        if len(errors) > 0:
            raise TypeError(errors)

        return self.values