Skip to content

Commit

Permalink
restructure getReferenceKey tests so they don't mention key values
Browse files Browse the repository at this point in the history
closes #202

Co-authored-by: spicyfalafel <[email protected]>
  • Loading branch information
Yngwarr and spicyfalafel committed Mar 4, 2024
1 parent 801d24a commit 2cb3506
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 44 deletions.
8 changes: 3 additions & 5 deletions sof-js/src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { default as fhirpath } from 'fhirpath'

const identity = (ctx, v) => [v]

function getResourceKey(nodes, resource) {
function getResourceKey(nodes) {
return nodes.flatMap((node) => {
const type = node.resourceType
const key = `${node.resourceType}/${node.id}`
return !resource || resource === tmpe ? [key] : []
return [node.id]
})
}

Expand Down Expand Up @@ -51,7 +49,7 @@ function rewrite_path(path) {

let fhirpath_options = {
userInvocationTable: {
getResourceKey: { fn: getResourceKey, arity: { 0: [], 1: ['TypeSpecifier'] } },
getResourceKey: { fn: getResourceKey, arity: { 0: [] } },
getReferenceKey: { fn: getReferenceKey, arity: { 0: [], 1: ['TypeSpecifier'] } },
identity: { fn: (nodes) => nodes, arity: { 0: [] } },
}
Expand Down
11 changes: 0 additions & 11 deletions sof-js/tests/2_fhirpath.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,6 @@ describe('fhirpath', () => {
],
})

// are we sure about this?
add_test({
title: 'getResourceKey()',
view: {
resource: 'Patient',
status: 'active',
select: [{ column: [{ name: 'id', path: 'getResourceKey()' }] }],
},
expect: [{ id: 'Patient/pt1' }, { id: 'Patient/pt2' }, { id: 'Patient/pt3' }],
})

add_test({
title: 'getReferenceKey()',
view: {
Expand Down
94 changes: 94 additions & 0 deletions sof-js/tests/fn_reference_keys.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { describe } from 'bun:test'
import { add_test, end_case, start_case } from './test_helpers'

const resources = [
{
resourceType: "Patient",
id: "p1",
link: [
{
other: {
reference: "Patient/p1"
}
}
]
}
]

start_case('fn_reference_keys', 'TBD', resources)

describe('getReferenceKey result matches getResourceKey', () => {
add_test({
title: "getReferenceKey result matches getResourceKey without type specifier",
view: {
resource: "Patient",
select: [
{
column: [
{
path: "getResourceKey() = link.other.getReferenceKey()",
name: "key_equal_ref"
}
]
}
]
},
expect: [
{
key_equal_ref: true
}
]
})

add_test({
title: "getReferenceKey result matches getResourceKey with right type specifier",
view: {
resource: "Patient",
select: [
{
column: [
{
path: "getResourceKey() = link.other.getReferenceKey(Patient)",
name: "key_equal_ref"
}
]
}
]
},
expect: [
{
key_equal_ref: true
}
]
})

add_test({
title: "getReferenceKey result matches getResourceKey with wrong type specifier",
view: {
resource: "Patient",
select: [
{
column: [
{
path: "link.other.getReferenceKey(Observation)",
name: "referenceKey"
},
{
path: "getResourceKey() = link.other.getReferenceKey(Observation)",
name: "key_equal_ref"
}
]
}
]
},
expect: [
{
referenceKey: null,
key_equal_ref: null
}
]
})

end_case()
})

28 changes: 0 additions & 28 deletions tests/fhirpath.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,34 +451,6 @@
}
]
},
{
"title": "getResourceKey()",
"view": {
"resource": "Patient",
"status": "active",
"select": [
{
"column": [
{
"name": "id",
"path": "getResourceKey()"
}
]
}
]
},
"expect": [
{
"id": "Patient/pt1"
},
{
"id": "Patient/pt2"
},
{
"id": "Patient/pt3"
}
]
},
{
"title": "getReferenceKey()",
"view": {
Expand Down
87 changes: 87 additions & 0 deletions tests/fn_reference_keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"title": "fn_reference_keys",
"description": "TBD",
"resources": [
{
"resourceType": "Patient",
"id": "p1",
"link": [
{
"other": {
"reference": "Patient/p1"
}
}
]
}
],
"tests": [
{
"title": "getReferenceKey result matches getResourceKey without type specifier",
"view": {
"resource": "Patient",
"select": [
{
"column": [
{
"path": "getResourceKey() = link.other.getReferenceKey()",
"name": "key_equal_ref"
}
]
}
]
},
"expect": [
{
"key_equal_ref": true
}
]
},
{
"title": "getReferenceKey result matches getResourceKey with right type specifier",
"view": {
"resource": "Patient",
"select": [
{
"column": [
{
"path": "getResourceKey() = link.other.getReferenceKey(Patient)",
"name": "key_equal_ref"
}
]
}
]
},
"expect": [
{
"key_equal_ref": true
}
]
},
{
"title": "getReferenceKey result matches getResourceKey with wrong type specifier",
"view": {
"resource": "Patient",
"select": [
{
"column": [
{
"path": "link.other.getReferenceKey(Observation)",
"name": "referenceKey"
},
{
"path": "getResourceKey() = link.other.getReferenceKey(Observation)",
"name": "key_equal_ref"
}
]
}
]
},
"expect": [
{
"referenceKey": null,
"key_equal_ref": null
}
]
}
]
}

0 comments on commit 2cb3506

Please sign in to comment.