ac-fhir-models
Advanced tools
Comparing version 7.4.0 to 7.5.0
31
index.js
@@ -508,2 +508,5 @@ 'use strict'; | ||
/** | ||
* A tag that only supports a single value for a given coding system, but | ||
* maintains other tags | ||
* | ||
* @param {string} path | ||
@@ -513,2 +516,23 @@ * @param {string} codingSystem | ||
*/ | ||
const getSingularTagProp = (path, codingSystem) => ({ | ||
get: obj => { | ||
const tag = dlv__default['default'](obj, path, []).find(item => item.system === codingSystem); | ||
if (!tag || !tag.code) return null | ||
return tag.code | ||
}, | ||
set: (obj, newValue, definition) => { | ||
const currentTags = dlv__default['default'](obj, path, []); | ||
const newTags = currentTags.filter(item => item.system !== codingSystem); | ||
if (newValue) { | ||
newTags.push({ code: newValue, system: codingSystem }); | ||
} | ||
return definition.setValue(obj, path, newTags.length ? newTags : null) | ||
}, | ||
}); | ||
/** | ||
* @param {string} path | ||
* @param {string} codingSystem | ||
* @returns {GetterSetter} | ||
*/ | ||
const getTagsProp = (path, codingSystem) => ({ | ||
@@ -1284,2 +1308,6 @@ get: obj => | ||
tasks: getTasksProp(), | ||
arStatus: getSingularTagProp( | ||
'meta.tag', | ||
'https://ns.anesthesiacharting.com/ar-status' | ||
), | ||
}, | ||
@@ -1303,2 +1331,5 @@ definition: sinks.buildDefinition( | ||
'meta.versionId': 'str', | ||
'meta.tag': 'arr', | ||
'meta.tag.[].system': 'str', | ||
'meta.tag.[].code': 'str', | ||
'supportingInformation.[].reference': 'str', | ||
@@ -1305,0 +1336,0 @@ 'supportingInformation.[].type': 'str', |
{ | ||
"name": "ac-fhir-models", | ||
"version": "7.4.0", | ||
"version": "7.5.0", | ||
"author": "Henrik Joreteg <henrik@anesthesiacharting.com>", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -217,2 +217,5 @@ // @ts-check | ||
/** | ||
* A tag that only supports a single value for a given coding system, but | ||
* maintains other tags | ||
* | ||
* @param {string} path | ||
@@ -222,2 +225,23 @@ * @param {string} codingSystem | ||
*/ | ||
export const getSingularTagProp = (path, codingSystem) => ({ | ||
get: obj => { | ||
const tag = dlv(obj, path, []).find(item => item.system === codingSystem) | ||
if (!tag || !tag.code) return null | ||
return tag.code | ||
}, | ||
set: (obj, newValue, definition) => { | ||
const currentTags = dlv(obj, path, []) | ||
const newTags = currentTags.filter(item => item.system !== codingSystem) | ||
if (newValue) { | ||
newTags.push({ code: newValue, system: codingSystem }) | ||
} | ||
return definition.setValue(obj, path, newTags.length ? newTags : null) | ||
}, | ||
}) | ||
/** | ||
* @param {string} path | ||
* @param {string} codingSystem | ||
* @returns {GetterSetter} | ||
*/ | ||
export const getTagsProp = (path, codingSystem) => ({ | ||
@@ -224,0 +248,0 @@ get: obj => |
@@ -14,2 +14,3 @@ // @ts-check | ||
getExtIdsProp, | ||
getSingularTagProp, | ||
} from '../helpers/prop-definitions.js' | ||
@@ -85,2 +86,6 @@ | ||
tasks: getTasksProp(), | ||
arStatus: getSingularTagProp( | ||
'meta.tag', | ||
'https://ns.anesthesiacharting.com/ar-status' | ||
), | ||
}, | ||
@@ -104,2 +109,5 @@ definition: buildDefinition( | ||
'meta.versionId': 'str', | ||
'meta.tag': 'arr', | ||
'meta.tag.[].system': 'str', | ||
'meta.tag.[].code': 'str', | ||
'supportingInformation.[].reference': 'str', | ||
@@ -106,0 +114,0 @@ 'supportingInformation.[].type': 'str', |
@@ -5,2 +5,103 @@ // @ts-check | ||
test('appointmentDefinition arStatus', t => { | ||
const resource = appointmentDefinition.create({ | ||
arStatus: 'signed', | ||
}) | ||
t.deepEqual(resource, { | ||
resourceType: 'Appointment', | ||
meta: { | ||
tag: [ | ||
{ | ||
system: 'https://ns.anesthesiacharting.com/ar-status', | ||
code: 'signed', | ||
}, | ||
], | ||
}, | ||
}) | ||
const values = appointmentDefinition.getValues(resource) | ||
t.equal(values.arStatus, 'signed') | ||
const updatedResource = appointmentDefinition.set(resource, { | ||
arStatus: 'started', | ||
}) | ||
t.deepEqual(updatedResource, { | ||
resourceType: 'Appointment', | ||
meta: { | ||
tag: [ | ||
{ | ||
system: 'https://ns.anesthesiacharting.com/ar-status', | ||
code: 'started', | ||
}, | ||
], | ||
}, | ||
}) | ||
const updatedValues = appointmentDefinition.getValues(updatedResource) | ||
t.equal(updatedValues.arStatus, 'started') | ||
const updatedResource2 = appointmentDefinition.set(updatedResource, { | ||
arStatus: null, | ||
}) | ||
t.deepEqual(updatedResource2, { | ||
resourceType: 'Appointment', | ||
}) | ||
const updatedValues2 = appointmentDefinition.getValues(updatedResource2) | ||
t.notOk(updatedValues2.arStatus, 'should not be set') | ||
// maintains existing tags | ||
const resourceWithExistingTags = { | ||
resourceType: 'Appointment', | ||
meta: { | ||
tag: [ | ||
{ | ||
system: 'https://acme.org', | ||
code: 'foo', | ||
}, | ||
], | ||
}, | ||
} | ||
const updatedResource3 = appointmentDefinition.set(resourceWithExistingTags, { | ||
arStatus: 'signed', | ||
}) | ||
t.deepEqual(updatedResource3, { | ||
resourceType: 'Appointment', | ||
meta: { | ||
tag: [ | ||
{ | ||
system: 'https://acme.org', | ||
code: 'foo', | ||
}, | ||
{ | ||
system: 'https://ns.anesthesiacharting.com/ar-status', | ||
code: 'signed', | ||
}, | ||
], | ||
}, | ||
}) | ||
const updatedResource4 = appointmentDefinition.set(updatedResource3, { | ||
arStatus: null, | ||
}) | ||
t.deepEqual(updatedResource4, { | ||
resourceType: 'Appointment', | ||
meta: { | ||
tag: [ | ||
{ | ||
system: 'https://acme.org', | ||
code: 'foo', | ||
}, | ||
], | ||
}, | ||
}) | ||
t.end() | ||
}) | ||
test('appointmentDefinition pdf', t => { | ||
@@ -7,0 +108,0 @@ const resource = appointmentDefinition.create({ |
187212
6506