diff --git a/packages/client-testing-demo-tests-standard/src/index.ts b/packages/client-testing-demo-tests-standard/src/index.ts index f6b0c17..80031d7 100644 --- a/packages/client-testing-demo-tests-standard/src/index.ts +++ b/packages/client-testing-demo-tests-standard/src/index.ts @@ -6,7 +6,9 @@ export function patientDemoTest() { describe('Patients test (2nd version)', () => { let requests: Request[] = []; beforeAll(async () => { - requests = global.requests.filter((request) => request.resourceType === 'Patient' && request.session.id === global.SESSION_ID); + requests = global.requests.filter( + (request) => request.resourceType === 'Patient' && request.session.id === global.SESSION_ID, + ); }); test('Should only have available interactions', async () => { @@ -37,8 +39,17 @@ export function patientDemoTest() { }); test('Should only have available combo search params', async () => { - const availableComboSearchParams = new Set(['birthdate+family', 'birthdate+name', 'gender+name', 'family+gender']); - const filteredRequests = new Set(requests.filter((request) => request.filtersCodes.length > 1).map((request) => request.filtersCodes.join('+'))); + const availableComboSearchParams = new Set([ + 'birthdate+family', + 'birthdate+name', + 'gender+name', + 'family+gender', + ]); + const filteredRequests = new Set( + requests + .filter((request) => request.filtersCodes.length > 1) + .map((request) => request.filtersCodes.join('+')), + ); expect(filteredRequests.isSubsetOf(availableComboSearchParams)).toBe(true); }); @@ -48,7 +59,7 @@ export function patientDemoTest() { (request) => request.fhirAction === 'CREATE' && request.requestBody?.resourceType === 'Patient', ); const validationStatuses = await Promise.all( - filteredRequests.map(async (request) => await isResourceValid(request.requestBody as Patient)), + filteredRequests.map(async (request) => await isResourceValid(request.requestBody)), ); const falseValidations = validationStatuses.filter((status) => status === false); diff --git a/packages/fhir-validator/src/index.ts b/packages/fhir-validator/src/index.ts index a7bb0e1..8e15d84 100644 --- a/packages/fhir-validator/src/index.ts +++ b/packages/fhir-validator/src/index.ts @@ -44,10 +44,15 @@ export async function validateResource(ig: string, version: string, txServer: st return response.data; } -export async function isResourceValid(resource: FhirResource): Promise { +export async function isResourceValid(data?: FhirResource | any): Promise { + if (data?.resourceType) { + console.error('Only FHIR resources can be validated'); + return false; + } + const { IG, IG_VERSION, TX_SERVER, VALIDATOR_SENSITIVITY } = getValidatorEnvs(); try { - const result = await validateResource(IG, IG_VERSION, TX_SERVER, JSON.stringify(resource)); + const result = await validateResource(IG, IG_VERSION, TX_SERVER, JSON.stringify(data)); return result.outcomes?.[0]?.issues.filter((issue) => VALIDATOR_SENSITIVITY.includes(issue.level)).length === 0; } catch (error) { console.error('Error validating resource', error);