smart-on-fhir / client-py

Python SMART on FHIR client
http://docs.smarthealthit.org
Other
574 stars 209 forks source link

What if elementProperties returns dictionary but not list? #137

Open tmitanitky opened 1 year ago

tmitanitky commented 1 year ago

Hi,

Is there any reason that fhirclient.models.fhirabstractbase.FHIRAbstractBase.elementProperties() returns list but not dictionary? As the order of elements has no special meaning in FHIR, there seems to be no necessity to use list and there are some advantages for `using ``dictionary```.

If it returns dictionary, we can easily access information of an specific element of a resource:

from  fhirclient.models.organization import Organization
organization = Organization()
organization.elementProperties()['identifier']
-> ('identifier', 'identifier', fhirclient.models.identifier.Identifier, True, None, False)

(As it could be a breaking change, new function such as *.elementPropertiesDictionary() might be preferred.)

How do you think about this??

Thanks.

p2-apple commented 1 year ago

The list preserves the order of the properties as they are in the spec IIRC.

tmitanitky commented 1 year ago

Thanks.

FHIR JSON representation saids

Properties can appear in any order.

FHIR XML representations saids

Elements must always appear in the order documented.

They are not consistent. I propose to keep an .elementProperty method that returns an ordered list and to add a method called .elementPropertyDict that returns an unordered dictionary.

I believe the method has advantage for easy access to an specific element of a resource without knowing the order of elements.