Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitive extensions #5

Open
niquola opened this issue Jun 16, 2017 · 2 comments
Open

Primitive extensions #5

niquola opened this issue Jun 16, 2017 · 2 comments

Comments

@niquola
Copy link
Member

niquola commented Jun 16, 2017

Problem

In FHIR you could extend primitive types with additional attributes.
This encoded in JSON with "_" prefix and has similar to variable type elements problems
with collections, schema, databases etc:

{ 
  value: 42'
  _value { extension: [....]}
}

Solution 1

We could apply the json-ld approach and encode primitives with objects:

{ 
  value: {
    @type: "Number",
    number: 42,
    extension: [...]
  }
}

Additionally, we fix weak typed JSON by embedding type labels into object

We pay by deeper paths and some size of Resource (because of additional $type labels):

obj.value vs obj.value.number 

{
  resourceType: "Patient",
  id: "example",
  identifier: [ ... ],
  active: { 
     @type: "boolean"
     boolean: true
  },
  gender: { 
     @type: "code"
     code: "male"
  },
  birthDate: {
    @type: "date",
    date: "1974-12-25",
    extension": [
      {
        "url": "http://hl7.org/fhir/StructureDefinition/patient-birthTime",
        "valueDateTime": "1974-12-25T14:35:45-05:00"
      }
    ]
  }
  deceased: {
    @type: 'boolean',
    boolean: false
  },
  managingOrganization: {
    "reference": "Organization/1"
  }
}

But we simplify typed parsing of JSON because of type information is in the document
and does not require lookup in meta-data.
We also allow collections of extended primitives.

We could go farther and add $type annotation attribute to other elements
(i.e. complex elements or datatypes):

  managingOrganization: {
    "reference": "Organization/1"
  }

  managingOrganization: {
    @type: "Reference",
    "reference": "Organization/1"
  }

@niquola
Copy link
Member Author

niquola commented Jun 8, 2018

Here is new option for primitives:

// in simple case

{"attribute": "primitiveValue"}

// in case with extensions

{"attribute": {"value": ...., "extensions": .....}}
// or
{"attribute": {"<type>": ...., "extensions": .....}}
{"attribute": {"string": ...., "extensions": .....}}

@niquola
Copy link
Member Author

niquola commented Jun 8, 2018

so all of your lookups should be like resource.attr.value OR resource.attr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant