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

Validation error with ImagingStudy resource #120

Open alessiacarotenuto opened 1 year ago

alessiacarotenuto commented 1 year ago

Validation error with ImagingStudy resource

I am trying to create an ImagingStudy resource associated with a patient (already created with fhir.resources) and then transform the resource into a JSON/XML object. I get the following error:

Traceback (most recent call last):
  File "C:\Users\\PycharmProjects\pythonProject1\Prova_json_imagingstudy.py", line 13, in <module>
    study = ImagingStudy()
  File "C:\Users\\anaconda3\envs\pythonProject1\lib\site-packages\fhir\resources\core\fhirabstractmodel.py", line 105, in __init__
    BaseModel.__init__(__pydantic_self__, **data)
  File "pydantic\main.py", line 342, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for ImagingStudy
__root__ -> status
  field required (type=value_error.missing)

My simple code is: 

### from fhir.resources.imagingstudy import ImagingStudy
from fhir.resources.coding import Coding

from Prova_json_patient import my_patient

import uuid

# Create a new study object
study = ImagingStudy()

# Set the study resource fields
study.subject = 'Patient/' + my_patient.id

study.modality = Coding()
study.modality.code = 'CT'
study.modality.system = 'https://dicom.nema.org/resources/ontology/DCM'

study.id = 'urn:oid:' + str(uuid.uuid4())
study.status = 'available'
print(study.json())

How can this be solved and why does it happen?

@nazrulworld @mmabey @chgl @simonvadee

chgl commented 1 year ago

Maybe the same issue as https://github.com/nazrulworld/fhir.resources/issues/56

Could you please try the workaround from https://github.com/nazrulworld/fhir.resources/issues/56#issuecomment-1172972519

Vamshi3130 commented 5 months ago

It's because in ImagingStudy class status field is mmarked required , Ur instantiating class without passing required field which gives this error.