Skip to content

Instantly share code, notes, and snippets.

@niquola
Last active November 27, 2019 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niquola/48d106a88dbf93eb17783c0d5c5beb36 to your computer and use it in GitHub Desktop.
Save niquola/48d106a88dbf93eb17783c0d5c5beb36 to your computer and use it in GitHub Desktop.

FHIR include & revinclude behavior is non-DRY and sometimes confusing.

This is informal proposal of alternative for (rev)include - _with parameter - simple (graphql like) DSL to describe nested includes:


Encounter?_with=patient
=> Encounter?_include=Encounter:patient

Encounter?_with=patient{Patient}
=> Encounter?_include=Encounter:patient:Patient

Encounter?_with=patient{Patient{organization}}
=> Encounter?_include=Encounter:patient:Patient&
             _include(:iterate)=Patient:organization
             
Encounter?_with=patient{Patient{organization{Organization{part-of:recur}}
=> Encounter?_include=Encounter:patient:Patient&
             _include(:iterate)=Patient:organization
             _include(:recursive)=Organization:parto-of
             
             
Patient?_with=organization,Condition.patient,MedicationStatement.patient{medication}

=> Patient?_include=Patient:organization&
           _revinclude=Condition:patient:Patient
           _revinclude=MedicationStatement:patient:Patient
           _include=MedicationStatement:medication
             
RequestGroup?_with=
 author
 patient{Patient{organization,AllergyIntolerance.patient}}
 target{
  MedicationRequest{
    medication
    intended-performer{Organization}
    requester{PractitionerRole{practitioner,location}}}}
=>
RequestGroup?_include=patient,author
    &_include:iterate=RequestGroup:target:MedicationRequest
    &_include:iterate=MedicationRequest:medication
    &_include:iterate=MedicationRequest:requester:PractitionerRole
    &_include:iterate=MedicationRequest:intended-performer:Organization
    &_include:iterate=PractitionerRole:practitioner
    &_include:iterate=Patient:organization
    &_include:iterate=PractitionerRole:location
    &_revinclude:iterate=AllergyIntolerance:patient

Formal definitoin:

expr = param-expr (space param-expr)*
param-expr = param ( '{' typed-ref-expr (space typed-ref-expr)* '}')?
typed-ref-expr = resource-type | resource-type '{' expr '}'
param = resource-type '.' param-name  | param-name
space = ',' | ' ' | '\n'
param-name = ALPAHNUM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment