nazrulworld / fhir.resources

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

treating empty lists ('[]') as None #73

Closed Healthedata1 closed 3 years ago

Healthedata1 commented 3 years ago

Description

I am creating a FHIR object using the models and a spreadsheet as a source When there is repeating element and their is no data in the source, my code creates an empty list. This empty list is preserved unlike when the element is None. I think when an element is evaluated to these Falsy types listed below I think it should behave the same ... namely the element value should be None. Note that in FHIR "when present, elements cannot be empty - they SHALL have a value attribute, child elements, or extensions".

  1. None
  2. [] - an empty list
  3. {} - an empty dict
  4. () - an empty tuple
  5. '' - an empty str
  6. b'' - an empty bytes
  7. set() - an empty set.

What I Did

cs = construct_fhir_element('CapabilityStatement',dict(
id = meta.id,
url = f'{canon}CapabilityStatement/{meta.id}',
version = meta.version,
# more elements
instantiates = [i for i in meta.instantiates.split(',') if i],  #<<<< this evaluates to '[]'  instead of None 
))

Note that I can code around this but I think this should be the default behavior of the classes as a convienence.

Healthedata1 commented 3 years ago

never mind :-)

vadi2 commented 6 months ago

What solution did you end up going with? Not creating the list to begin with?