ac-fhir-models
Advanced tools
Comparing version 7.6.3 to 7.6.4
{ | ||
"name": "ac-fhir-models", | ||
"version": "7.6.3", | ||
"version": "7.6.4", | ||
"author": "Henrik Joreteg <henrik@anesthesiacharting.com>", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -6,2 +6,5 @@ // @ts-check | ||
export const DELETED_REFERENCE_URL_PREFIX = | ||
'https://ns.anesthesiacharting.com/deleted-reference/' | ||
/** | ||
@@ -296,6 +299,12 @@ * @typedef GetterSetter | ||
* @param {string} resourceType The FHIR Resource type | ||
* @param {{ deletable?: boolean }} [opts] | ||
* @returns {GetterSetter} | ||
*/ | ||
export const getReferenceProp = (propName, resourceType) => { | ||
export const getReferenceProp = ( | ||
propName, | ||
resourceType, | ||
{ deletable = false } = {} | ||
) => { | ||
const predicate = entry => entry.reference.includes(`${resourceType}/`) | ||
const deletedPrefixWithResourceType = `${DELETED_REFERENCE_URL_PREFIX}${resourceType}/` | ||
return { | ||
@@ -308,2 +317,9 @@ get: data => { | ||
} | ||
if (reference.startsWith(DELETED_REFERENCE_URL_PREFIX)) { | ||
return { | ||
deleted: reference.replace(deletedPrefixWithResourceType, ''), | ||
} | ||
} | ||
return reference.replace(`${resourceType}/`, '') | ||
@@ -317,4 +333,14 @@ }, | ||
if (value) { | ||
let reference | ||
if (value.deleted) { | ||
if (!deletable) { | ||
throw new Error('Cannot delete this reference') | ||
} | ||
reference = `${deletedPrefixWithResourceType}${value.deleted}` | ||
} else { | ||
reference = `${resourceType}/${value}` | ||
} | ||
return setValue(data, `${propName}.[${index}]`, { | ||
reference: `${resourceType}/${value}`, | ||
reference, | ||
}) | ||
@@ -321,0 +347,0 @@ } else { |
@@ -115,3 +115,5 @@ // @ts-check | ||
}), | ||
appointmentId: getReferenceProp('about', 'Appointment'), | ||
appointmentId: getReferenceProp('partOf', 'Appointment', { | ||
deletable: true, | ||
}), | ||
}, | ||
@@ -139,3 +141,3 @@ definition: buildDefinition( | ||
'statusReason.coding.[].display': 'str', | ||
'about.[].reference': 'str', | ||
'partOf.[].reference': 'str', | ||
}, | ||
@@ -142,0 +144,0 @@ fhirFieldTypes |
@@ -5,2 +5,35 @@ // @ts-check | ||
test('patientCommentDefinition supports deletable references', t => { | ||
t.test('When not deleted, deals in string references', t => { | ||
const startProps = { | ||
appointmentId: 'abc', | ||
} | ||
const resource = patientCommentDefinition.create(startProps) | ||
t.deepEqual(resource.partOf, [{ reference: 'Appointment/abc' }]) | ||
const values = patientCommentDefinition.getValues(resource) | ||
t.equal(values.appointmentId, 'abc') | ||
t.end() | ||
}) | ||
t.test('When deleted, deals in { deleted: id } objects', t => { | ||
const startProps = { | ||
appointmentId: { deleted: 'abc' }, | ||
} | ||
const resource = patientCommentDefinition.create(startProps) | ||
t.deepEqual(resource.partOf, [ | ||
{ | ||
reference: | ||
'https://ns.anesthesiacharting.com/deleted-reference/Appointment/abc', | ||
}, | ||
]) | ||
const values = patientCommentDefinition.getValues(resource) | ||
t.deepEqual(values.appointmentId, { deleted: 'abc' }) | ||
t.end() | ||
}) | ||
t.end() | ||
}) | ||
test('patientCommentDefinition supports external author types', t => { | ||
@@ -110,3 +143,3 @@ const startProps = { | ||
], | ||
about: [{ reference: 'Appointment/abc' }], | ||
partOf: [{ reference: 'Appointment/abc' }], | ||
status: 'completed', | ||
@@ -113,0 +146,0 @@ }) |
Sorry, the diff of this file is too big to display
201872
7024