nazrulworld / fhir.resources

FHIR Resources https://www.hl7.org/fhir/resourcelist.html
https://pypi.org/project/fhir.resources/
Other
365 stars 104 forks source link

ElementDefinition.id typing is incorrect #101

Closed Healthedata1 closed 2 years ago

Healthedata1 commented 2 years ago

Description

The StructureDefinition model generates validation errors for the element.id elements due to the regex defined in the model. The regex is based on the FHIR id datatype. However, the element.id element is a string datatype and should not use the id datatype regex.

See the element definition here http://hl7.org/fhir/element.html#Element, and Element.id definition here : http://hl7.org/fhir/elementdefinition.html#id

What I Did

from fhir.resources.structuredefinition import StructureDefinition
for i in us_core_files:
    #print(i.name)
    constraints = {}
    #sd_dict = loads(i.read_text())
    sd = StructureDefinition.parse_file(i)

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Input In [30], in <cell line: 2>()
      4 constraints = {}
      5 #sd_dict = loads(i.read_text())
----> 6 sd = StructureDefinition.parse_file(i)
      7 #print(sd_dict['type'])
      9 if sd.type =="Observation":

File ~/.pyenv/versions/3.10.2/envs/jupyter/lib/python3.10/site-packages/fhir/resources/fhirabstractmodel.py:243, in FHIRAbstractModel.parse_file(cls, path, content_type, encoding, proto, allow_pickle, **extra)
    233 extra.update({"cls": cls})
    234 obj = load_file(
    235     path,
    236     proto=proto,
   (...)
    241     **extra,
    242 )
--> 243 return cls.parse_obj(obj)

File ~/.pyenv/versions/3.10.2/envs/jupyter/lib/python3.10/site-packages/pydantic/main.py:511, in pydantic.main.BaseModel.parse_obj()

File ~/.pyenv/versions/3.10.2/envs/jupyter/lib/python3.10/site-packages/fhir/resources/fhirabstractmodel.py:105, in FHIRAbstractModel.__init__(__pydantic_self__, **data)
    102 if errors:
    103     raise ValidationError(errors, __pydantic_self__.__class__)
--> 105 BaseModel.__init__(__pydantic_self__, **data)

File ~/.pyenv/versions/3.10.2/envs/jupyter/lib/python3.10/site-packages/pydantic/main.py:331, in pydantic.main.BaseModel.__init__()

ValidationError: 23 validation errors for StructureDefinition
snapshot -> element -> 14 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 15 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 16 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 17 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 18 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 19 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 20 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 21 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 22 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 23 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 24 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 25 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 30 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 33 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 34 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 35 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 36 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 37 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 38 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 39 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 40 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 41 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
snapshot -> element -> 66 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)