Skip to content

Commit

Permalink
Merge pull request #96 from mechanik-daniel/improve-translate-coding
Browse files Browse the repository at this point in the history
fix: include display in translateCoding
  • Loading branch information
mechanik-daniel authored Jul 17, 2024
2 parents b203cef + 35c5937 commit 2a1bd91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/helpers/fhirFunctions/translateCoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
* Project name: FUME-COMMUNITY
*/
import { getCache } from '../cache';
import { getTable } from '../conformance';
import expressions from '../jsonataExpression';
import { getLogger } from '../logger';

export const translateCoding = async (input, tableId) => {
// fork: os
export const translateCoding = async (input: string, tableId: string) => {
const { tables } = getCache();
try {
const map = tables.get(tableId);
let map = tables.get(tableId);
if (map === undefined) {
getLogger().info(`Table ${tableId} not cached, trying to fetch from server...`);
const table = await getTable(tableId);
if (table) {
map = table[tableId];
tables.set(tableId, map);
}
};

const mapFiltered = map[input];
let result;

Expand Down
19 changes: 8 additions & 11 deletions src/helpers/jsonataExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ export interface InternalJsonataExpression {

const expressions: InternalJsonataExpression = {
translateCodeExtract: jsonata('$mapFiltered.code'),
translateCodingExtract: jsonata(`$result.[
{
translateCodingExtract: jsonata(`
$result.{
'system': target,
'code': code
},
{
'system': source,
'code': $input
}
]`),
'code': code,
'display': display
}`),
searchSingle: jsonata(`(
$assert(
$bundle.total <= 1,
Expand Down Expand Up @@ -261,7 +257,8 @@ const expressions: InternalJsonataExpression = {
].code.{
"code": $,
"source": %.%.%.source,
"target": %.%.%.target
"target": %.%.%.target,
"display": %.display
}[]
}
)
Expand Down Expand Up @@ -614,7 +611,7 @@ const expressions: InternalJsonataExpression = {
)
)`),
testCodeableAgainstVS: jsonata(`(
$codings := $codeable.coding;
$codings := $codeable.$sift(function($v, $k){$substring($k,0,6) = 'coding'}).*;
$codings.$testCodingAgainstVS($, $vs);
)`)
};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/runtime/castToFhir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export const castToFhir = async (options: CastToFhirOptions, input: any) => {

if (options.vsDictionary && options.baseType === 'CodeableConcept') {
// required bindings on CodeableConcept
if (resObj?.coding) {
if (Object.keys(resObj).filter((k: string) => k.startsWith('coding')).length > 0) {
const vsTest = await expressions.testCodeableAgainstVS.evaluate({}, { codeable: resObj, vs: options.vsDictionary, testCodingAgainstVS });
if (!vsTest) {
return thrower.throwRuntimeError(`Element ${options?.path} is invalid since none of the codings provided are in the required value set`);
Expand Down

0 comments on commit 2a1bd91

Please sign in to comment.