Skip to content

Commit

Permalink
Merge pull request #116 from mechanik-daniel/resolve-issue-114
Browse files Browse the repository at this point in the history
fix: resolve issue 114
  • Loading branch information
mechanik-daniel authored Dec 1, 2024
2 parents 4dd5aeb + d916c6c commit 2df4ee1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
71 changes: 46 additions & 25 deletions src/helpers/jsonataExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,34 +556,54 @@ const expressions: InternalJsonataExpression = {
$_isEmpty($value)
)`),
codeSystemToDictionary: jsonata('concept.**[$type($)="object"]{code:display}'),
valueSetExpandDictionary: jsonata(`(
$compose := $vs.(
$expandInclude := function($include){(
$exists(filter) ? undefined : (
$vs := $include.valueSet.$valueSetExpand($);
$concepts := $exists($include.concept) ? $include.{system: concept{code: display}} : ($exists($include.system) ? $include.{system: $codeSystemDictionary(system)});
$count($vs) > 0 ? (
$exists($include.system) ? (
$system = $include.system;
{
$system: $concepts.*.$sift(function($v,$k){(
$exists(
$vs.$lookup($system) ~> $lookup($k)
)
)})
valueSetExpandDictionary: jsonata(` (
$expandInclude := function($include){(
$exists($include.filter) ? undefined : (
$vs := $include.valueSet.$valueSetExpand($);
$concepts := (
/*if*/
$exists($include.concept)
/*then*/ ?
$include.(
$sys := system;
{
system: concept{
code: (
$exists(display) ? display : $lookup($codeSystemDictionary($sys),code)
)
}
) : (
$vs
)
) : $concepts
)
)};
}
)
/*else*/ : (
$exists($include.system)
? $include.{
system: $codeSystemDictionary($include.system)
}
));
$count($vs) > 0 ? (
$exists($include.system) ? (
$system = $include.system;
{
$system: $concepts.*.$sift(function($v,$k){(
$exists(
$vs.$lookup($system) ~> $lookup($k)
)
)})
}
) : (
$vs
)
) : $concepts
)
)};
$compose := $vs.(
$countIncludes := $count(compose.include);
$countExcludes := $count(compose.exclude);
$includes := compose.$expandInclude(include);
$excludes := compose.$expandInclude(exclude);
$includes := compose.include.$expandInclude($);
$excludes := compose.exclude.$expandInclude($);
$count($includes)=$countIncludes and $count($excludes)=$countExcludes ? (
[$includes.(
Expand All @@ -601,7 +621,8 @@ const expressions: InternalJsonataExpression = {
)]
)
);
$count($compose) > 0 ? $compose
$count($compose) > 0 ? $compose;
)`),
testCodeAgainstVS: jsonata(`(
$allCodes := $merge($vs.*);
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/jsonataFunctions/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import jsonata from 'jsonata';
import { IAppBinding } from '../../types';
import { getCache } from '../cache';
import * as conformance from '../conformance';
import { codeSystemDictionary, valueSetExpandDictionary } from '../conformance/conformance';
import fhirFuncs from '../fhirFunctions';
import { parseCsv } from '../inputConverters';
import * as v2 from '../inputConverters/hl7v2';
Expand Down Expand Up @@ -111,6 +112,8 @@ export const transform = async (input, expression: string, extraBindings: Record
if (dev) bindings.getElementDefinition = compiler.getElementDefinition;
if (dev) bindings.replaceColonsWithBrackets = compiler.replaceColonsWithBrackets;
if (dev) bindings.removeComments = removeComments;
if (dev) bindings.valueSetExpandDictionary = valueSetExpandDictionary;
if (dev) bindings.codeSystemDictionary = codeSystemDictionary;
bindings.getCodeSystem = conformance.getCodeSystem;
bindings.getValueSet = conformance.getValueSet;
// end of debug functions
Expand Down
15 changes: 15 additions & 0 deletions tests/root/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,21 @@ describe('integration tests', () => {
expect(wrong.body.message).toBe('Transformation error: value \'lalaland\' is invalid for element address.country. This code is not in the required value set');
});

test('Validate Task.intent code', async () => {
const fume = `InstanceOf: Task
* status = 'accepted'
* intent = 'plan'`;
const requestBody = { fume };

const res = await request(globalThis.app).post('/').send(requestBody);

expect(res.body).toStrictEqual({
resourceType: 'Task',
status: 'accepted',
intent: 'plan'
});
});

test('Case 2 - Slices with fixed values appear even if no children are set', async () => {
const mapping = `
InstanceOf: il-core-patient
Expand Down

0 comments on commit 2df4ee1

Please sign in to comment.