diff --git a/sof-js/src/index.js b/sof-js/src/index.js index 0265dac..8c5772e 100644 --- a/sof-js/src/index.js +++ b/sof-js/src/index.js @@ -145,7 +145,7 @@ function normalize(def) { def.type = 'forEach' if (def.unionAll) { - def.select.unshift({unionAll: def.union}) + def.select.unshift({unionAll: def.unionAll}) delete def.unionAll } @@ -162,7 +162,7 @@ function normalize(def) { def.type = 'forEachOrNull' if (def.unionAll) { - def.select.unshift({unionAll: def.union}) + def.select.unshift({unionAll: def.unionAll}) delete def.unionAll } @@ -272,5 +272,9 @@ export function evaluate(def, node) { } const normal_def = normalize(structuredClone(def)); + + // console.log("======= NORM =========") + // console.dir(normal_def, {depth: null}) + return node.flatMap(n => do_eval(normal_def, n, def)) } diff --git a/sof-js/tests/1_basic.test.js b/sof-js/tests/1_basic.test.js index 1fc059a..e5e643d 100644 --- a/sof-js/tests/1_basic.test.js +++ b/sof-js/tests/1_basic.test.js @@ -202,5 +202,24 @@ describe("basics", () => { expect: [{id: 'pt1'}] }) + add_test({ + title: 'select & column', + view: { + resource: 'Patient', + select: [ + { + column: [{path: 'id', name: 'c_id'}], + select: [{column: [{path: 'id', name: 's_id'}]}] + } + + ] + }, + expect: [ + {c_id: 'pt1', s_id: 'pt1'}, + {c_id: 'pt2', s_id: 'pt2'}, + {c_id: 'pt3', s_id: 'pt3'} + ] + }); + end_case(); }); diff --git a/sof-js/tests/3_foreach.test.js b/sof-js/tests/3_foreach.test.js index e3fe9a4..229fb56 100644 --- a/sof-js/tests/3_foreach.test.js +++ b/sof-js/tests/3_foreach.test.js @@ -17,6 +17,7 @@ let resources = [ { system: 'phone' } ], name: { + family: 'FC1.1', given: ['N1', 'N1`'] } }, @@ -24,7 +25,11 @@ let resources = [ telecom: [ { system: 'email' } ], - name: { given: ['N2'] } + gender: "unknown", + name: { + family: 'FC1.2', + given: ['N2'] + } } ] }, @@ -77,7 +82,7 @@ describe('foreach', () => { }) add_test({ - title: 'forEachOrNull: normal', + title: 'forEachOrNull: basic', view: { resource: 'Patient', status: 'active', @@ -114,6 +119,52 @@ describe('foreach', () => { expect: [] }) + + add_test({ + title: 'forEach: two on the same level', + view: { + resource: 'Patient', + status: 'active', + select: [ + { + forEach: 'contact', + column: [{ name: 'cont_family', path: 'name.family' }] + }, + { + forEach: 'name', + column: [{ name: 'pat_family' , path: 'family' }] + } + ] + }, + expect: [ + {pat_family: 'F1.1', cont_family: 'FC1.1'}, + {pat_family: 'F1.1', cont_family: 'FC1.2'}, + + {pat_family: 'F1.2', cont_family: 'FC1.1'}, + {pat_family: 'F1.2', cont_family: 'FC1.2'} + ] + }) + + add_test({ + title: 'forEach: two on the same level (empty result)', + view: { + resource: 'Patient', + status: 'active', + select: [ + { column: [{ name: 'id', path: 'id' }] }, + { + forEach: 'identifier', + column: [{ name: 'value', path: 'value' }] + }, + { + forEach: 'name', + column: [{ name: 'family', path: 'family' }] + } + ] + }, + expect: [] + }) + add_test({ title: 'forEachOrNull: null case', view: { @@ -134,6 +185,31 @@ describe('foreach', () => { ] }) + add_test({ + title: 'forEach and forEachOrNull on the same level', + view: { + resource: 'Patient', + status: 'active', + select: [ + { column: [{ name: 'id', path: 'id' }] }, + { + forEachOrNull: 'identifier', + column: [{ name: 'value', path: 'value' }] + }, + { + forEach: 'name', + column: [{ name: 'family', path: 'family' }] + } + ] + }, + expect: [ + { id: 'pt1', family: 'F1.1', value: null }, + { id: 'pt1', family: 'F1.2', value: null }, + { id: 'pt2', family: 'F2.1', value: null }, + { id: 'pt2', family: 'F2.2', value: null }, + ] + }) + let nested_result = [ { contact_type: "phone", name: "N1" , id: "pt1" }, { contact_type: "phone", name: "N1`", id: "pt1" }, @@ -185,6 +261,131 @@ describe('foreach', () => { expect: nested_result }); + add_test({ + title: 'forEachOrNull & unionAll on the same level', + view: { + resource: 'Patient', + select: [ + { + column: [{path: 'id', name: 'id'}], + }, + { + forEachOrNull: "contact", + unionAll: [ + {column: [{path: 'name.family', name: 'name'}]}, + {forEach: "name.given", + column: [{path: '$this', name: 'name'}]} + + ] + } + + ] + }, + expect: [ + {id: 'pt1', name: 'FC1.1'}, + {id: 'pt1', name: 'N1'}, + {id: 'pt1', name: 'N1`'}, + {id: 'pt1', name: 'FC1.2'}, + {id: 'pt1', name: 'N2'}, + {id: 'pt2', name: null}, + {id: 'pt3', name: null}, + ] + }) + + add_test({ + title: 'forEach & unionAll on the same level', + view: { + resource: 'Patient', + select: [ + { + column: [{path: 'id', name: 'id'}], + }, + { + forEach: "contact", + unionAll: [ + {column: [{path: 'name.family', name: 'name'}]}, + {forEach: "name.given", + column: [{path: '$this', name: 'name'}]} + + ] + } + + ] + }, + expect: [ + {id: 'pt1', name: 'FC1.1'}, + {id: 'pt1', name: 'N1'}, + {id: 'pt1', name: 'N1`'}, + {id: 'pt1', name: 'FC1.2'}, + {id: 'pt1', name: 'N2'}, + ] + }) + + add_test({ + title: 'forEach & unionAll & column & select on the same level', + view: { + resource: 'Patient', + select: [ + { + column: [{path: 'id', name: 'id'}], + }, + { + forEach: "contact", + column: [{path: 'telecom.system', name: 'tel_system'}], + select: [{column: [{path: 'gender', name: 'gender'}]}], + unionAll: [ + {column: [{path: 'name.family', name: 'name'}]}, + {forEach: "name.given", + column: [{path: '$this', name: 'name'}]} + + ] + } + + ] + }, + expect: [ + {id: 'pt1', name: 'FC1.1', tel_system: "phone", gender: null}, + {id: 'pt1', name: 'N1', tel_system: "phone", gender: null}, + {id: 'pt1', name: 'N1`', tel_system: "phone", gender: null}, + {id: 'pt1', name: 'FC1.2', tel_system: "email", gender: "unknown"}, + {id: 'pt1', name: 'N2', tel_system: "email", gender: "unknown"}, + ] + }) + + add_test({ + title: 'forEachOrNull & unionAll & column & select on the same level', + view: { + resource: 'Patient', + select: [ + { + column: [{path: 'id', name: 'id'}], + }, + { + forEachOrNull: "contact", + column: [{path: 'telecom.system', name: 'tel_system'}], + select: [{column: [{path: 'gender', name: 'gender'}]}], + unionAll: [ + {column: [{path: 'name.family', name: 'name'}]}, + {forEach: "name.given", + column: [{path: '$this', name: 'name'}]} + + ] + } + + ] + }, + expect: [ + {id: 'pt1', name: 'FC1.1', tel_system: "phone", gender: null}, + {id: 'pt1', name: 'N1', tel_system: "phone", gender: null}, + {id: 'pt1', name: 'N1`', tel_system: "phone", gender: null}, + {id: 'pt1', name: 'FC1.2', tel_system: "email", gender: "unknown"}, + {id: 'pt1', name: 'N2', tel_system: "email", gender: "unknown"}, + {id: 'pt2', name: null, tel_system: null, gender: null}, + {id: 'pt3', name: null, tel_system: null, gender: null}, + ] + }) + + end_case(); }) diff --git a/sof-js/tests/4_union.test.js b/sof-js/tests/4_union.test.js index e66853c..41ea9dc 100644 --- a/sof-js/tests/4_union.test.js +++ b/sof-js/tests/4_union.test.js @@ -236,6 +236,35 @@ describe("union", () => { ] }); + add_test({ + title: 'forEachOrNull and forEach', + view: { + resource: 'Patient', + status: 'active', + select: [ + { + column: [{ name: 'id', path: 'id' }], + unionAll: [ + { + forEach: 'name', + column: [{ name: 'given', path: 'given' }] + }, + { + forEachOrNull: 'name', + column: [{ name: 'given', path: 'given' }] + } + ] + } + ] + }, + expect: [ + { given: null, id: "pt1" }, + { given: null, id: "pt2" }, + { given: null, id: "pt3" }, + { given: null, id: "pt4" }, + ] + }) + add_test({ title: 'nested', view: { diff --git a/sof-js/tests/combination.test.js b/sof-js/tests/combination.test.js deleted file mode 100644 index 98c57a2..0000000 --- a/sof-js/tests/combination.test.js +++ /dev/null @@ -1,47 +0,0 @@ -import { describe } from "bun:test"; -import { start_case, end_case, add_test, debug } from './test_helpers.js' - - -let resources = [ - {id: 'pt1', resourceType: 'Patient'}, - {id: 'pt2', resourceType: 'Patient'}, - {id: 'pt3', resourceType: 'Patient'}, -] - -start_case('Combinations', 'TBD', resources) - -describe("combinations", () => { - - add_test({ - title: 'select & column', - view: { - resource: 'Patient', - status: 'active', - select: [{column: [{path: 'id', name: 'id'}]}] - }, - expect: [{id: 'pt1'}, {id: 'pt2'}, {id: 'pt3'}] - }); - - add_test({ - title: 'top level column', - view: { - resource: 'Patient', - status: 'active', - select: [{column: [{path: 'id', name: 'id'}]}] - }, - expect: [{id: 'pt1'}, {id: 'pt2'}, {id: 'pt3'}] - }); - - - add_test({ - title: 'select & select & column', - view: { - resource: 'Patient', - select: [{select: [{column: [{path: 'id', name: 'id'}]}]}] - }, - expect: [{id: 'pt1'}, {id: 'pt2'}, {id: 'pt3'}] - }); - - end_case() - -}) diff --git a/tests/Combinations.json b/tests/Combinations.json deleted file mode 100644 index c17910e..0000000 --- a/tests/Combinations.json +++ /dev/null @@ -1,107 +0,0 @@ -{ - "title": "Combinations", - "description": "TBD", - "resources": [ - { - "id": "pt1", - "resourceType": "Patient" - }, - { - "id": "pt2", - "resourceType": "Patient" - }, - { - "id": "pt3", - "resourceType": "Patient" - } - ], - "tests": [ - { - "title": "select & column", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - } - ] - } - ] - }, - "expect": [ - { - "id": "pt1" - }, - { - "id": "pt2" - }, - { - "id": "pt3" - } - ] - }, - { - "title": "top level column", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - } - ] - } - ] - }, - "expect": [ - { - "id": "pt1" - }, - { - "id": "pt2" - }, - { - "id": "pt3" - } - ] - }, - { - "title": "select & select & column", - "view": { - "resource": "Patient", - "select": [ - { - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - } - ] - } - ] - } - ] - }, - "expect": [ - { - "id": "pt1" - }, - { - "id": "pt2" - }, - { - "id": "pt3" - } - ] - } - ] -} \ No newline at end of file diff --git a/tests/basic.json b/tests/basic.json index 8f7dce3..caf877c 100644 --- a/tests/basic.json +++ b/tests/basic.json @@ -1,304 +1,344 @@ { - "title": "basic", - "description": "basic view definition", - "resources": [ - { - "resourceType": "Patient", - "id": "pt1", - "name": [ + "title": "basic", + "description": "basic view definition", + "resources": [ { - "family": "F1" - } - ], - "active": true - }, - { - "resourceType": "Patient", - "id": "pt2", - "name": [ - { - "family": "F2" - } - ], - "active": false - }, - { - "resourceType": "Patient", - "id": "pt3" - } - ], - "tests": [ - { - "title": "basic attribute", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - } - ] - }, - "expect": [ - { - "id": "pt1" + "resourceType": "Patient", + "id": "pt1", + "name": [ + { + "family": "F1" + } + ], + "active": true }, { - "id": "pt2" + "resourceType": "Patient", + "id": "pt2", + "name": [ + { + "family": "F2" + } + ], + "active": false }, { - "id": "pt3" + "resourceType": "Patient", + "id": "pt3" } - ] - }, - { - "title": "boolean attribute with false", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "active", - "path": "active" - } - ] - } - ] - }, - "expect": [ + ], + "tests": [ { - "id": "pt1", - "active": true - }, - { - "id": "pt2", - "active": false + "title": "basic attribute", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1" + }, + { + "id": "pt2" + }, + { + "id": "pt3" + } + ] }, { - "id": "pt3", - "active": null - } - ] - }, - { - "title": "two columns", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "last_name", - "path": "name.family.first()" - } + "title": "boolean attribute with false", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "active", + "path": "active" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "active": true + }, + { + "id": "pt2", + "active": false + }, + { + "id": "pt3", + "active": null + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "last_name": "F1" }, { - "id": "pt2", - "last_name": "F2" + "title": "two columns", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "last_name", + "path": "name.family.first()" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "last_name": "F1" + }, + { + "id": "pt2", + "last_name": "F2" + }, + { + "id": "pt3", + "last_name": null + } + ] }, { - "id": "pt3", - "last_name": null - } - ] - }, - { - "title": "two selects with columns", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } + "title": "two selects with columns", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "column": [ + { + "name": "last_name", + "path": "name.family.first()" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "last_name": "F1" + }, + { + "id": "pt2", + "last_name": "F2" + }, + { + "id": "pt3", + "last_name": null + } ] - }, - { - "column": [ - { - "name": "last_name", - "path": "name.family.first()" - } - ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "last_name": "F1" }, { - "id": "pt2", - "last_name": "F2" + "title": "where - 1", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + } + ], + "where": [ + { + "path": "active = true" + } + ] + }, + "expect": [ + { + "id": "pt1" + } + ] }, { - "id": "pt3", - "last_name": null - } - ] - }, - { - "title": "where - 1", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } + "title": "where - 2", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + } + ], + "where": [ + { + "path": "active = false" + } + ] + }, + "expect": [ + { + "id": "pt2" + } ] - } - ], - "where": [ - { - "path": "active = true" - } - ] - }, - "expect": [ + }, { - "id": "pt1" - } - ] - }, - { - "title": "where - 2", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } + "title": "where as element", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + } + ], + "where": [ + { + "path": "active" + } + ] + }, + "expect": [ + { + "id": "pt1" + } ] - } - ], - "where": [ - { - "path": "active = false" - } - ] - }, - "expect": [ + }, { - "id": "pt2" - } - ] - }, - { - "title": "where as element", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } + "title": "where as expr - 1", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + } + ], + "where": [ + { + "path": "name.family = 'F2'" + } + ] + }, + "expect": [ + { + "id": "pt2" + } ] - } - ], - "where": [ - { - "path": "active" - } - ] - }, - "expect": [ + }, { - "id": "pt1" - } - ] - }, - { - "title": "where as expr - 1", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } + "title": "where as expr - 2", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + } + ], + "where": [ + { + "path": "name.family = 'F1'" + } + ] + }, + "expect": [ + { + "id": "pt1" + } ] - } - ], - "where": [ - { - "path": "name.family = 'F2'" - } - ] - }, - "expect": [ + }, { - "id": "pt2" - } - ] - }, - { - "title": "where as expr - 2", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } + "title": "select & column", + "view": { + "resource": "Patient", + "select": [ + { + "column": [ + { + "path": "id", + "name": "c_id" + } + ], + "select": [ + { + "column": [ + { + "path": "id", + "name": "s_id" + } + ] + } + ] + } + ] + }, + "expect": [ + { + "c_id": "pt1", + "s_id": "pt1" + }, + { + "c_id": "pt2", + "s_id": "pt2" + }, + { + "c_id": "pt3", + "s_id": "pt3" + } ] - } - ], - "where": [ - { - "path": "name.family = 'F1'" - } - ] - }, - "expect": [ - { - "id": "pt1" } - ] - } - ] -} \ No newline at end of file + ] +} diff --git a/tests/collection.json b/tests/collection.json index c67e267..424bf4a 100644 --- a/tests/collection.json +++ b/tests/collection.json @@ -1,270 +1,226 @@ { - "title": "collection", - "description": "TBD", - "resources": [ - { - "resourceType": "Patient", - "id": "pt1", - "name": [ + "title": "collection", + "description": "TBD", + "resources": [ { - "use": "official", - "family": "f1.1", - "given": [ - "g1.1" - ] + "resourceType": "Patient", + "id": "pt1", + "name": [ + { + "use": "official", + "family": "f1.1", + "given": ["g1.1"] + }, + { + "family": "f1.2", + "given": ["g1.2", "g1.3"] + } + ], + "gender": "male", + "birthDate": "1950-01-01", + "address": [ + { + "city": "c1" + } + ] }, { - "family": "f1.2", - "given": [ - "g1.2", - "g1.3" - ] - } - ], - "gender": "male", - "birthDate": "1950-01-01", - "address": [ - { - "city": "c1" + "resourceType": "Patient", + "id": "pt2", + "name": [ + { + "family": "f2.1", + "given": ["g2.1"] + }, + { + "use": "official", + "family": "f2.2", + "given": ["g2.2", "g2.3"] + } + ], + "gender": "female", + "birthDate": "1950-01-01" } - ] - }, - { - "resourceType": "Patient", - "id": "pt2", - "name": [ + ], + "tests": [ { - "family": "f2.1", - "given": [ - "g2.1" - ] + "title": "fail when 'collection' is not true", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "last_name", + "path": "name.family", + "collection": false + }, + { + "name": "first_name", + "path": "name.given", + "collection": true + } + ] + } + ] + }, + "expectError": true }, { - "use": "official", - "family": "f2.2", - "given": [ - "g2.2", - "g2.3" - ] - } - ], - "gender": "female", - "birthDate": "1950-01-01" - } - ], - "tests": [ - { - "title": "fail when 'collection' is not true", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "last_name", - "path": "name.family", - "collection": false - }, - { - "name": "first_name", - "path": "name.given", - "collection": true - } - ] - } - ] - }, - "expectError": true - }, - { - "title": "collection = true", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "last_name", - "path": "name.family", - "collection": true - }, - { - "name": "first_name", - "path": "name.given", - "collection": true - } + "title": "collection = true", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "last_name", + "path": "name.family", + "collection": true + }, + { + "name": "first_name", + "path": "name.given", + "collection": true + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "last_name": ["f1.1", "f1.2"], + "first_name": ["g1.1", "g1.2", "g1.3"] + }, + { + "id": "pt2", + "last_name": ["f2.1", "f2.2"], + "first_name": ["g2.1", "g2.2", "g2.3"] + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "last_name": [ - "f1.1", - "f1.2" - ], - "first_name": [ - "g1.1", - "g1.2", - "g1.3" - ] }, { - "id": "pt2", - "last_name": [ - "f2.1", - "f2.2" - ], - "first_name": [ - "g2.1", - "g2.2", - "g2.3" - ] - } - ] - }, - { - "title": "collection = false relative to forEach parent", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ], - "select": [ - { - "forEach": "name", - "column": [ - { - "name": "last_name", - "path": "family", - "collection": false - }, - { - "name": "first_name", - "path": "given", - "collection": true - } + "title": "collection = false relative to forEach parent", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ], + "select": [ + { + "forEach": "name", + "column": [ + { + "name": "last_name", + "path": "family", + "collection": false + }, + { + "name": "first_name", + "path": "given", + "collection": true + } + ] + } + ] + } ] - } + }, + "expect": [ + { + "id": "pt1", + "last_name": "f1.1", + "first_name": ["g1.1"] + }, + { + "id": "pt1", + "last_name": "f1.2", + "first_name": ["g1.2", "g1.3"] + }, + { + "id": "pt2", + "last_name": "f2.1", + "first_name": ["g2.1"] + }, + { + "id": "pt2", + "last_name": "f2.2", + "first_name": ["g2.2", "g2.3"] + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "last_name": "f1.1", - "first_name": [ - "g1.1" - ] }, { - "id": "pt1", - "last_name": "f1.2", - "first_name": [ - "g1.2", - "g1.3" - ] - }, - { - "id": "pt2", - "last_name": "f2.1", - "first_name": [ - "g2.1" - ] - }, - { - "id": "pt2", - "last_name": "f2.2", - "first_name": [ - "g2.2", - "g2.3" - ] - } - ] - }, - { - "title": "collection = false relative to forEachOrNull parent", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ], - "select": [ - { - "forEach": "name", - "column": [ - { - "name": "last_name", - "path": "family", - "collection": false - }, - { - "name": "first_name", - "path": "given", - "collection": true - } + "title": "collection = false relative to forEachOrNull parent", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ], + "select": [ + { + "forEach": "name", + "column": [ + { + "name": "last_name", + "path": "family", + "collection": false + }, + { + "name": "first_name", + "path": "given", + "collection": true + } + ] + } + ] + } ] - } + }, + "expect": [ + { + "id": "pt1", + "last_name": "f1.1", + "first_name": ["g1.1"] + }, + { + "id": "pt1", + "last_name": "f1.2", + "first_name": ["g1.2", "g1.3"] + }, + { + "id": "pt2", + "last_name": "f2.1", + "first_name": ["g2.1"] + }, + { + "id": "pt2", + "last_name": "f2.2", + "first_name": ["g2.2", "g2.3"] + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "last_name": "f1.1", - "first_name": [ - "g1.1" - ] - }, - { - "id": "pt1", - "last_name": "f1.2", - "first_name": [ - "g1.2", - "g1.3" - ] - }, - { - "id": "pt2", - "last_name": "f2.1", - "first_name": [ - "g2.1" - ] - }, - { - "id": "pt2", - "last_name": "f2.2", - "first_name": [ - "g2.2", - "g2.3" - ] } - ] - } - ] -} \ No newline at end of file + ] +} diff --git a/tests/constant.json b/tests/constant.json index 0c20bd8..ef19fce 100644 --- a/tests/constant.json +++ b/tests/constant.json @@ -1,310 +1,310 @@ { - "title": "constant", - "description": "constant substitution", - "resources": [ - { - "resourceType": "Patient", - "id": "pt1", - "name": [ + "title": "constant", + "description": "constant substitution", + "resources": [ { - "family": "Block", - "use": "usual" + "resourceType": "Patient", + "id": "pt1", + "name": [ + { + "family": "Block", + "use": "usual" + }, + { + "family": "Smith", + "use": "official" + } + ] }, { - "family": "Smith", - "use": "official" + "resourceType": "Patient", + "id": "pt2", + "deceasedBoolean": true, + "name": [ + { + "family": "Johnson", + "use": "usual" + }, + { + "family": "Menendez", + "use": "old" + } + ] } - ] - }, - { - "resourceType": "Patient", - "id": "pt2", - "deceasedBoolean": true, - "name": [ - { - "family": "Johnson", - "use": "usual" - }, + ], + "tests": [ { - "family": "Menendez", - "use": "old" - } - ] - } - ], - "tests": [ - { - "title": "constant in path", - "view": { - "resource": "Patient", - "status": "active", - "constant": [ - { - "name": "name_use", - "valueString": "official" - } - ], - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "official_name", - "path": "name.where(use = %name_use).family" - } + "title": "constant in path", + "view": { + "resource": "Patient", + "status": "active", + "constant": [ + { + "name": "name_use", + "valueString": "official" + } + ], + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "official_name", + "path": "name.where(use = %name_use).family" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "official_name": "Smith" + }, + { + "id": "pt2", + "official_name": null + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "official_name": "Smith" }, { - "id": "pt2", - "official_name": null - } - ] - }, - { - "title": "constant in forEach", - "view": { - "resource": "Patient", - "status": "active", - "constant": [ - { - "name": "name_use", - "valueString": "official" - } - ], - "select": [ - { - "forEach": "name.where(use = %name_use)", - "column": [ - { - "name": "official_name", - "path": "family" - } + "title": "constant in forEach", + "view": { + "resource": "Patient", + "status": "active", + "constant": [ + { + "name": "name_use", + "valueString": "official" + } + ], + "select": [ + { + "forEach": "name.where(use = %name_use)", + "column": [ + { + "name": "official_name", + "path": "family" + } + ] + } + ] + }, + "expect": [ + { + "official_name": "Smith" + } ] - } - ] - }, - "expect": [ + }, { - "official_name": "Smith" - } - ] - }, - { - "title": "constant in where element", - "view": { - "resource": "Patient", - "status": "active", - "constant": [ - { - "name": "name_use", - "valueString": "official" - } - ], - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } + "title": "constant in where element", + "view": { + "resource": "Patient", + "status": "active", + "constant": [ + { + "name": "name_use", + "valueString": "official" + } + ], + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + } + ], + "where": [ + { + "path": "name.where(use = %name_use)" + } + ] + }, + "expect": [ + { + "id": "pt1" + } ] - } - ], - "where": [ - { - "path": "name.where(use = %name_use)" - } - ] - }, - "expect": [ + }, { - "id": "pt1" - } - ] - }, - { - "title": "constant in unionAll", - "view": { - "resource": "Patient", - "status": "active", - "constant": [ - { - "name": "use1", - "valueString": "official" - }, - { - "name": "use2", - "valueString": "usual" - } - ], - "select": [ - { - "unionAll": [ - { - "forEach": "name.where(use = %use1)", - "column": [ - { - "name": "name", - "path": "family" - } + "title": "constant in unionAll", + "view": { + "resource": "Patient", + "status": "active", + "constant": [ + { + "name": "use1", + "valueString": "official" + }, + { + "name": "use2", + "valueString": "usual" + } + ], + "select": [ + { + "unionAll": [ + { + "forEach": "name.where(use = %use1)", + "column": [ + { + "name": "name", + "path": "family" + } + ] + }, + { + "forEach": "name.where(use = %use2)", + "column": [ + { + "name": "name", + "path": "family" + } + ] + } + ] + } ] - }, - { - "forEach": "name.where(use = %use2)", - "column": [ - { - "name": "name", - "path": "family" - } - ] - } + }, + "expect": [ + { + "name": "Smith" + }, + { + "name": "Block" + }, + { + "name": "Johnson" + } ] - } - ] - }, - "expect": [ - { - "name": "Smith" }, { - "name": "Block" + "title": "integer constant", + "view": { + "resource": "Patient", + "status": "active", + "constant": [ + { + "name": "name_index", + "valueInteger": 1 + } + ], + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "official_name", + "path": "name[%name_index].family" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "official_name": "Smith" + }, + { + "id": "pt2", + "official_name": "Menendez" + } + ] }, { - "name": "Johnson" - } - ] - }, - { - "title": "integer constant", - "view": { - "resource": "Patient", - "status": "active", - "constant": [ - { - "name": "name_index", - "valueInteger": 1 - } - ], - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "official_name", - "path": "name[%name_index].family" - } + "title": "boolean constant", + "view": { + "resource": "Patient", + "status": "active", + "constant": [ + { + "name": "is_deceased", + "valueInteger": true + } + ], + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + } + ], + "where": [ + { + "path": "deceased.ofType(boolean) = %is_deceased" + } + ] + }, + "expect": [ + { + "id": "pt2" + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "official_name": "Smith" }, { - "id": "pt2", - "official_name": "Menendez" - } - ] - }, - { - "title": "boolean constant", - "view": { - "resource": "Patient", - "status": "active", - "constant": [ - { - "name": "is_deceased", - "valueInteger": true - } - ], - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - } - ], - "where": [ - { - "path": "deceased.ofType(boolean) = %is_deceased" - } - ] - }, - "expect": [ + "title": "accessing an undefined constant", + "view": { + "resource": "Patient", + "status": "active", + "constant": [ + { + "name": "name_use", + "valueString": "official" + } + ], + "select": [ + { + "forEach": "name.where(use = %wrong_name)", + "column": [ + { + "name": "official_name", + "path": "family" + } + ] + } + ] + }, + "expectError": true + }, { - "id": "pt2" + "title": "incorrect constant definition", + "view": { + "resource": "Patient", + "status": "active", + "constant": [ + { + "name": "name_use" + } + ], + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "official_name", + "path": "name.where(use = %name_use).family" + } + ] + } + ] + }, + "expectError": true } - ] - }, - { - "title": "accessing an undefined constant", - "view": { - "resource": "Patient", - "status": "active", - "constant": [ - { - "name": "name_use", - "valueString": "official" - } - ], - "select": [ - { - "forEach": "name.where(use = %wrong_name)", - "column": [ - { - "name": "official_name", - "path": "family" - } - ] - } - ] - }, - "expectError": true - }, - { - "title": "incorrect constant definition", - "view": { - "resource": "Patient", - "status": "active", - "constant": [ - { - "name": "name_use" - } - ], - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "official_name", - "path": "name.where(use = %name_use).family" - } - ] - } - ] - }, - "expectError": true - } - ] -} \ No newline at end of file + ] +} diff --git a/tests/fhirpath.json b/tests/fhirpath.json index 241699b..5adb1f2 100644 --- a/tests/fhirpath.json +++ b/tests/fhirpath.json @@ -1,599 +1,588 @@ { - "title": "fhirpath", - "description": "fhirpath features", - "resources": [ - { - "resourceType": "Patient", - "id": "pt1", - "managingOrganization": { - "reference": "Organization/o1" - }, - "name": [ - { - "family": "f1.1", - "use": "official", - "given": [ - "g1.1.1", - "g1.1.2" - ] - }, - { - "family": "f1.2", - "given": [ - "g1.2.1" - ] - } - ], - "active": true - }, - { - "resourceType": "Patient", - "id": "pt2", - "managingOrganization": { - "reference": "http://myapp.com/prefix/Organization/o2" - }, - "name": [ - { - "family": "f2.1" - }, - { - "family": "f2.2", - "use": "official" + "title": "fhirpath", + "description": "fhirpath features", + "resources": [ + { + "resourceType": "Patient", + "id": "pt1", + "managingOrganization": { + "reference": "Organization/o1" + }, + "name": [ + { + "family": "f1.1", + "use": "official", + "given": ["g1.1.1", "g1.1.2"] + }, + { + "family": "f1.2", + "given": ["g1.2.1"] + } + ], + "active": true + }, + { + "resourceType": "Patient", + "id": "pt2", + "managingOrganization": { + "reference": "http://myapp.com/prefix/Organization/o2" + }, + "name": [ + { + "family": "f2.1" + }, + { + "family": "f2.2", + "use": "official" + } + ], + "active": false + }, + { + "resourceType": "Patient", + "id": "pt3" } - ], - "active": false - }, - { - "resourceType": "Patient", - "id": "pt3" - } - ], - "tests": [ - { - "title": "one element", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } + ], + "tests": [ + { + "title": "one element", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1" + }, + { + "id": "pt2" + }, + { + "id": "pt3" + } ] - } - ] - }, - "expect": [ - { - "id": "pt1" - }, - { - "id": "pt2" }, { - "id": "pt3" - } - ] - }, - { - "title": "two elements + first", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "v", - "path": "name.family.first()" - } + "title": "two elements + first", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "v", + "path": "name.family.first()" + } + ] + } + ] + }, + "expect": [ + { + "v": "f1.1" + }, + { + "v": "f2.1" + }, + { + "v": null + } ] - } - ] - }, - "expect": [ - { - "v": "f1.1" }, { - "v": "f2.1" - }, - { - "v": null - } - ] - }, - { - "title": "collection", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "v", - "path": "name.family", - "collection": true - } + "title": "collection", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "v", + "path": "name.family", + "collection": true + } + ] + } + ] + }, + "expect": [ + { + "v": ["f1.1", "f1.2"] + }, + { + "v": ["f2.1", "f2.2"] + }, + { + "v": [] + } ] - } - ] - }, - "expect": [ - { - "v": [ - "f1.1", - "f1.2" - ] - }, - { - "v": [ - "f2.1", - "f2.2" - ] }, { - "v": [] - } - ] - }, - { - "title": "index[0]", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "v", - "path": "name[0].family" - } + "title": "index[0]", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "v", + "path": "name[0].family" + } + ] + } + ] + }, + "expect": [ + { + "v": "f1.1" + }, + { + "v": "f2.1" + }, + { + "v": null + } ] - } - ] - }, - "expect": [ - { - "v": "f1.1" - }, - { - "v": "f2.1" }, { - "v": null - } - ] - }, - { - "title": "index[1]", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "v", - "path": "name[1].family" - } + "title": "index[1]", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "v", + "path": "name[1].family" + } + ] + } + ] + }, + "expect": [ + { + "v": "f1.2" + }, + { + "v": "f2.2" + }, + { + "v": null + } ] - } - ] - }, - "expect": [ - { - "v": "f1.2" }, { - "v": "f2.2" - }, - { - "v": null - } - ] - }, - { - "title": "out of index", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "v", - "path": "name[2].family" - } + "title": "out of index", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "v", + "path": "name[2].family" + } + ] + } + ] + }, + "expect": [ + { + "v": null + }, + { + "v": null + }, + { + "v": null + } ] - } - ] - }, - "expect": [ - { - "v": null }, { - "v": null - }, - { - "v": null - } - ] - }, - { - "title": "where", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "v", - "path": "name.where(use='official').family" - } + "title": "where", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "v", + "path": "name.where(use='official').family" + } + ] + } + ] + }, + "expect": [ + { + "v": "f1.1" + }, + { + "v": "f2.2" + }, + { + "v": null + } ] - } - ] - }, - "expect": [ - { - "v": "f1.1" - }, - { - "v": "f2.2" }, { - "v": null - } - ] - }, - { - "title": "exists", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "has_name", - "path": "name.exists()" - } + "title": "exists", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "has_name", + "path": "name.exists()" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "has_name": true + }, + { + "id": "pt2", + "has_name": true + }, + { + "id": "pt3", + "has_name": false + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "has_name": true - }, - { - "id": "pt2", - "has_name": true }, { - "id": "pt3", - "has_name": false - } - ] - }, - { - "title": "nested exists", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "has_given", - "path": "name.given.exists()" - } + "title": "nested exists", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "has_given", + "path": "name.given.exists()" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "has_given": true + }, + { + "id": "pt2", + "has_given": false + }, + { + "id": "pt3", + "has_given": false + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "has_given": true }, { - "id": "pt2", - "has_given": false - }, - { - "id": "pt3", - "has_given": false - } - ] - }, - { - "title": "exists", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "first_given", - "path": "name.given.first()" - } + "title": "exists", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "first_given", + "path": "name.given.first()" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "first_given": "g1.1.1" + }, + { + "id": "pt2", + "first_given": null + }, + { + "id": "pt3", + "first_given": null + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "first_given": "g1.1.1" - }, - { - "id": "pt2", - "first_given": null }, { - "id": "pt3", - "first_given": null - } - ] - }, - { - "title": "exists", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "first_family", - "path": "name.family.first()" - } + "title": "exists", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "first_family", + "path": "name.family.first()" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "first_family": "f1.1" + }, + { + "id": "pt2", + "first_family": "f2.1" + }, + { + "id": "pt3", + "first_family": null + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "first_family": "f1.1" }, { - "id": "pt2", - "first_family": "f2.1" - }, - { - "id": "pt3", - "first_family": null - } - ] - }, - { - "title": "string join", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "given", - "path": "name.given.join(', ' )" - } + "title": "string join", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "given", + "path": "name.given.join(', ' )" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "given": "g1.1.1, g1.1.2, g1.2.1" + }, + { + "id": "pt2", + "given": "" + }, + { + "id": "pt3", + "given": "" + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "given": "g1.1.1, g1.1.2, g1.2.1" }, { - "id": "pt2", - "given": "" - }, - { - "id": "pt3", - "given": "" - } - ] - }, - { - "title": "string join: default separator", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "given", - "path": "name.given.join()" - } + "title": "string join: default separator", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "given", + "path": "name.given.join()" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "given": "g1.1.1g1.1.2g1.2.1" + }, + { + "id": "pt2", + "given": "" + }, + { + "id": "pt3", + "given": "" + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "given": "g1.1.1g1.1.2g1.2.1" - }, - { - "id": "pt2", - "given": "" }, { - "id": "pt3", - "given": "" - } - ] - }, - { - "title": "getResourceKey()", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "getResourceKey()" - } + "title": "getResourceKey()", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "getResourceKey()" + } + ] + } + ] + }, + "expect": [ + { + "id": "Patient/pt1" + }, + { + "id": "Patient/pt2" + }, + { + "id": "Patient/pt3" + } ] - } - ] - }, - "expect": [ - { - "id": "Patient/pt1" - }, - { - "id": "Patient/pt2" }, { - "id": "Patient/pt3" - } - ] - }, - { - "title": "getReferenceKey()", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "ref", - "path": "managingOrganization.getReferenceKey()" - } + "title": "getReferenceKey()", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "ref", + "path": "managingOrganization.getReferenceKey()" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "ref": "o1" + }, + { + "id": "pt2", + "ref": "o2" + }, + { + "id": "pt3", + "ref": null + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "ref": "o1" }, { - "id": "pt2", - "ref": "o2" - }, - { - "id": "pt3", - "ref": null - } - ] - }, - { - "title": "getReferenceKey(Organization)", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "ref", - "path": "managingOrganization.getReferenceKey(Organization)" - } + "title": "getReferenceKey(Organization)", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "ref", + "path": "managingOrganization.getReferenceKey(Organization)" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "ref": "o1" + }, + { + "id": "pt2", + "ref": "o2" + }, + { + "id": "pt3", + "ref": null + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "ref": "o1" - }, - { - "id": "pt2", - "ref": "o2" }, { - "id": "pt3", - "ref": null - } - ] - }, - { - "title": "getReferenceKey(Encounter)", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "ref", - "path": "managingOrganization.getReferenceKey(Encounter)" - } + "title": "getReferenceKey(Encounter)", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "ref", + "path": "managingOrganization.getReferenceKey(Encounter)" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "ref": null + }, + { + "id": "pt2", + "ref": null + }, + { + "id": "pt3", + "ref": null + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "ref": null - }, - { - "id": "pt2", - "ref": null - }, - { - "id": "pt3", - "ref": null } - ] - } - ] -} \ No newline at end of file + ] +} diff --git a/tests/fn_boundary.json b/tests/fn_boundary.json index 8f0fc56..c2668a0 100644 --- a/tests/fn_boundary.json +++ b/tests/fn_boundary.json @@ -1,35 +1,35 @@ { - "title": "fn_boundary", - "description": "TBD", - "resources": [ - { - "resourceType": "Observation", - "id": "o1", - "code": { - "text": "code" - }, - "status": "final", - "valueQuantity": { - "value": 1 - } - }, - { - "resourceType": "Observation", - "id": "o2", - "code": { - "text": "code" - }, - "status": "final", - "valueDateTime": "2010-10-10" - }, - { - "resourceType": "Observation", - "id": "o3", - "code": { - "text": "code" - }, - "status": "final" - } - ], - "tests": [] -} \ No newline at end of file + "title": "fn_boundary", + "description": "TBD", + "resources": [ + { + "resourceType": "Observation", + "id": "o1", + "code": { + "text": "code" + }, + "status": "final", + "valueQuantity": { + "value": 1 + } + }, + { + "resourceType": "Observation", + "id": "o2", + "code": { + "text": "code" + }, + "status": "final", + "valueDateTime": "2010-10-10" + }, + { + "resourceType": "Observation", + "id": "o3", + "code": { + "text": "code" + }, + "status": "final" + } + ], + "tests": [] +} diff --git a/tests/fn_empty.json b/tests/fn_empty.json index 765393d..c8a85ca 100644 --- a/tests/fn_empty.json +++ b/tests/fn_empty.json @@ -1,53 +1,53 @@ { - "title": "fn_empty", - "description": "TBD", - "resources": [ - { - "resourceType": "Patient", - "id": "p1", - "name": [ + "title": "fn_empty", + "description": "TBD", + "resources": [ { - "use": "official", - "family": "f1" - } - ] - }, - { - "resourceType": "Patient", - "id": "p2" - } - ], - "tests": [ - { - "title": "empty names", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - }, - { - "name": "name_empty", - "path": "name.empty()" - } + "resourceType": "Patient", + "id": "p1", + "name": [ + { + "use": "official", + "family": "f1" + } ] - } - ] - }, - "expect": [ - { - "id": "p1", - "name_empty": false }, { - "id": "p2", - "name_empty": true + "resourceType": "Patient", + "id": "p2" + } + ], + "tests": [ + { + "title": "empty names", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "name_empty", + "path": "name.empty()" + } + ] + } + ] + }, + "expect": [ + { + "id": "p1", + "name_empty": false + }, + { + "id": "p2", + "name_empty": true + } + ] } - ] - } - ] -} \ No newline at end of file + ] +} diff --git a/tests/fn_oftype.json b/tests/fn_oftype.json index 02ea671..58c9fa7 100644 --- a/tests/fn_oftype.json +++ b/tests/fn_oftype.json @@ -1,148 +1,148 @@ { - "title": "fn_oftype", - "description": "TBD", - "resources": [ - { - "resourceType": "Observation", - "id": "o1", - "code": { - "text": "code" - }, - "status": "final", - "valueString": "foo" - }, - { - "resourceType": "Observation", - "id": "o2", - "code": { - "text": "code" - }, - "status": "final", - "valueInteger": 42 - }, - { - "resourceType": "Observation", - "id": "o3", - "code": { - "text": "code" - }, - "status": "final" - } - ], - "tests": [ - { - "title": "select string values", - "view": { - "resource": "Observation", - "status": "active", - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - }, - { - "path": "value.ofType(string)", - "name": "string_value" - } - ] - } - ] - }, - "expect": [ + "title": "fn_oftype", + "description": "TBD", + "resources": [ { - "id": "o1", - "string_value": "foo" + "resourceType": "Observation", + "id": "o1", + "code": { + "text": "code" + }, + "status": "final", + "valueString": "foo" }, { - "id": "o2", - "string_value": null + "resourceType": "Observation", + "id": "o2", + "code": { + "text": "code" + }, + "status": "final", + "valueInteger": 42 }, { - "id": "o3", - "string_value": null + "resourceType": "Observation", + "id": "o3", + "code": { + "text": "code" + }, + "status": "final" } - ] - }, - { - "title": "select integer values", - "view": { - "resource": "Observation", - "status": "active", - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - }, - { - "path": "value.ofType(integer)", - "name": "integer_value" - } + ], + "tests": [ + { + "title": "select string values", + "view": { + "resource": "Observation", + "status": "active", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + }, + { + "path": "value.ofType(string)", + "name": "string_value" + } + ] + } + ] + }, + "expect": [ + { + "id": "o1", + "string_value": "foo" + }, + { + "id": "o2", + "string_value": null + }, + { + "id": "o3", + "string_value": null + } ] - } - ] - }, - "expect": [ + }, { - "id": "o1", - "integer_value": null + "title": "select integer values", + "view": { + "resource": "Observation", + "status": "active", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + }, + { + "path": "value.ofType(integer)", + "name": "integer_value" + } + ] + } + ] + }, + "expect": [ + { + "id": "o1", + "integer_value": null + }, + { + "id": "o2", + "integer_value": 42 + }, + { + "id": "o3", + "integer_value": null + } + ] }, { - "id": "o2", - "integer_value": 42 + "title": "select invalid type", + "view": { + "resource": "Observation", + "status": "active", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + }, + { + "path": "value.ofType(Invalid)", + "name": "invalid_value" + } + ] + } + ] + }, + "expectError": true }, { - "id": "o3", - "integer_value": null + "title": "invalid argument type", + "view": { + "resource": "Observation", + "status": "active", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + }, + { + "path": "value.ofType(42)", + "name": "invalid_argument" + } + ] + } + ] + }, + "expectError": true } - ] - }, - { - "title": "select invalid type", - "view": { - "resource": "Observation", - "status": "active", - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - }, - { - "path": "value.ofType(Invalid)", - "name": "invalid_value" - } - ] - } - ] - }, - "expectError": true - }, - { - "title": "invalid argument type", - "view": { - "resource": "Observation", - "status": "active", - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - }, - { - "path": "value.ofType(42)", - "name": "invalid_argument" - } - ] - } - ] - }, - "expectError": true - } - ] -} \ No newline at end of file + ] +} diff --git a/tests/foreach.json b/tests/foreach.json index 94b52da..9834508 100644 --- a/tests/foreach.json +++ b/tests/foreach.json @@ -1,332 +1,780 @@ { - "title": "foreach", - "description": "TBD", - "resources": [ - { - "resourceType": "Patient", - "id": "pt1", - "name": [ + "title": "foreach", + "description": "TBD", + "resources": [ { - "family": "F1.1" - }, - { - "family": "F1.2" - } - ], - "contact": [ - { - "telecom": [ - { - "system": "phone" - } - ], - "name": { - "given": [ - "N1", - "N1`" + "resourceType": "Patient", + "id": "pt1", + "name": [ + { + "family": "F1.1" + }, + { + "family": "F1.2" + } + ], + "contact": [ + { + "telecom": [ + { + "system": "phone" + } + ], + "name": { + "family": "FC1.1", + "given": ["N1", "N1`"] + } + }, + { + "telecom": [ + { + "system": "email" + } + ], + "gender": "unknown", + "name": { + "family": "FC1.2", + "given": ["N2"] + } + } ] - } }, { - "telecom": [ - { - "system": "email" - } - ], - "name": { - "given": [ - "N2" + "resourceType": "Patient", + "id": "pt2", + "name": [ + { + "family": "F2.1" + }, + { + "family": "F2.2" + } ] - } - } - ] - }, - { - "resourceType": "Patient", - "id": "pt2", - "name": [ - { - "family": "F2.1" }, { - "family": "F2.2" + "resourceType": "Patient", + "id": "pt3" } - ] - }, - { - "resourceType": "Patient", - "id": "pt3" - } - ], - "tests": [ - { - "title": "forEach: normal", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - }, - { - "forEach": "name", - "column": [ - { - "name": "family", - "path": "family" - } - ] - } - ] - }, - "expect": [ + ], + "tests": [ { - "id": "pt1", - "family": "F1.1" + "title": "forEach: normal", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "forEach": "name", + "column": [ + { + "name": "family", + "path": "family" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "family": "F1.1" + }, + { + "id": "pt1", + "family": "F1.2" + }, + { + "id": "pt2", + "family": "F2.1" + }, + { + "id": "pt2", + "family": "F2.2" + } + ] }, { - "id": "pt1", - "family": "F1.2" + "title": "forEachOrNull: basic", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "forEachOrNull": "name", + "column": [ + { + "name": "family", + "path": "family" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "family": "F1.1" + }, + { + "id": "pt1", + "family": "F1.2" + }, + { + "id": "pt2", + "family": "F2.1" + }, + { + "id": "pt2", + "family": "F2.2" + }, + { + "id": "pt3", + "family": null + } + ] }, { - "id": "pt2", - "family": "F2.1" + "title": "forEach: empty", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "forEach": "identifier", + "column": [ + { + "name": "value", + "path": "value" + } + ] + } + ] + }, + "expect": [] }, { - "id": "pt2", - "family": "F2.2" - } - ] - }, - { - "title": "forEachOrNull: normal", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - }, - { - "forEachOrNull": "name", - "column": [ - { - "name": "family", - "path": "family" - } + "title": "forEach: two on the same level", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "forEach": "contact", + "column": [ + { + "name": "cont_family", + "path": "name.family" + } + ] + }, + { + "forEach": "name", + "column": [ + { + "name": "pat_family", + "path": "family" + } + ] + } + ] + }, + "expect": [ + { + "pat_family": "F1.1", + "cont_family": "FC1.1" + }, + { + "pat_family": "F1.1", + "cont_family": "FC1.2" + }, + { + "pat_family": "F1.2", + "cont_family": "FC1.1" + }, + { + "pat_family": "F1.2", + "cont_family": "FC1.2" + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "family": "F1.1" }, { - "id": "pt1", - "family": "F1.2" - }, - { - "id": "pt2", - "family": "F2.1" + "title": "forEach: two on the same level (empty result)", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "forEach": "identifier", + "column": [ + { + "name": "value", + "path": "value" + } + ] + }, + { + "forEach": "name", + "column": [ + { + "name": "family", + "path": "family" + } + ] + } + ] + }, + "expect": [] }, { - "id": "pt2", - "family": "F2.2" + "title": "forEachOrNull: null case", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "forEachOrNull": "identifier", + "column": [ + { + "name": "value", + "path": "value" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "value": null + }, + { + "id": "pt2", + "value": null + }, + { + "id": "pt3", + "value": null + } + ] }, { - "id": "pt3", - "family": null - } - ] - }, - { - "title": "forEach: empty", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - }, - { - "forEach": "identifier", - "column": [ - { - "name": "value", - "path": "value" - } - ] - } - ] - }, - "expect": [] - }, - { - "title": "forEachOrNull: null case", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - }, - { - "forEachOrNull": "identifier", - "column": [ - { - "name": "value", - "path": "value" - } + "title": "forEach and forEachOrNull on the same level", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "forEachOrNull": "identifier", + "column": [ + { + "name": "value", + "path": "value" + } + ] + }, + { + "forEach": "name", + "column": [ + { + "name": "family", + "path": "family" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "family": "F1.1", + "value": null + }, + { + "id": "pt1", + "family": "F1.2", + "value": null + }, + { + "id": "pt2", + "family": "F2.1", + "value": null + }, + { + "id": "pt2", + "family": "F2.2", + "value": null + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "value": null }, { - "id": "pt2", - "value": null + "title": "nested forEach", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "forEach": "contact", + "select": [ + { + "column": [ + { + "name": "contact_type", + "path": "telecom.system" + } + ] + }, + { + "forEach": "name.given", + "column": [ + { + "name": "name", + "path": "$this" + } + ] + } + ] + } + ] + }, + "expect": [ + { + "contact_type": "phone", + "name": "N1", + "id": "pt1" + }, + { + "contact_type": "phone", + "name": "N1`", + "id": "pt1" + }, + { + "contact_type": "email", + "name": "N2", + "id": "pt1" + } + ] }, { - "id": "pt3", - "value": null - } - ] - }, - { - "title": "nested forEach", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - }, - { - "forEach": "contact", - "select": [ - { - "column": [ - { - "name": "contact_type", - "path": "telecom.system" - } - ] - }, - { - "forEach": "name.given", - "column": [ - { - "name": "name", - "path": "$this" - } + "title": "nested forEach: select & column", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "forEach": "contact", + "column": [ + { + "name": "contact_type", + "path": "telecom.system" + } + ], + "select": [ + { + "forEach": "name.given", + "column": [ + { + "name": "name", + "path": "$this" + } + ] + } + ] + } ] - } + }, + "expect": [ + { + "contact_type": "phone", + "name": "N1", + "id": "pt1" + }, + { + "contact_type": "phone", + "name": "N1`", + "id": "pt1" + }, + { + "contact_type": "email", + "name": "N2", + "id": "pt1" + } ] - } - ] - }, - "expect": [ - { - "contact_type": "phone", - "name": "N1", - "id": "pt1" }, { - "contact_type": "phone", - "name": "N1`", - "id": "pt1" + "title": "forEachOrNull & unionAll on the same level", + "view": { + "resource": "Patient", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + } + ] + }, + { + "forEachOrNull": "contact", + "unionAll": [ + { + "column": [ + { + "path": "name.family", + "name": "name" + } + ] + }, + { + "forEach": "name.given", + "column": [ + { + "path": "$this", + "name": "name" + } + ] + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "name": "FC1.1" + }, + { + "id": "pt1", + "name": "N1" + }, + { + "id": "pt1", + "name": "N1`" + }, + { + "id": "pt1", + "name": "FC1.2" + }, + { + "id": "pt1", + "name": "N2" + }, + { + "id": "pt2", + "name": null + }, + { + "id": "pt3", + "name": null + } + ] }, { - "contact_type": "email", - "name": "N2", - "id": "pt1" - } - ] - }, - { - "title": "nested forEach: select & column", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - }, - { - "forEach": "contact", - "column": [ - { - "name": "contact_type", - "path": "telecom.system" - } - ], - "select": [ - { - "forEach": "name.given", - "column": [ - { - "name": "name", - "path": "$this" - } + "title": "forEach & unionAll on the same level", + "view": { + "resource": "Patient", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + } + ] + }, + { + "forEach": "contact", + "unionAll": [ + { + "column": [ + { + "path": "name.family", + "name": "name" + } + ] + }, + { + "forEach": "name.given", + "column": [ + { + "path": "$this", + "name": "name" + } + ] + } + ] + } ] - } + }, + "expect": [ + { + "id": "pt1", + "name": "FC1.1" + }, + { + "id": "pt1", + "name": "N1" + }, + { + "id": "pt1", + "name": "N1`" + }, + { + "id": "pt1", + "name": "FC1.2" + }, + { + "id": "pt1", + "name": "N2" + } ] - } - ] - }, - "expect": [ - { - "contact_type": "phone", - "name": "N1", - "id": "pt1" }, { - "contact_type": "phone", - "name": "N1`", - "id": "pt1" + "title": "forEach & unionAll & column & select on the same level", + "view": { + "resource": "Patient", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + } + ] + }, + { + "forEach": "contact", + "column": [ + { + "path": "telecom.system", + "name": "tel_system" + } + ], + "select": [ + { + "column": [ + { + "path": "gender", + "name": "gender" + } + ] + } + ], + "unionAll": [ + { + "column": [ + { + "path": "name.family", + "name": "name" + } + ] + }, + { + "forEach": "name.given", + "column": [ + { + "path": "$this", + "name": "name" + } + ] + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "name": "FC1.1", + "tel_system": "phone", + "gender": null + }, + { + "id": "pt1", + "name": "N1", + "tel_system": "phone", + "gender": null + }, + { + "id": "pt1", + "name": "N1`", + "tel_system": "phone", + "gender": null + }, + { + "id": "pt1", + "name": "FC1.2", + "tel_system": "email", + "gender": "unknown" + }, + { + "id": "pt1", + "name": "N2", + "tel_system": "email", + "gender": "unknown" + } + ] }, { - "contact_type": "email", - "name": "N2", - "id": "pt1" + "title": "forEachOrNull & unionAll & column & select on the same level", + "view": { + "resource": "Patient", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + } + ] + }, + { + "forEachOrNull": "contact", + "column": [ + { + "path": "telecom.system", + "name": "tel_system" + } + ], + "select": [ + { + "column": [ + { + "path": "gender", + "name": "gender" + } + ] + } + ], + "unionAll": [ + { + "column": [ + { + "path": "name.family", + "name": "name" + } + ] + }, + { + "forEach": "name.given", + "column": [ + { + "path": "$this", + "name": "name" + } + ] + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1", + "name": "FC1.1", + "tel_system": "phone", + "gender": null + }, + { + "id": "pt1", + "name": "N1", + "tel_system": "phone", + "gender": null + }, + { + "id": "pt1", + "name": "N1`", + "tel_system": "phone", + "gender": null + }, + { + "id": "pt1", + "name": "FC1.2", + "tel_system": "email", + "gender": "unknown" + }, + { + "id": "pt1", + "name": "N2", + "tel_system": "email", + "gender": "unknown" + }, + { + "id": "pt2", + "name": null, + "tel_system": null, + "gender": null + }, + { + "id": "pt3", + "name": null, + "tel_system": null, + "gender": null + } + ] } - ] - } - ] -} \ No newline at end of file + ] +} diff --git a/tests/union.json b/tests/union.json index 6339c79..82f10e7 100644 --- a/tests/union.json +++ b/tests/union.json @@ -1,735 +1,790 @@ { - "title": "union", - "description": "TBD", - "resources": [ - { - "resourceType": "Patient", - "id": "pt1", - "telecom": [ - { - "value": "t1.1", - "system": "s1.1" - }, - { - "value": "t1.2", - "system": "s1.2" + "title": "union", + "description": "TBD", + "resources": [ + { + "resourceType": "Patient", + "id": "pt1", + "telecom": [ + { + "value": "t1.1", + "system": "s1.1" + }, + { + "value": "t1.2", + "system": "s1.2" + }, + { + "value": "t1.3", + "system": "s1.3" + } + ], + "contact": [ + { + "telecom": [ + { + "value": "t1.c1.1", + "system": "s1.c1.1" + } + ] + }, + { + "telecom": [ + { + "value": "t1.c2.1", + "system": "s1.c2.1" + }, + { + "value": "t1.c2.2", + "system": "s1.c2.2" + } + ] + } + ] }, { - "value": "t1.3", - "system": "s1.3" - } - ], - "contact": [ - { - "telecom": [ - { - "value": "t1.c1.1", - "system": "s1.c1.1" - } - ] + "resourceType": "Patient", + "id": "pt2", + "telecom": [ + { + "value": "t2.1", + "system": "s2.1" + }, + { + "value": "t2.2", + "system": "s2.2" + } + ] }, { - "telecom": [ - { - "value": "t1.c2.1", - "system": "s1.c2.1" - }, - { - "value": "t1.c2.2", - "system": "s1.c2.2" - } - ] - } - ] - }, - { - "resourceType": "Patient", - "id": "pt2", - "telecom": [ - { - "value": "t2.1", - "system": "s2.1" + "resourceType": "Patient", + "id": "pt3", + "contact": [ + { + "telecom": [ + { + "value": "t3.c1.1", + "system": "s3.c1.1" + }, + { + "value": "t3.c1.2", + "system": "s3.c1.2" + } + ] + }, + { + "telecom": [ + { + "value": "t3.c2.1", + "system": "s3.c2.1" + } + ] + } + ] }, { - "value": "t2.2", - "system": "s2.2" + "resourceType": "Patient", + "id": "pt4" } - ] - }, - { - "resourceType": "Patient", - "id": "pt3", - "contact": [ - { - "telecom": [ - { - "value": "t3.c1.1", - "system": "s3.c1.1" + ], + "tests": [ + { + "title": "basic", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "unionAll": [ + { + "forEach": "telecom", + "column": [ + { + "name": "tel", + "path": "value" + }, + { + "name": "sys", + "path": "system" + } + ] + }, + { + "forEach": "contact.telecom", + "column": [ + { + "name": "tel", + "path": "value" + }, + { + "name": "sys", + "path": "system" + } + ] + } + ] + } + ] }, - { - "value": "t3.c1.2", - "system": "s3.c1.2" - } - ] + "expect": [ + { + "tel": "t1.1", + "sys": "s1.1", + "id": "pt1" + }, + { + "tel": "t1.2", + "sys": "s1.2", + "id": "pt1" + }, + { + "tel": "t1.3", + "sys": "s1.3", + "id": "pt1" + }, + { + "tel": "t1.c1.1", + "sys": "s1.c1.1", + "id": "pt1" + }, + { + "tel": "t1.c2.1", + "sys": "s1.c2.1", + "id": "pt1" + }, + { + "tel": "t1.c2.2", + "sys": "s1.c2.2", + "id": "pt1" + }, + { + "tel": "t2.1", + "sys": "s2.1", + "id": "pt2" + }, + { + "tel": "t2.2", + "sys": "s2.2", + "id": "pt2" + }, + { + "tel": "t3.c1.1", + "sys": "s3.c1.1", + "id": "pt3" + }, + { + "tel": "t3.c1.2", + "sys": "s3.c1.2", + "id": "pt3" + }, + { + "tel": "t3.c2.1", + "sys": "s3.c2.1", + "id": "pt3" + } + ] }, { - "telecom": [ - { - "value": "t3.c2.1", - "system": "s3.c2.1" - } - ] - } - ] - }, - { - "resourceType": "Patient", - "id": "pt4" - } - ], - "tests": [ - { - "title": "basic", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - }, - { - "unionAll": [ - { - "forEach": "telecom", - "column": [ - { - "name": "tel", - "path": "value" - }, - { - "name": "sys", - "path": "system" - } + "title": "unionAll + column", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ], + "unionAll": [ + { + "forEach": "telecom", + "column": [ + { + "name": "tel", + "path": "value" + }, + { + "name": "sys", + "path": "system" + } + ] + }, + { + "forEach": "contact.telecom", + "column": [ + { + "name": "tel", + "path": "value" + }, + { + "name": "sys", + "path": "system" + } + ] + } + ] + } ] - }, - { - "forEach": "contact.telecom", - "column": [ - { - "name": "tel", - "path": "value" - }, - { - "name": "sys", - "path": "system" - } - ] - } + }, + "expect": [ + { + "tel": "t1.1", + "sys": "s1.1", + "id": "pt1" + }, + { + "tel": "t1.2", + "sys": "s1.2", + "id": "pt1" + }, + { + "tel": "t1.3", + "sys": "s1.3", + "id": "pt1" + }, + { + "tel": "t1.c1.1", + "sys": "s1.c1.1", + "id": "pt1" + }, + { + "tel": "t1.c2.1", + "sys": "s1.c2.1", + "id": "pt1" + }, + { + "tel": "t1.c2.2", + "sys": "s1.c2.2", + "id": "pt1" + }, + { + "tel": "t2.1", + "sys": "s2.1", + "id": "pt2" + }, + { + "tel": "t2.2", + "sys": "s2.2", + "id": "pt2" + }, + { + "tel": "t3.c1.1", + "sys": "s3.c1.1", + "id": "pt3" + }, + { + "tel": "t3.c1.2", + "sys": "s3.c1.2", + "id": "pt3" + }, + { + "tel": "t3.c2.1", + "sys": "s3.c2.1", + "id": "pt3" + } ] - } - ] - }, - "expect": [ - { - "tel": "t1.1", - "sys": "s1.1", - "id": "pt1" - }, - { - "tel": "t1.2", - "sys": "s1.2", - "id": "pt1" - }, - { - "tel": "t1.3", - "sys": "s1.3", - "id": "pt1" - }, - { - "tel": "t1.c1.1", - "sys": "s1.c1.1", - "id": "pt1" - }, - { - "tel": "t1.c2.1", - "sys": "s1.c2.1", - "id": "pt1" - }, - { - "tel": "t1.c2.2", - "sys": "s1.c2.2", - "id": "pt1" - }, - { - "tel": "t2.1", - "sys": "s2.1", - "id": "pt2" }, { - "tel": "t2.2", - "sys": "s2.2", - "id": "pt2" - }, - { - "tel": "t3.c1.1", - "sys": "s3.c1.1", - "id": "pt3" - }, - { - "tel": "t3.c1.2", - "sys": "s3.c1.2", - "id": "pt3" - }, - { - "tel": "t3.c2.1", - "sys": "s3.c2.1", - "id": "pt3" - } - ] - }, - { - "title": "unionAll + column", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ], - "unionAll": [ - { - "forEach": "telecom", - "column": [ - { - "name": "tel", - "path": "value" - }, - { - "name": "sys", - "path": "system" - } - ] - }, - { - "forEach": "contact.telecom", - "column": [ - { - "name": "tel", - "path": "value" - }, - { - "name": "sys", - "path": "system" - } + "title": "duplicates", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ], + "unionAll": [ + { + "forEach": "telecom", + "column": [ + { + "name": "tel", + "path": "value" + }, + { + "name": "sys", + "path": "system" + } + ] + }, + { + "forEach": "telecom", + "column": [ + { + "name": "tel", + "path": "value" + }, + { + "name": "sys", + "path": "system" + } + ] + } + ] + } ] - } + }, + "expect": [ + { + "tel": "t1.1", + "sys": "s1.1", + "id": "pt1" + }, + { + "tel": "t1.2", + "sys": "s1.2", + "id": "pt1" + }, + { + "tel": "t1.3", + "sys": "s1.3", + "id": "pt1" + }, + { + "tel": "t1.1", + "sys": "s1.1", + "id": "pt1" + }, + { + "tel": "t1.2", + "sys": "s1.2", + "id": "pt1" + }, + { + "tel": "t1.3", + "sys": "s1.3", + "id": "pt1" + }, + { + "tel": "t2.1", + "sys": "s2.1", + "id": "pt2" + }, + { + "tel": "t2.2", + "sys": "s2.2", + "id": "pt2" + }, + { + "tel": "t2.1", + "sys": "s2.1", + "id": "pt2" + }, + { + "tel": "t2.2", + "sys": "s2.2", + "id": "pt2" + } ] - } - ] - }, - "expect": [ - { - "tel": "t1.1", - "sys": "s1.1", - "id": "pt1" - }, - { - "tel": "t1.2", - "sys": "s1.2", - "id": "pt1" - }, - { - "tel": "t1.3", - "sys": "s1.3", - "id": "pt1" - }, - { - "tel": "t1.c1.1", - "sys": "s1.c1.1", - "id": "pt1" - }, - { - "tel": "t1.c2.1", - "sys": "s1.c2.1", - "id": "pt1" - }, - { - "tel": "t1.c2.2", - "sys": "s1.c2.2", - "id": "pt1" - }, - { - "tel": "t2.1", - "sys": "s2.1", - "id": "pt2" - }, - { - "tel": "t2.2", - "sys": "s2.2", - "id": "pt2" - }, - { - "tel": "t3.c1.1", - "sys": "s3.c1.1", - "id": "pt3" }, { - "tel": "t3.c1.2", - "sys": "s3.c1.2", - "id": "pt3" - }, - { - "tel": "t3.c2.1", - "sys": "s3.c2.1", - "id": "pt3" - } - ] - }, - { - "title": "duplicates", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ], - "unionAll": [ - { - "forEach": "telecom", - "column": [ - { - "name": "tel", - "path": "value" - }, - { - "name": "sys", - "path": "system" - } + "title": "empty results", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ], + "unionAll": [ + { + "forEach": "name", + "column": [ + { + "name": "given", + "path": "given" + } + ] + }, + { + "forEach": "name", + "column": [ + { + "name": "given", + "path": "given" + } + ] + } + ] + } ] - }, - { - "forEach": "telecom", - "column": [ - { - "name": "tel", - "path": "value" - }, - { - "name": "sys", - "path": "system" - } + }, + "expect": [] + }, + { + "title": "empty with forEachOrNull", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ], + "unionAll": [ + { + "forEachOrNull": "name", + "column": [ + { + "name": "given", + "path": "given" + } + ] + }, + { + "forEachOrNull": "name", + "column": [ + { + "name": "given", + "path": "given" + } + ] + } + ] + } ] - } + }, + "expect": [ + { + "given": null, + "id": "pt1" + }, + { + "given": null, + "id": "pt1" + }, + { + "given": null, + "id": "pt2" + }, + { + "given": null, + "id": "pt2" + }, + { + "given": null, + "id": "pt3" + }, + { + "given": null, + "id": "pt3" + }, + { + "given": null, + "id": "pt4" + }, + { + "given": null, + "id": "pt4" + } ] - } - ] - }, - "expect": [ - { - "tel": "t1.1", - "sys": "s1.1", - "id": "pt1" - }, - { - "tel": "t1.2", - "sys": "s1.2", - "id": "pt1" }, { - "tel": "t1.3", - "sys": "s1.3", - "id": "pt1" - }, - { - "tel": "t1.1", - "sys": "s1.1", - "id": "pt1" - }, - { - "tel": "t1.2", - "sys": "s1.2", - "id": "pt1" - }, - { - "tel": "t1.3", - "sys": "s1.3", - "id": "pt1" - }, - { - "tel": "t2.1", - "sys": "s2.1", - "id": "pt2" - }, - { - "tel": "t2.2", - "sys": "s2.2", - "id": "pt2" - }, - { - "tel": "t2.1", - "sys": "s2.1", - "id": "pt2" - }, - { - "tel": "t2.2", - "sys": "s2.2", - "id": "pt2" - } - ] - }, - { - "title": "empty results", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ], - "unionAll": [ - { - "forEach": "name", - "column": [ - { - "name": "given", - "path": "given" - } - ] - }, - { - "forEach": "name", - "column": [ - { - "name": "given", - "path": "given" - } - ] - } - ] - } - ] - }, - "expect": [] - }, - { - "title": "empty with forEachOrNull", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ], - "unionAll": [ - { - "forEachOrNull": "name", - "column": [ - { - "name": "given", - "path": "given" - } - ] - }, - { - "forEachOrNull": "name", - "column": [ - { - "name": "given", - "path": "given" - } + "title": "forEachOrNull and forEach", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ], + "unionAll": [ + { + "forEach": "name", + "column": [ + { + "name": "given", + "path": "given" + } + ] + }, + { + "forEachOrNull": "name", + "column": [ + { + "name": "given", + "path": "given" + } + ] + } + ] + } ] - } + }, + "expect": [ + { + "given": null, + "id": "pt1" + }, + { + "given": null, + "id": "pt2" + }, + { + "given": null, + "id": "pt3" + }, + { + "given": null, + "id": "pt4" + } ] - } - ] - }, - "expect": [ - { - "given": null, - "id": "pt1" - }, - { - "given": null, - "id": "pt1" - }, - { - "given": null, - "id": "pt2" }, { - "given": null, - "id": "pt2" - }, - { - "given": null, - "id": "pt3" - }, - { - "given": null, - "id": "pt3" - }, - { - "given": null, - "id": "pt4" - }, - { - "given": null, - "id": "pt4" - } - ] - }, - { - "title": "nested", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ], - "unionAll": [ - { - "forEach": "telecom[0]", - "column": [ - { - "name": "tel", - "path": "value" - } + "title": "nested", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ], + "unionAll": [ + { + "forEach": "telecom[0]", + "column": [ + { + "name": "tel", + "path": "value" + } + ] + }, + { + "unionAll": [ + { + "forEach": "telecom[0]", + "column": [ + { + "name": "tel", + "path": "value" + } + ] + }, + { + "forEach": "contact.telecom[0]", + "column": [ + { + "name": "tel", + "path": "value" + } + ] + } + ] + } + ] + } ] - }, - { - "unionAll": [ - { - "forEach": "telecom[0]", - "column": [ - { - "name": "tel", - "path": "value" - } - ] - }, - { - "forEach": "contact.telecom[0]", - "column": [ - { - "name": "tel", - "path": "value" - } - ] - } - ] - } + }, + "expect": [ + { + "id": "pt1", + "tel": "t1.1" + }, + { + "id": "pt1", + "tel": "t1.1" + }, + { + "id": "pt1", + "tel": "t1.c1.1" + }, + { + "id": "pt2", + "tel": "t2.1" + }, + { + "id": "pt2", + "tel": "t2.1" + }, + { + "id": "pt3", + "tel": "t3.c1.1" + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "tel": "t1.1" - }, - { - "id": "pt1", - "tel": "t1.1" - }, - { - "id": "pt1", - "tel": "t1.c1.1" - }, - { - "id": "pt2", - "tel": "t2.1" - }, - { - "id": "pt2", - "tel": "t2.1" }, { - "id": "pt3", - "tel": "t3.c1.1" - } - ] - }, - { - "title": "one empty operand", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "name": "id", - "path": "id" - } - ] - }, - { - "unionAll": [ - { - "forEach": "telecom.where(false)", - "column": [ - { - "name": "tel", - "path": "value" - }, - { - "name": "sys", - "path": "system" - } + "title": "one empty operand", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + } + ] + }, + { + "unionAll": [ + { + "forEach": "telecom.where(false)", + "column": [ + { + "name": "tel", + "path": "value" + }, + { + "name": "sys", + "path": "system" + } + ] + }, + { + "forEach": "contact.telecom", + "column": [ + { + "name": "tel", + "path": "value" + }, + { + "name": "sys", + "path": "system" + } + ] + } + ] + } ] - }, - { - "forEach": "contact.telecom", - "column": [ - { - "name": "tel", - "path": "value" - }, - { - "name": "sys", - "path": "system" - } - ] - } + }, + "expect": [ + { + "id": "pt1", + "sys": "s1.c1.1", + "tel": "t1.c1.1" + }, + { + "id": "pt1", + "sys": "s1.c2.1", + "tel": "t1.c2.1" + }, + { + "id": "pt1", + "sys": "s1.c2.2", + "tel": "t1.c2.2" + }, + { + "id": "pt3", + "sys": "s3.c1.1", + "tel": "t3.c1.1" + }, + { + "id": "pt3", + "sys": "s3.c1.2", + "tel": "t3.c1.2" + }, + { + "id": "pt3", + "sys": "s3.c2.1", + "tel": "t3.c2.1" + } ] - } - ] - }, - "expect": [ - { - "id": "pt1", - "sys": "s1.c1.1", - "tel": "t1.c1.1" - }, - { - "id": "pt1", - "sys": "s1.c2.1", - "tel": "t1.c2.1" - }, - { - "id": "pt1", - "sys": "s1.c2.2", - "tel": "t1.c2.2" - }, - { - "id": "pt3", - "sys": "s3.c1.1", - "tel": "t3.c1.1" - }, - { - "id": "pt3", - "sys": "s3.c1.2", - "tel": "t3.c1.2" }, { - "id": "pt3", - "sys": "s3.c2.1", - "tel": "t3.c2.1" - } - ] - }, - { - "title": "column mismatch", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "unionAll": [ - { - "column": [ - { - "name": "a", - "path": "a" - }, - { - "name": "b", - "path": "b" - } - ] - }, - { - "column": [ - { - "name": "a", - "path": "a" - }, - { - "name": "c", - "path": "c" - } - ] - } - ] - } - ] - }, - "expectError": true - }, - { - "title": "column order mismatch", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "unionAll": [ - { - "column": [ - { - "name": "a", - "path": "a" - }, - { - "name": "b", - "path": "b" - } + "title": "column mismatch", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "unionAll": [ + { + "column": [ + { + "name": "a", + "path": "a" + }, + { + "name": "b", + "path": "b" + } + ] + }, + { + "column": [ + { + "name": "a", + "path": "a" + }, + { + "name": "c", + "path": "c" + } + ] + } + ] + } ] - }, - { - "column": [ - { - "name": "b", - "path": "b" - }, - { - "name": "a", - "path": "a" - } + }, + "expectError": true + }, + { + "title": "column order mismatch", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "unionAll": [ + { + "column": [ + { + "name": "a", + "path": "a" + }, + { + "name": "b", + "path": "b" + } + ] + }, + { + "column": [ + { + "name": "b", + "path": "b" + }, + { + "name": "a", + "path": "a" + } + ] + } + ] + } ] - } - ] - } - ] - }, - "expectError": true - } - ] -} \ No newline at end of file + }, + "expectError": true + } + ] +} diff --git a/tests/validate.json b/tests/validate.json index f717356..141523c 100644 --- a/tests/validate.json +++ b/tests/validate.json @@ -1,47 +1,47 @@ { - "title": "validate", - "description": "TBD", - "resources": [ - { - "resourceType": "Patient", - "id": "pt1" - }, - { - "resourceType": "Patient", - "id": "pt2" - } - ], - "tests": [ - { - "title": "empty", - "view": {}, - "error": "structure" - }, - { - "title": "wrong fhirpath", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "forEach": "@@" - } - ] - }, - "error": "fhirpath" - }, - { - "title": "wrong type", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "forEach": 1 - } - ] - }, - "error": "structure" - } - ] -} \ No newline at end of file + "title": "validate", + "description": "TBD", + "resources": [ + { + "resourceType": "Patient", + "id": "pt1" + }, + { + "resourceType": "Patient", + "id": "pt2" + } + ], + "tests": [ + { + "title": "empty", + "view": {}, + "error": "structure" + }, + { + "title": "wrong fhirpath", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "forEach": "@@" + } + ] + }, + "error": "fhirpath" + }, + { + "title": "wrong type", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "forEach": 1 + } + ] + }, + "error": "structure" + } + ] +} diff --git a/tests/view_resource.json b/tests/view_resource.json index 73ab73f..b773692 100644 --- a/tests/view_resource.json +++ b/tests/view_resource.json @@ -1,88 +1,88 @@ { - "title": "view_resource", - "description": "TBD", - "resources": [ - { - "id": "pt1", - "resourceType": "Patient" - }, - { - "id": "pt2", - "resourceType": "Patient" - }, - { - "id": "ob1", - "resourceType": "Observation", - "code": { - "text": "code" - }, - "status": "final" - } - ], - "tests": [ - { - "title": "only pts", - "view": { - "resource": "Patient", - "status": "active", - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - } - ] - } - ] - }, - "expect": [ + "title": "view_resource", + "description": "TBD", + "resources": [ + { + "id": "pt1", + "resourceType": "Patient" + }, { - "id": "pt1" + "id": "pt2", + "resourceType": "Patient" }, { - "id": "pt2" + "id": "ob1", + "resourceType": "Observation", + "code": { + "text": "code" + }, + "status": "final" } - ] - }, - { - "title": "only obs", - "view": { - "resource": "Observation", - "status": "active", - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - } + ], + "tests": [ + { + "title": "only pts", + "view": { + "resource": "Patient", + "status": "active", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + } + ] + } + ] + }, + "expect": [ + { + "id": "pt1" + }, + { + "id": "pt2" + } ] - } - ] - }, - "expect": [ + }, { - "id": "ob1" - } - ] - }, - { - "title": "resource not specified", - "view": { - "status": "active", - "select": [ - { - "column": [ - { - "path": "id", - "name": "id" - } + "title": "only obs", + "view": { + "resource": "Observation", + "status": "active", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + } + ] + } + ] + }, + "expect": [ + { + "id": "ob1" + } ] - } - ] - }, - "expectError": true - } - ] -} \ No newline at end of file + }, + { + "title": "resource not specified", + "view": { + "status": "active", + "select": [ + { + "column": [ + { + "path": "id", + "name": "id" + } + ] + } + ] + }, + "expectError": true + } + ] +}