skalarsystems / fhirzeug

A Python FHIR specification parser and class generator
Apache License 2.0
17 stars 1 forks source link

Add custom validator for Reference Element #60

Closed Wauplin closed 3 years ago

Wauplin commented 4 years ago

Context:

Reference element has a reference attribute of type string. It is currently validated by pydantic_fhir as a string. The idea is to add a custom validator to also validate the consistency of the URL.

From https://www.hl7.org/fhir/references-definitions.html#Reference.reference :

Reference.reference : A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources.

Using absolute URLs provides a stable scalable approach suitable for a cloud/web context, while using relative/logical references provides a flexible approach suitable for use when trading across closed eco-system boundaries. Absolute URLs do not need to point to a FHIR RESTful server, though this is the preferred approach. If the URL conforms to the structure "/[type]/[id]" then it should be assumed that the reference is to a FHIR RESTful server.

Also, from https://www.hl7.org/fhir/references-definitions.html#Reference.type:

Reference.type : The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.

According to this, two conditions must be validated:

Additional material: