Skip to content

Commit

Permalink
refactor: get rid of custom hasAnswers function in favor to answers a…
Browse files Browse the repository at this point in the history
…nd exists
  • Loading branch information
ruscoder committed May 25, 2024
1 parent 9796eca commit 8f635f9
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions ts/server/src/utils/extract-complex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const template = {
{
observationEntries: [
{
"{% if hasAnswers('WEIGHT') and hasAnswers('HEIGHT') %}": {
"{% if answers('WEIGHT').exists() and answers('HEIGHT').exists() %}": {
'{% assign %}': [
{
observationId:
Expand Down Expand Up @@ -413,24 +413,16 @@ const sample = {
};

const userInvocationTable: UserInvocationTable = {
hasAnswers: {
fn: (inputs, linkId) =>
fhirpath.evaluate(
inputs,
`repeat(item).where(linkId='${linkId}').answer.value.exists()`,
)[0],
arity: { 0: [], 1: ['String'] },
},
answers: {
fn: (inputs, linkId, type) => {
const getter = ['Reference', 'Coding', 'Quantity'].includes(type) ? 'children()' : type;
fn: (inputs, linkId: string, type?: string) => {
const getter = ['Reference', 'Coding', 'Quantity', undefined].includes(type) ? 'children()' : type;

return fhirpath.evaluate(
inputs,
`repeat(item).where(linkId='${linkId}').answer.value.${getter}`,
);
},
arity: { 0: [], 2: ['String', 'String'] },
arity: { 0: [], 1: ['String'], 2: ['String', 'String'] },
},
// Get rid of toString once it's fixed https://github.com/HL7/fhirpath.js/issues/156
toString: {
Expand Down

0 comments on commit 8f635f9

Please sign in to comment.