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

Add targetProfiles for References #46

Closed lschmierer closed 3 years ago

lschmierer commented 3 years ago

This PR adds a _targetProfiles field to ParsedProperty.

_targetProfiles is only set if Element type == 'Reference'.

seanmcilvenna commented 3 years ago

How is _targetProperty used here??? Is it just for information purposes for users of FHIR.js? Doesn't seem that _targetProperty is used internally in any way...

lschmierer commented 3 years ago

Ah yes, I am sorry. Should haven given more context.

I needed _targetProperty for a GraphQL schema generator I am currently developing.

More precisely to add schema directives like

type AccountResource implements Resource & DomainResource {
  resourceType: String!
  ...
  subject: [Reference] @target(profiles: ["Patient", "Device", "Practitioner", "PractitionerRole", "Location", "HealthcareService", "Organization"])
  ...

I am using https://github.com/lantanagroup/FHIR.js/blob/master/profiles/types.json as base for schema generation.

The GraphQL generator will be published open source soon.

I will look into enhancing the FHIR.js validation logic https://github.com/lantanagroup/FHIR.js/blob/master/validator.ts to also use _targetProperty for validating references. This way both out projects can improve from the new addition.

seanmcilvenna commented 3 years ago

Very good. Makes sense. Would love to see a PR for validation! I've merged your PR... Do you need a new patch-release made on NPM, or are you good with just merging?

lschmierer commented 3 years ago

In many cases it is not possible to validate the reference target, without resolving the references object. Does it make sense ti implement validation for such cases where the type is explicitly defined in the reference?

https://www.hl7.org/fhir/references.html#type

seanmcilvenna commented 3 years ago

Yes. I would only worry about validating references that are relative. I would bother (right now) trying to validate a reference to an identifier, or a reference to a canonical url.