-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from beda-software/directives-support
- Loading branch information
Showing
14 changed files
with
2,502 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ExceptionFilter, Catch, ArgumentsHost, HttpStatus } from '@nestjs/common'; | ||
import { FPMLValidationError } from './utils/extract'; | ||
|
||
@Catch(FPMLValidationError) | ||
export class FPMLValidationErrorFilter implements ExceptionFilter { | ||
catch(exception: any, host: ArgumentsHost) { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse(); | ||
const request = ctx.getRequest(); | ||
|
||
response.status(HttpStatus.BAD_REQUEST).json({ | ||
statusCode: HttpStatus.BAD_REQUEST, | ||
timestamp: new Date().toISOString(), | ||
path: request.url, | ||
message: exception.message || 'Unprocessable Entity', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,47 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { resolveTemplate } from './utils/extract'; | ||
import { Resource } from 'fhir/r4b'; | ||
import { FPOptions, resolveTemplate } from './utils/extract'; | ||
import * as fhirpath from 'fhirpath'; | ||
|
||
@Injectable() | ||
export class AppService { | ||
resolveTemplate(qr: Resource, template: object): object { | ||
return resolveTemplate(qr, template); | ||
resolveTemplate( | ||
resource: Record<string, any>, | ||
template: object, | ||
context: Context, | ||
model?: Model, | ||
strict?: boolean, | ||
): object { | ||
const options: FPOptions = { | ||
userInvocationTable: { | ||
answers: { | ||
fn: (inputs, linkId: string) => { | ||
return fhirpath.evaluate( | ||
inputs, | ||
model | ||
? `repeat(item).where(linkId='${linkId}').answer.value` | ||
: `repeat(item).where(linkId='${linkId}').answer.value.children()`, | ||
null, | ||
model, | ||
null, | ||
); | ||
}, | ||
arity: { 0: [], 1: ['String'] }, | ||
}, | ||
// Get rid of toString once it's fixed https://github.com/HL7/fhirpath.js/issues/156 | ||
toString: { | ||
fn: (inputs) => fhirpath.evaluate({ x: inputs }, 'x.toString()'), | ||
arity: { 0: [] }, | ||
}, | ||
}, | ||
}; | ||
|
||
return resolveTemplate( | ||
resource, | ||
template, | ||
{ root: resource, ...context }, | ||
model, | ||
options, | ||
strict, | ||
); | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
ts/server/src/utils/__data__/complex-example.aidbox.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
body: | ||
"{% assign %}": | ||
- patientId: "{{ %Patient.id }}" | ||
- recordedDate: "{{ %QuestionnaireResponse.authored }}" | ||
- observationEntries: | ||
- "{% if answers('WEIGHT').exists() and answers('HEIGHT').exists() %}": | ||
"{% assign %}": | ||
- observationId: >- | ||
{{ | ||
%Observation.where( | ||
id in %Provenance.target.id and | ||
category.coding.code='vital-signs' and | ||
resourceType='Observation' and | ||
code.coding.code='29463-7' | ||
).id | ||
}} | ||
fullUrl: "urn:uuid:observation-weight" | ||
request: | ||
"{% if %observationId.exists() %}": | ||
url: "/Observation/{{ %observationId }}" | ||
method: PUT | ||
"{% else %}": | ||
url: "/Observation?patient={{ %patientId }}&category=vital-signs&code=http://loinc.org|29463-7" | ||
method: POST | ||
resource: | ||
resourceType: Observation | ||
id: "{{ %observationId }}" | ||
subject: | ||
resourceType: Patient | ||
id: "{{ %patientId }}" | ||
status: final | ||
effective: | ||
dateTime: "{{ %recordedDate }}" | ||
category: | ||
- coding: | ||
- system: http://terminology.hl7.org/CodeSystem/observation-category | ||
code: vital-signs | ||
code: | ||
coding: | ||
- system: "http://loinc.org" | ||
code: 29463-7 | ||
display: Body Weight | ||
value: | ||
Quantity: | ||
value: | ||
"{% assign %}": | ||
- rawHeight: "{{ answers('HEIGHT') }}" | ||
- rawWeight: "{{ answers('WEIGHT') }}" | ||
"{% if %rawHeight < 90 %}": "{{ %rawWeight / 2.205 }}" | ||
"{% else %}": "{{ %rawWeight }}" | ||
unit: kg | ||
system: "http://unitsofmeasure.org" | ||
code: kg | ||
|
||
- "{% if answers('HEIGHT').exists() %}": | ||
"{% assign %}": | ||
- observationId: >- | ||
{{ | ||
%Observation.where( | ||
id in %Provenance.target.id and | ||
category.coding.code='vital-signs' and | ||
resourceType='Observation' and | ||
code.coding.code='29463-7' | ||
).id | ||
}} | ||
fullUrl: "urn:uuid:observation-height" | ||
request: | ||
"{% if %observationId.exists() %}": | ||
url: "/Observation/{{ %observationId }}" | ||
method: PUT | ||
"{% else %}": | ||
url: "/Observation?patient={{ %patientId }}&category=vital-signs&code=http://loinc.org|8302-2" | ||
method: POST | ||
resource: | ||
resourceType: Observation | ||
id: "{{ %observationId }}" | ||
subject: | ||
resourceType: Patient | ||
id: "{{ %patientId }}" | ||
status: final | ||
effective: | ||
dateTime: "{{ %recordedDate }}" | ||
category: | ||
- coding: | ||
- system: http://terminology.hl7.org/CodeSystem/observation-category | ||
code: vital-signs | ||
code: | ||
coding: | ||
- system: "http://loinc.org" | ||
code: 8302-2 | ||
display: Body Height | ||
value: | ||
Quantity: | ||
value: | ||
"{% assign %}": | ||
- rawHeight: "{{ answers('HEIGHT') }}" | ||
# 90 inch ~ 230cm | ||
"{% if %rawHeight < 90 %}": "{{ %rawHeight * 2.54 }}" # inches to cm | ||
"{% else %}": "{{ %rawHeight }}" # cm | ||
unit: kg | ||
system: "http://unitsofmeasure.org" | ||
code: kg | ||
|
||
- conditionEntries: | ||
"{% for index, coding in answers('MEDCOND1') | answers('MEDCOND2') %}": | ||
"{% assign %}": | ||
- conditionId: >- | ||
{{ | ||
%Condition.where(resourceType='Condition').where( | ||
id in %Provenance.target.id and | ||
category.coding.code='medicalHistory' | ||
and code.coding.system=%coding.system and | ||
code.coding.code=%coding.code | ||
).id | ||
}} | ||
fullUrl: "urn:uuid:condition-medical-history-{{ %index }}" | ||
request: | ||
"{% if %conditionId.exists() %}": | ||
url: "Condition/{{ %conditionId }}" | ||
method: PUT | ||
"{% else %}": | ||
url: /Condition?category=medicalHistory&code={{ %coding.system }}|{{ %coding.code }}&patient={{ %patientId }} | ||
method: POST | ||
resource: | ||
resourceType: Condition | ||
id: "{{ %conditionId }}" | ||
subject: | ||
resourceType: Patient | ||
id: "{{ %patientId }}" | ||
recordedDate: "{{ %recordedDate }}" | ||
code: | ||
coding: | ||
- "{{ %coding }}" | ||
text: "{{ %coding.display }}" | ||
category: | ||
- coding: | ||
- code: medicalHistory | ||
display: Medical history | ||
- provenanceEntries: | ||
"{% for entry in %observationEntries | %conditionEntries %}": | ||
request: | ||
url: /Provenance | ||
method: POST | ||
resource: | ||
resourceType: Provenance | ||
target: | ||
- uri: "{{ %entry.fullUrl }}" | ||
recorded: "{{ %recordedDate }}" | ||
agent: | ||
- who: | ||
resourceType: Organization | ||
id: "{{ %Organization.id }}" | ||
entity: | ||
- role: source | ||
what: | ||
resourceType: QuestionnaireResponse | ||
id: "{{ %QuestionnaireResponse.id }}" | ||
resourceType: Bundle | ||
type: transaction | ||
entry: | ||
- "{% for entry in %observationEntries | %conditionEntries | %provenanceEntries %}": "{{ %entry }}" | ||
- "{% assign %}": | ||
- resourceIdsToDelete: | ||
"{% for id in %Provenance.target.id.exclude((%observationEntries | %conditionEntries).resource.id) %}": "{{ %id }}" | ||
"{% for provenance in %Provenance.where(target.id in %resourceIdsToDelete) %}": | ||
- request: | ||
url: "/Provenance/{{ %provenance.id }}" | ||
method: DELETE | ||
- request: | ||
url: "/{{ %provenance.target.resourceType }}/{{ %provenance.target.id }}" | ||
method: DELETE |
Oops, something went wrong.