-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 in LFOR/fhirpath.js from feature/LF-1485/updat…
…e-test-converter to master * commit 'ed74194ff0c1ecc4d74871eb9e4388134c21f647': Update FHIRPath test converter Update FHIRPath test converter Update FHIRPath test converter
- Loading branch information
Showing
24 changed files
with
3,865 additions
and
3,340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
# FHIR-r4 test converter | ||
|
||
CLI-tool for converting fhirpath [XML test cases](https://github.com/hl7-fhir/fhir-svn/blob/master/tests/resources/tests-fhir-r4.xml) | ||
into fhirpath.js yaml test cases format. | ||
CLI-tool for converting fhirpath [XML test cases](https://github.com/HL7/FHIRPath/tree/master/tests/r4/) | ||
into fhirpath.js yaml test cases format with json resource files. | ||
|
||
### Installing: | ||
```npm ci``` | ||
|
||
|
||
### Convert test file: | ||
```converter/bin/index.js converter/dataset/fhir-r4.xml(path to xml file) converter/dataset/tests-r4.yaml(path to save result data)``` | ||
### Download and convert test file and resource files: | ||
```converter/bin/index.js``` | ||
|
||
### Converter test in whole test scope: | ||
```npm run test``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,74 @@ | ||
#! /usr/bin/env node | ||
|
||
// Directory for downloading XML source files | ||
const sourceDir = __dirname + '/../dataset/'; | ||
// Directory for converter output(for YAML and JSON files) | ||
const destDir = __dirname + '/../../test/'; | ||
|
||
// Descriptions for file generation: | ||
// [<relative path to XML source file>, <relative path to YAML/JSON output file>, <download URL>] | ||
const sources = [ | ||
['fhir-r4.xml', 'cases/fhir-r4.yaml', 'https://raw.githubusercontent.com/HL7/FHIRPath/master/tests/r4/tests-fhir-r4.xml'], | ||
['input/observation-example.xml', 'resources/observation-example.json', 'https://raw.githubusercontent.com/HL7/FHIRPath/master/tests/r4/input/observation-example.xml'], | ||
['input/patient-example.xml', 'resources/patient-example.json', 'https://raw.githubusercontent.com/HL7/FHIRPath/master/tests/r4/input/patient-example.xml'], | ||
['input/questionnaire-example.xml', 'resources/questionnaire-example.json', 'https://raw.githubusercontent.com/HL7/FHIRPath/master/tests/r4/input/questionnaire-example.xml'], | ||
['input/valueset-example-expansion.xml', 'resources/valueset-example-expansion.json', 'https://raw.githubusercontent.com/HL7/FHIRPath/master/tests/r4/input/valueset-example-expansion.xml'] | ||
]; | ||
|
||
const commander = require('commander'); | ||
const run = require('../index'); | ||
const convert = require('../index'); | ||
|
||
const https = require('https'); | ||
const fs = require('fs'); | ||
|
||
function downloadFile(url, dest) { | ||
return new Promise((resolve, reject) => { | ||
const file = fs.createWriteStream(dest); | ||
https.get(url, function(res) { | ||
const { statusCode } = res; | ||
|
||
if (statusCode !== 200) { | ||
// Consume response data to free up memory | ||
res.resume(); | ||
reject(`Failed to download ${url}.\n` + | ||
`Status Code: ${statusCode}`); | ||
} else { | ||
res.pipe(file); | ||
file.on('finish', function () { | ||
resolve(); | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
commander | ||
.arguments('<path_from> <path_to>') | ||
.description('Convert xml test cases to yaml') | ||
.action(async (from, to) => | ||
await run(from, to)) | ||
.option('-s, --skip-download', 'skip downloading sources from FHIRPath repository') | ||
.description('Convert xml test cases/resources to yaml/json') | ||
.action(async (cmd) => { | ||
try { | ||
if (!cmd.skipDownload) { | ||
for (let i = 0; i < sources.length; i++) { | ||
const [xmlFilename,, url] = sources[i]; | ||
await downloadFile(url, sourceDir + xmlFilename); | ||
} | ||
} | ||
|
||
const resourceFiles = sources.filter(([,target]) => target.endsWith('.json')); | ||
const testFiles = sources.filter(([,target]) => target.endsWith('.yaml')); | ||
|
||
for (let i = 0; i < resourceFiles.length; i++) { | ||
const [xmlFilename, jsonFilename] = resourceFiles[i]; | ||
await convert.resourceXmlFileToJsonFile(sourceDir + xmlFilename, destDir + jsonFilename); | ||
} | ||
|
||
for (let i = 0; i < testFiles.length; i++) { | ||
const [xmlFilename, yamlFilename] = testFiles[i]; | ||
await convert.testsXmlFileToYamlFile(sourceDir + xmlFilename, destDir + yamlFilename); | ||
} | ||
} catch(e) { | ||
console.error(e); | ||
} | ||
}) | ||
.parse(process.argv); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.