Skip to content

Commit

Permalink
#72: Updating config to use $cql operation (#73)
Browse files Browse the repository at this point in the history
* #72: updated config and components to work with updated  operation in the cqf-ruler

* cleanup
  • Loading branch information
c-schuler committed Jul 18, 2022
1 parent 52fd2d7 commit bca12a1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 85 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 7 additions & 67 deletions src/app/components/runner/runner.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Configuration } from '../config/config.model';
import { ConfigService } from '../config/config.service';
import { CodeMirrorDirective } from '../../shared/code-mirror/code-mirror.directive';
import { EditorType } from '../../shared/code-mirror/code-mirror.model';
import { environment } from 'src/environments/environment';

@Component ({
selector: 'app-runner',
Expand Down Expand Up @@ -54,82 +55,21 @@ export class RunnerComponent {
}
}

// Tacks on line numbers from the given string location
private getNumberedResponses(responses: any) {
for (const response of responses) {
if (!response['translation-error'] && !response['error']) {
response.line = parseInt(response.location.substring(response.location.indexOf('[') + 1, response.location.indexOf(':')));
}
}
return responses;
}

processResponses(responses: any) {
// TODO: Move this sorting/line property to service end
// responses = this.getNumberedResponses (responses);
// // Sort responses in ascending order by line number
// responses = responses.sort((a, b) => {
// return a.line === b.line ? 0 : +(a.line > b.line) || -1;
// });

this.oValue += '\n';

if (responses && responses.entry) {
for (const e of responses.entry) {
const name = e.fullUrl;
const p = e.resource?.parameter;
if (responses && responses.parameter) {
for (const e of responses.parameter) {
const name = e.name;
let value = 'undefined';
let location = 'unknown';
if (p) {
location = p[0].valueString;
value = p[1].valueString ? p[1].valueString : (p[1].resource ? JSON.stringify(p[1].resource) : 'undefined');
}
this.oValue += '>> ' + name + ' ' + location + ' ' + value + '\n';
value = Object.keys(e).filter(k => k.startsWith('value'))[0];
value = e[value] ? JSON.stringify(e[value]) : (e.resource ? JSON.stringify(e.resource) : 'undefined');
this.oValue += '>> ' + name + ': ' + value + '\n';
}
}

// for (const response of responses) {
// // Invalid expression – could not translate
// if (response['translation-error']) {
// this.oValue += '>> Translation Error: ' + response['translation-error'] + '\n';
// }
// // Invalid expression – error with named expression
// if (response['error']) {
// this.oValue += '>> Error ' + response.location + ': ' + response['error'] + '\n';
// }
// // Valid expression
// if (response['result'] || response['result'] === '') {
// this.oValue += '>> ' + response['name'] + ' ' + response.location + ' ' + response.result + '\n';
// }
// }

this.updateOutput();
}
format() {
const currentEngineUrl = this.config.engineUri;
const input = this.codeEditors.find((mirror) => mirror.type === EditorType.input);
this.config.value = input.value;
this.config.engineUri = 'https://cql.dataphoria.org/cql/format';
this.apiService.post(this.config)
.forEach(responses => {
this.processResponse(responses);
})
.catch(error => {
this.output = error;
this.displayOutput();
});
this.config.engineUri = currentEngineUrl;
}

processResponse(responses: any) {
for (const response of responses) {
if (response['formatted-cql']) {
this.output = response['formatted-cql'];
}
}

this.displayOutput();
}

displayOutput() {
const input = this.codeEditors.find((mirror) => mirror.type === EditorType.input);
Expand Down
59 changes: 42 additions & 17 deletions src/app/shared/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,67 @@ export class ApiService {
'Content-Type': 'application/json'
});

// TODO: add authorization headers for endpoints
const parameters = {
resourceType : 'Parameters',
parameter: [
{
name: 'code',
name: 'content',
valueString: config.value
},
{
name : 'patientId',
name : 'subject',
valueString : config.patientId
},
,
{
name: 'context',
valueString: config.patientId ? 'Patient' : ''
name: 'dataEndpoint',
resource: {
resourceType: "Endpoint",
status: "active",
connectionType: {
system: "https://terminology.hl7.org/CodeSystem/endpoint-connection-type",
code: "hl7-fhir-rest"
},
address: config.dataSourceUri,
header: [
"Content-Type: application/json"
]
}
},
{
name : 'terminologyServiceUri',
valueString : config.terminologyUri
name : 'terminologyEndpoint',
resource: {
resourceType: "Endpoint",
status: "active",
connectionType: {
system: "https://terminology.hl7.org/CodeSystem/endpoint-connection-type",
code: "hl7-fhir-rest"
},
address: config.terminologyUri,
header: [
"Content-Type: application/json"
]
}
},
{
name : 'terminologyUser',
valueString : config.terminologyUsername
},
{
name : 'terminologyPass',
valueString : config.terminologyPassword
name : 'contentEndpoint',
resource: {
resourceType: "Endpoint",
status: "active",
connectionType: {
system: "https://terminology.hl7.org/CodeSystem/endpoint-connection-type",
code: "hl7-fhir-rest"
},
address: config.librarySourceUri,
header: [
"Content-Type: application/json"
]
}
}
]
};

// TODO: data and library
// dataServiceUri: config.dataSourceUri || environment.dataSourceUri,
// dataUser: config.dataSourceUsername,
// dataPass: config.dataSourcePassword,

// TODO: enable authorization for engine service
return this.http.post(config.engineUri || environment.engineUri, JSON.stringify(parameters), {headers});
}
Expand Down

0 comments on commit bca12a1

Please sign in to comment.