Skip to content

Commit 9d11102

Browse files
Merge remote-tracking branch 'nlm/master' into bugfix/ts-import
2 parents ae5efe3 + ad1b3c8 commit 9d11102

File tree

14 files changed

+309
-114
lines changed

14 files changed

+309
-114
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
This log documents significant changes for each release. This project follows
44
[Semantic Versioning](http://semver.org/).
55

6+
## [2.6.0] - 2020-09-01
7+
### Added
8+
Limited support for types (see README.md for details):
9+
- Function is(type) and operator "is"
10+
- Function ofType(type)
11+
612
## [2.5.0] - 2020-08-26
713
### Added
814
- Function union(other: collection)

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ some behavior may still be following the previous version, STU1.
125125
The core parser was generated from the FHIRPath ANTLR grammar.
126126

127127
Completed sections:
128-
- 3 (Path selection) - except that "is" and "as" are not supported yet
128+
- 3 (Path selection)
129129
- 5.1 (Existence)
130-
- 5.2 (Filtering and Projection) "ofType" - basic support for primitives
130+
- 5.2 (Filtering and Projection) "ofType" - limited support for types (see below)
131131
- 5.3 (Subsetting)
132132
- 5.4 (Combining)
133133
- 5.6 (String Manipulation)
@@ -149,13 +149,23 @@ Almost completed sections:
149149
We are deferring handling information about FHIR resources, as much as
150150
possible, with the exception of support for choice types. This affects
151151
implementation of the following sections:
152-
- 6.3 (Types) - deferred
152+
- 6.3 (Types) - "is" - limited support for types(see below),
153+
"as" is not supported yet
153154

154155
Also, because in JSON DateTime and Time types are represented as strings, if a
155156
string in a resource looks like a DateTime or Time (matches the regular
156157
expression defined for those types in FHIR), the string will be interpreted as a
157158
DateTime or Time.
158159

160+
### Limited support for types:
161+
Currently, the type of the resource property value is used to determine the type,
162+
without using the FHIR specification. This shortcut causes the following issues:
163+
- Type hierarchy is not supported;
164+
- FHIR.uri, FHIR.code, FHIR.oid, FHIR.id, FHIR.uuid, FHIR.sid, FHIR.markdown, FHIR.base64Binary are treated as FHIR.string;
165+
- FHIR.unsignedInt, FHIR.positiveInt are treated as FHIR.integer;
166+
- Also, a property could be specified as FHIR.decimal, but treated as FHIR.integer;
167+
- For date-time related types, only FHIR.dateTime, FHIR.time, System.DateTime and System.Time are supported.
168+
159169
## Development Notes
160170

161171
This section is for people doing development on this package (as opposed to

converter/bin/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const sourceDir = __dirname + '/../dataset/';
55
// Directory for converter output(for YAML and JSON files)
66
const destDir = __dirname + '/../../test/';
77

8+
// FHIR model used for test cases
9+
const model = 'r4';
810
// Descriptions for file generation:
911
// [<relative path to XML source file>, <relative path to YAML/JSON output file>, <download URL>]
1012
const sources = [
@@ -64,7 +66,7 @@ commander
6466

6567
for (let i = 0; i < testFiles.length; i++) {
6668
const [xmlFilename, yamlFilename] = testFiles[i];
67-
await convert.testsXmlFileToYamlFile(sourceDir + xmlFilename, destDir + yamlFilename);
69+
await convert.testsXmlFileToYamlFile(sourceDir + xmlFilename, destDir + yamlFilename, model);
6870
}
6971
} catch(e) {
7072
console.error(e);

converter/converter.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,35 @@ const castValue = (value, type) => mapper[type](value);
5757
/**
5858
* Converts Object representing test cases from XML to Object that can be serialized to YAML
5959
* @param {Object} node - result of xml2js.parseString
60+
* @param {string} model - model name, e.g. 'r4','stu3', 'dstu2'
6061
* @return {Object}
6162
*/
62-
const transform = (node) => {
63+
const transform = (node, model = null) => {
6364

6465
return Object.keys(node).reduce((acc, key) => {
6566

6667
switch(key) {
6768
case 'tests':
68-
return { tests: transform(_.pick(node[key], 'group')) };
69+
return { tests: transform(_.pick(node[key], 'group'), model) };
6970

7071
case 'group':
7172
return [...acc, ...node[key].map(item =>
72-
({ [`group: ${item['$'].description || item['$'].name}`]: transform(_.pick(item, 'test')) }))];
73+
({ [`group: ${item['$'].description || item['$'].name}`]: transform(_.pick(item, 'test'), model) }))];
7374

7475
case 'test':
7576
return [...acc, ...node[key].map(item => {
76-
let test = transform(item);
77+
let test = transform(item, model);
7778
if (!test.hasOwnProperty('result') && !test.error) {
7879
test.result = [];
7980
}
8081
if (!validateTest(test)) {
81-
test.disable = true;
82+
if (model && validateTest(Object.assign({}, test, { model }))) {
83+
// if the test cannot be passed without set the model, we set the model
84+
test.model = model;
85+
} else {
86+
// if the test cannot be passed at all, we disable it
87+
test.disable = true;
88+
}
8289
}
8390
return test;
8491
})];
@@ -120,14 +127,15 @@ module.exports = {
120127
/**
121128
* Serializes an XML test cases to YAML
122129
* @param {string} xmlData
130+
* @param {string} model - model name, e.g. 'r4','stu3', 'dstu2'
123131
* @returns {string}
124132
*/
125-
testsXmlStringToYamlString: async (xmlData) => {
133+
testsXmlStringToYamlString: async (xmlData, model) => {
126134
const parser = new xml2js.Parser({ explicitCharkey: true });
127135
const parseString = util.promisify(parser.parseString);
128136

129137
const parsed = await parseString(xmlData);
130-
const transformed = transform(parsed);
138+
const transformed = transform(parsed, model);
131139
transformed.tests.forEach(group => {
132140
const groupKey = Object.keys(group)[0];
133141
const groupTests = group[groupKey];

converter/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,27 @@ const readFile = util.promisify(fs.readFile);
66
const writeFile = util.promisify(fs.writeFile);
77

88
module.exports = {
9+
/**
10+
* Converts XML resource to the YAML format
11+
* @param {string} from - path to XML file
12+
* @param {string} to - path to YAML file
13+
*/
914
resourceXmlFileToJsonFile: async (from, to) => {
1015
const xmlData = await readFile(from);
1116
const ymlData = await convert.resourceXmlStringToJsonString(xmlData);
1217
await writeFile(to, ymlData);
1318
},
14-
testsXmlFileToYamlFile: async (from, to) => {
19+
20+
21+
/**
22+
* Converts XML test cases to the YAML format
23+
* @param {string} from - path to XML file
24+
* @param {string} to - path to YAML file
25+
* @param {string} model - model name, e.g. 'r4','stu3', 'dstu2'
26+
*/
27+
testsXmlFileToYamlFile: async (from, to, model) => {
1528
const xmlData = await readFile(from);
16-
const ymlData = await convert.testsXmlStringToYamlString(xmlData);
29+
const ymlData = await convert.testsXmlStringToYamlString(xmlData, model);
1730
await writeFile(to, ymlData);
1831
}
1932
};

package-lock.json

Lines changed: 42 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fhirpath",
3-
"version": "2.5.0",
3+
"version": "2.6.0",
44
"description": "A FHIRPath engine",
55
"main": "src/fhirpath.js",
66
"dependencies": {
@@ -15,7 +15,7 @@
1515
"@babel/preset-env": "^7.5.5",
1616
"babel-eslint": "^9.0.0",
1717
"babel-loader": "^8.0.6",
18-
"bestzip": "^2.1.4",
18+
"bestzip": "^2.1.7",
1919
"copy-webpack-plugin": "^6.0.3",
2020
"eslint": "^5.2.0",
2121
"fhir": "^4.7.10",

0 commit comments

Comments
 (0)