-
Notifications
You must be signed in to change notification settings - Fork 118
Closed
Description
- fhir.resources version: 6.0.0b4.dev0
- Python version: 3.8
- Operating System: macOS
Description
I want FHIRAbstractModel
to be able to validate enum values. I think it's already supported by the current version but I couldn't find how to do it.
class Patient(domainresource.DomainResource):
...
gender: fhirtypes.Code = Field(
None,
alias="gender",
title="male | female | other | unknown",
description=(
"Administrative Gender - the gender that the patient is considered to "
"have for administration and record keeping purposes."
),
# if property is element of this resource.
element_property=True,
# note: Enum values can be used in validation,
# but use in your own responsibilities, read official FHIR documentation.
enum_values=["male", "female", "other", "unknown"],
)
I don't quite understand what this means:
note: Enum values can be used in validation, but use in your own responsibilities, read official FHIR documentation.
because the pydantic model does not enforce the value of this field.
What I Did
from fhir.resources import construct_fhir_element
resource = {"resourceType": "Patient", "gender": "toto"}
construct_fhir_element(resource["resourceType"], resource)
# everything went fine, but it should raise a validation error
Metadata
Metadata
Assignees
Labels
No labels