ac-fhir-models
Advanced tools
Comparing version 7.6.1 to 7.6.2
{ | ||
"name": "ac-fhir-models", | ||
"version": "7.6.1", | ||
"version": "7.6.2", | ||
"author": "Henrik Joreteg <henrik@anesthesiacharting.com>", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -529,10 +529,18 @@ // @ts-check | ||
* options: {} | ||
* single?: boolean | ||
* }} opts | ||
* @returns {GetterSetter} | ||
*/ | ||
export const getCodeableConceptProp = ({ propName, codingSystem, options }) => { | ||
export const getCodeableConceptProp = ({ | ||
propName, | ||
codingSystem, | ||
options, | ||
single = false, | ||
}) => { | ||
const predicate = item => dlv(item, 'coding.0.system') === codingSystem | ||
return { | ||
get: data => { | ||
const found = (data[propName] || []).find(predicate) | ||
const found = single | ||
? data[propName] | ||
: (data[propName] || []).find(predicate) | ||
const coding = found && found.coding && found.coding[0] | ||
@@ -549,18 +557,23 @@ if (!coding) { | ||
} | ||
const array = data[propName] || [] | ||
const length = (array && array.length) || 0 | ||
const foundIndex = length && array.findIndex(predicate) | ||
const index = foundIndex !== -1 ? foundIndex : length | ||
if (value) { | ||
return setValue(data, `${propName}.[${index}]`, { | ||
coding: [ | ||
{ | ||
system: codingSystem, | ||
code: value, | ||
display, | ||
}, | ||
], | ||
}) | ||
const newCoding = value | ||
? { | ||
coding: [ | ||
{ | ||
system: codingSystem, | ||
code: value, | ||
display, | ||
}, | ||
], | ||
} | ||
: null | ||
if (single) { | ||
return setValue(data, propName, newCoding) | ||
} else { | ||
return setValue(data, `${propName}.[${index}]`, null) | ||
const array = data[propName] || [] | ||
const length = (array && array.length) || 0 | ||
const foundIndex = length && array.findIndex(predicate) | ||
const index = foundIndex !== -1 ? foundIndex : length | ||
return setValue(data, `${propName}.[${index}]`, newCoding) | ||
} | ||
@@ -567,0 +580,0 @@ }, |
@@ -6,3 +6,5 @@ // @ts-check | ||
import { | ||
getCodeableConceptProp, | ||
getDirectReferenceProp, | ||
getReferenceProp, | ||
getTimeProp, | ||
@@ -105,2 +107,12 @@ } from '../helpers/prop-definitions' | ||
text: 'payload.[0].contentString', | ||
editStatus: getCodeableConceptProp({ | ||
propName: 'statusReason', | ||
codingSystem: 'https://ns.anesthesiacharting.com/comment-status', | ||
options: { | ||
deleted: 'deleted', | ||
edited: 'edited', | ||
}, | ||
single: true, | ||
}), | ||
appointmentId: getReferenceProp('about', 'Appointment'), | ||
}, | ||
@@ -125,2 +137,5 @@ definition: buildDefinition( | ||
'category.[].coding.[].display': 'str', | ||
'statusReason.coding.[].system': 'str', | ||
'statusReason.coding.[].code': 'str', | ||
'statusReason.coding.[].display': 'str', | ||
}, | ||
@@ -127,0 +142,0 @@ fhirFieldTypes |
@@ -88,2 +88,3 @@ // @ts-check | ||
text: 'Hello', | ||
appointmentId: 'abc', | ||
} | ||
@@ -109,2 +110,3 @@ | ||
], | ||
about: [{ reference: 'Appointment/abc' }], | ||
status: 'completed', | ||
@@ -117,1 +119,28 @@ }) | ||
}) | ||
test('patientCommentDefinition with editStatus', t => { | ||
const dateTime = new Date().toISOString() | ||
const startProps = { | ||
patientId: '123', | ||
author: { type: 'Practitioner', id: '456' }, | ||
date: dateTime, | ||
text: 'Hello', | ||
editStatus: 'edited', | ||
} | ||
const resource = patientCommentDefinition.create(startProps) | ||
t.deepEqual(resource.statusReason, { | ||
coding: [ | ||
{ | ||
system: 'https://ns.anesthesiacharting.com/comment-status', | ||
code: 'edited', | ||
display: 'edited', | ||
}, | ||
], | ||
}) | ||
t.deepEqual(patientCommentDefinition.getValues(resource).editStatus, 'edited') | ||
t.end() | ||
}) |
Sorry, the diff of this file is too big to display
199331
6946