Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support library evaluate #27

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions build-libraries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/node

const os = require('os');
const fs = require('fs');
const path = require('path');
const ConfigLoader = require('./configLoader');
const config = new ConfigLoader();
const loadTests = require('./loadTests');
const { generateEmptyResults } = require('./resultsShared');

async function main() {

const tests = loadTests.load();
// Set this to true to run only the first group of tests
const quickTest = config.Debug.QuickTest
const emptyResults = await generateEmptyResults(tests, quickTest);

const skipMap = config.skipListMap();


for (let testFile of emptyResults) {
await generateLibrariesFromTests(testFile, skipMap);
}

}

main();


async function generateLibrariesFromTests(group, skipMap) {
if (!group || group.length === 0) return;

const cqlFileVersion = config.Build.CqlFileVersion;
const cqlOutputPath = config.Build.CqlOutputPath;

let testsName = '';
let body = '';

for (let r of group) {
if (!testsName) {
testsName = r.testsName;
}

if (r.invalid !== 'semantic') {
const defineVal = `define "${r.groupName}.${r.testName}": ${r.expression}`;
const key = `${r.testsName}-${r.groupName}-${r.testName}`;
let reason = '';

if (r.testStatus === 'skip') {
console.log(`Skipping ${key}`);
reason = "Skipped by cql-tests-runner";
} else if (skipMap.has(key)) {
console.log(`Skipping ${key}`);
reason = skipMap.get(key);
}

if (reason) {
body += `/* ${os.EOL} Skipped: ${reason} ${os.EOL} ${defineVal} ${os.EOL}*/${os.EOL}${os.EOL}`;
} else {
body += `${defineVal}${os.EOL}${os.EOL}`;
}
}
}

if (!testsName) return;

body = `library ${testsName} version '${cqlFileVersion}'${os.EOL}${os.EOL}${body}`;

if (!fs.existsSync(cqlOutputPath)) {
fs.mkdirSync(cqlOutputPath, { recursive: true });
}

const fileName = `${testsName}.cql`;
const filePath = path.join(cqlOutputPath, fileName);
fs.writeFileSync(filePath, body, (error) => {
if (error) throw error;
});

}

44 changes: 34 additions & 10 deletions config/development.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
{
"FhirServer": {
"BaseUrl": "https://cloud.alphora.com/sandbox/r4/cds/fhir/",
"CqlOperation": "$cql"
},
"Tests": {
"ResultsPath": "./results"
},
"Debug": {
"QuickTest": true
}
"FhirServer": {
"BaseUrl": "https://cloud.alphora.com/sandbox/r4/cds/fhir/",
"CqlOperation": "$cql"
},
"Build": {
"CqlFileVersion": "1.0.000",
"CqlOutputPath": "./cql"
},
"Debug": {
"QuickTest": true
},
"Tests": {
"ResultsPath": "./results",
"SkipList": [
{
"testsName": "CqlAggregateTest",
"groupName": "AggregateTests",
"testName": "RolledOutIntervals",
"reason": "CQLtoELM - Could not resolve identifier MedicationRequestIntervals in the current library"
},
{
"testsName": "CqlDateTimeOperatorsTest",
"groupName": "DateTimeComponentFrom",
"testName": "DateTimeComponentFromTimezone",
"reason": "CQLtoElm - Timezone keyword is only valid in 1.3 or lower"
},
{
"testsName": "CqlDateTimeOperatorsTest",
"groupName": "Uncertainty tests",
"testName": "TimeDurationBetweenHourDiffPrecision",
"reason": "CQLtoELM - Syntax error at Z"
}
]
}
}
54 changes: 42 additions & 12 deletions configLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,77 @@
const config = require('config');

class ConfigLoader {

constructor() {

const baseURL = process.env.SERVER_BASE_URL || config.get('FhirServer.BaseUrl') || 'https://cloud.alphora.com/sandbox/r4/cds/fhir';

this.FhirServer = {
BaseUrl: this.removeTrailingSlash(baseURL),
BaseUrl: this.#removeTrailingSlash(baseURL),
CqlOperation: process.env.CQL_OPERATION || config.get('FhirServer.CqlOperation') || '$cql'
};
this.Build = {
CqlFileVersion: process.env.CQL_FILE_VERSION || config.get('Build.CqlFileVersion') || '1.0.000',
CqlOutputPath: process.env.CQL_OUTPUT_PATH || config.get('Build.CqlOutputPath') || './cql'

}
this.Tests = {
ResultsPath: process.env.RESULTS_PATH || config.get('Tests.ResultsPath') || './results'
ResultsPath: process.env.RESULTS_PATH || config.get('Tests.ResultsPath') || './results',
SkipList: process.env.SKIP_LIST || config.get('Tests.SkipList') || []
};
this.Debug = {
QuickTest: this.getQuickTestSetting()
QuickTest: this.#setQuickTestSetting()
};
}

removeTrailingSlash(url) {
this.CqlEndpoint = this.#cqlEndPoint();

}
// TODO: validate the config values
#removeTrailingSlash(url) {
return url.endsWith('/') ? url.slice(0, -1) : url;
}

#cqlEndPoint(){
if (this.FhirServer.CqlOperation === '$cql') {
return '$cql';
}
else {
return 'Library' + '/$evaluate';
}
}

get apiUrl() {
if (this.FhirServer.CqlOperation === '$cql') {
return this.FhirServer.BaseUrl + '/$cql';
}
else {
return this.FhirServer.BaseUrl + 'Library' + '/$evaluate';
return this.FhirServer.BaseUrl + '/Library' + '/$evaluate';
}
}
getQuickTestSetting() {

#setQuickTestSetting() {
if (process.env.QUICK_TEST !== undefined) {
return process.env.QUICK_TEST === 'true';
return process.env.QUICK_TEST === 'true';
}

const configValue = config.get('Debug.QuickTest');
if (configValue !== undefined) {
return configValue;
return configValue;
}

return true;
}
}

skipListMap() {
const skipList = this.Tests.SkipList;
const skipMap = new Map(
skipList.map(skipItem => [
`${skipItem.testsName}-${skipItem.groupName}-${skipItem.testName}`,
skipItem.reason
])
);
return skipMap
}
}

module.exports = ConfigLoader;
Loading