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.
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.
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:
If Reference.reference field (relative or absolute URL) use the /type/id pattern and Reference.type is populated, they must match.
If Reference.reference field doesn't use the /type/id pattern then it is considered to be an absolute URL and must be validated with pydantic URL validator.
Context:
Reference
element has areference
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 :
Also, from https://www.hl7.org/fhir/references-definitions.html#Reference.type:
According to this, two conditions must be validated:
Reference.reference
field (relative or absolute URL) use the/type/id
pattern andReference.type
is populated, they must match.Reference.reference
field doesn't use the/type/id
pattern then it is considered to be an absolute URL and must be validated with pydantic URL validator.Additional material: