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

Mat 6401 no context error #385

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
30 changes: 27 additions & 3 deletions src/api/useFhirElmTranslationServiceApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,31 @@ describe("Test FhirElmTranslationServiceApi", () => {

try {
const translate = await fhirElmTranslationServiceApi.translateCqlToElm(
"test"
"test",
true
);
expect(translate).toBe(elmTranslationWithNoErrors);
} catch (error) {
expect(error).not.toBeNull();
}
});

it("Should error when service config url is valid", async () => {
const successResponse = {
data: { json: JSON.stringify(elmTranslationWithNoErrors) },
status: 200,
};
mockedAxios.put.mockResolvedValue(successResponse);
const fhirElmTranslationServiceApi: FhirElmTranslationServiceApi =
new FhirElmTranslationServiceApi(
mockServiceConfig.qdmElmTranslationService.baseUrl,
mockGetAccessToken
);

try {
const translate = await fhirElmTranslationServiceApi.translateCqlToElm(
"test",
true
);
expect(translate).toBe(elmTranslationWithNoErrors);
} catch (error) {
Expand All @@ -51,7 +75,7 @@ describe("Test FhirElmTranslationServiceApi", () => {
new FhirElmTranslationServiceApi(null, mockGetAccessToken);

try {
await fhirElmTranslationServiceApi.translateCqlToElm("test");
await fhirElmTranslationServiceApi.translateCqlToElm("test", true);
} catch (error) {
expect(error).not.toBeNull();
expect(error.message).toBe(
Expand Down Expand Up @@ -80,7 +104,7 @@ describe("Test FhirElmTranslationServiceApi", () => {
new FhirElmTranslationServiceApi("test", mockGetAccessToken);

try {
await fhirElmTranslationServiceApi.translateCqlToElm("test");
await fhirElmTranslationServiceApi.translateCqlToElm("test", false);
} catch (error) {
expect(error).not.toBeNull();
expect(error.message).toBe("Request failed with status code 404");
Expand Down
6 changes: 5 additions & 1 deletion src/api/useFhirElmTranslationServiceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { AxiosResponse } from "axios";
export class FhirElmTranslationServiceApi {
constructor(private baseUrl: string, private getAccessToken: () => string) {}

async translateCqlToElm(cql: string): Promise<ElmTranslation> {
async translateCqlToElm(
cql: string,
checkContext: boolean
): Promise<ElmTranslation> {
if (this.baseUrl) {
try {
const resp = await axios.put(
Expand All @@ -25,6 +28,7 @@ export class FhirElmTranslationServiceApi {
"disable-list-demotion": true,
"disable-list-promotion": true,
"validate-units": true,
checkContext: checkContext,
},
timeout: 15000,
}
Expand Down
6 changes: 4 additions & 2 deletions src/madie-madie-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export const MadieEditor: FC<EditorPropsType> = MadieAceEditor;
export const parseContent: (content: string) => CqlError[] = parseEditorContent;

export type { ElmTranslationError };
export const validateContent: (content: string) => Promise<ValidationResult> =
useGetAllErrors;
export const validateContent: (
content: string,
checkContext: boolean
) => Promise<ValidationResult> = useGetAllErrors;

export const synchingEditorCqlContent: (
editorVal: string,
Expand Down
16 changes: 11 additions & 5 deletions src/validations/editorValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe("Editor Validation Test", () => {
});

it("validate cql null input", async () => {
const errorsResult: ValidationResult = await useGetAllErrors("");
const errorsResult: ValidationResult = await useGetAllErrors("", false);
expect(errorsResult).toBeNull();
});

Expand Down Expand Up @@ -201,7 +201,10 @@ describe("Editor Validation Test", () => {
});
}
});
const errorsResult: ValidationResult = await useGetAllErrors(editorContent);
const errorsResult: ValidationResult = await useGetAllErrors(
editorContent,
true
);
expect(errorsResult?.errors.length).toBe(0);
});

Expand Down Expand Up @@ -254,7 +257,7 @@ describe("Editor Validation Test", () => {
});
}
});
const errorsResult = await useGetAllErrors(editorContent);
const errorsResult = await useGetAllErrors(editorContent, true);
expect(errorsResult.errors.length).toBe(4);
});

Expand Down Expand Up @@ -308,7 +311,7 @@ describe("Editor Validation Test", () => {
}
});

const errorsResult = await useGetAllErrors(editorContent);
const errorsResult = await useGetAllErrors(editorContent, true);
expect(errorsResult.errors.length).toBe(3);
});

Expand All @@ -331,7 +334,10 @@ describe("Editor Validation Test", () => {
});
}
});
const errorsResult = await useGetAllErrors("Library FHIR version 1.0.000");
const errorsResult = await useGetAllErrors(
"Library FHIR version 1.0.000",
false
);
expect(errorsResult.externalErrors.length).toBe(1);
});
});
6 changes: 4 additions & 2 deletions src/validations/editorValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export interface ValidationResult {
}

export const useGetAllErrors = async (
cql: string
cql: string,
checkContext: boolean
): Promise<ValidationResult> => {
if (cql && cql.trim().length > 0) {
const cqlResult: CqlResult = new CqlAntlr(cql).parse();
Expand All @@ -34,7 +35,8 @@ export const useGetAllErrors = async (
isLoggedInUMLS.valueOf(),
cqlResult?.usings[0]?.name
),
TranslateCql(cql, cqlResult?.usings[0]?.name),

TranslateCql(cql, cqlResult?.usings[0]?.name, checkContext),
GetValueSetErrors(
cqlResult.valueSets,
isLoggedInUMLS.valueOf(),
Expand Down
18 changes: 18 additions & 0 deletions src/validations/elmTranslateValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,22 @@ describe("ELM Translation validation", () => {
expect(elmErrors).toBeNull();
} catch (error) {}
});

it("translate CQL to ELM no error QDM", async () => {
mockedAxios.put.mockImplementation((args) => {
if (
args &&
args.startsWith(mockServiceConfig.qdmElmTranslationService.baseUrl)
) {
return Promise.resolve({
data: { json: JSON.stringify(elmTranslationWithNoErrors) },
status: 200,
});
}
});

const elmErrors: ElmTranslation = await TranslateCql("test", "QDM");
expect(elmErrors.errorExceptions.length).toBe(0);
expect(elmErrors.externalErrors.length).toBe(0);
});
});
8 changes: 6 additions & 2 deletions src/validations/elmTranslateValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import useFhirElmTranslationServiceApi from "../api/useFhirElmTranslationService

const TranslateCql = async (
cql: string,
model: string
model: string,
checkContext: boolean
): Promise<ElmTranslation> => {
const qdmElmTranslationServiceApi = await useQdmElmTranslationServiceApi();
const fhirElmTranslationServiceApi = await useFhirElmTranslationServiceApi();
Expand All @@ -13,7 +14,10 @@ const TranslateCql = async (
if (model === "QDM") {
return await qdmElmTranslationServiceApi.translateCqlToElm(cql);
} else {
return await fhirElmTranslationServiceApi.translateCqlToElm(cql);
return await fhirElmTranslationServiceApi.translateCqlToElm(
cql,
checkContext
);
}
}
return null;
Expand Down
Loading