FHIR Chat · Singular field naming · implementers

Stream: implementers

Topic: Singular field naming


view this post on Zulip Jack Burnett (May 17 2021 at 14:36):

Just asking this out of interest more than anything else, but was wondering why field names on resources are always singular, rather than being plural for * cardinality elements?
https://confluence.hl7.org/display/FHIR/Guide+to+Designing+Resources#GuidetoDesigningResources-NamingRules&Guidelines
is the only relevant documentation on naming I'm aware of, and states this, but doesn't justify it.
The only rationale given is:
' Purpose is to give maximum insight for the unfamiliar developer to "what is this thing". '
Which I think this particular naming convention goes against since a few times I've seen people confused by these singular names.
Anyway, obviously not trying to convince anyone to change it haha, just curious why that decision was made in the first place?
Thanks!

view this post on Zulip Lloyd McKenzie (May 17 2021 at 18:08):

It's because in XML, the element name gets repeated for each repetition. So you'd end up with:
<Patient> <names>...</names> <names>...</names> </Patient>

view this post on Zulip Lloyd McKenzie (May 17 2021 at 18:08):

For that reason, we require that element names are always singular.

view this post on Zulip Lloyd McKenzie (May 17 2021 at 18:09):

Having
"name" : [{...}, {...}]
is still clear enough

view this post on Zulip Jack Burnett (May 18 2021 at 13:30):

Thanks for the explanation Llyod - yeah makes perfect sense when thinking about the XML structure (I only use JSON myself, so didn't occur).

RE: the JSON arrays being clear enough, I agree yeah, it was actually in the context of the proposed GraphQL spec that made me think about it, since it's definitely more common to use plural forms there.

view this post on Zulip Lloyd McKenzie (May 18 2021 at 15:44):

Hmm. Does the GraphQL spec allow aliasing of returned data? (I.e. changing the name of an element to something else) I can see that being useful, though perhaps not critical for this particular use-case.

view this post on Zulip Jack Burnett (May 19 2021 at 08:05):

Lloyd McKenzie said:

Hmm. Does the GraphQL spec allow aliasing of returned data? (I.e. changing the name of an element to something else) I can see that being useful, though perhaps not critical for this particular use-case.

Yep it does https://graphql.org/learn/queries/#aliases


Last updated: Apr 12 2022 at 19:14 UTC