lantanagroup / FHIR.js

Node.JS library for serializing/deserializing FHIR resources between JS/JSON and XML using various node.js XML libraries
Apache License 2.0
102 stars 29 forks source link

Array/object in validation #40

Closed jessicamrbr closed 3 years ago

jessicamrbr commented 3 years ago

The FHIR documentation highlights Note that though a profile can constrain an element from x.. to x..1, this doesn't make any difference to the representation in the JSON format - the element will still be represented in an array. As an example, take Patient.name which has a cardinality of 0... In an unprofiled Patient, ... (https://www.hl7.org/fhir/profiling.html#cardinality)

However in the code it seems to me that the validation of multiple (Array/Object) is based on the cardinality of the profile. image

Shouldn't the definition of multiple (Array/Object) be based on ElementDefinition.base.max instead of ElementDefinition.max?And that there is a permitted quantity inside the list?

profile:

{
  "resourceType" : "StructureDefinition",
  "id" : "patient",
...
      {
        "id" : "Patient.name",
        "path" : "Patient.name",
...
        "min" : 1,
        "max" : "1",
        "base" : {
          "path" : "Patient.name",
          "min" : 0,
          "max" : "*"
        },
...

You should consider it correct:

{
  "resourceType" : "Patient",
...
    "name" : [{
       "text" : "Peter James"
    }]
...
}
seanmcilvenna commented 3 years ago

Applied changes to consider base element definition's max cardinality before the profile's max cardinality