-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref: #7
- Loading branch information
Showing
7 changed files
with
152 additions
and
161 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
3 changes: 0 additions & 3 deletions
3
packages/app/src/suites/1.0.0-ballot/Patient/patient-db.spec.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
packages/client-testing-demo-tests-db/src/patientdb.spec.ts
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { In, Not } from 'typeorm'; | ||
|
||
describe('Patients test', () => { | ||
test('Should only have available interactions', async () => { | ||
const requests = await global.RequestsRepository.find({ | ||
where: { | ||
session: { id: global.SESSION_ID }, | ||
resourceType: 'Patient', | ||
fhirAction: Not(In(['READ', 'SEARCH', 'CREATE', 'UPDATE'])), | ||
}, | ||
relations: ['session'], | ||
}); | ||
expect(requests.length).toBe(0); | ||
}); | ||
|
||
test('Should only have available search params', async () => { | ||
// NOTE: SQL query example | ||
// SELECT * | ||
// FROM request | ||
// WHERE sessionId = 123 | ||
// AND resourceType = 'Patient' | ||
// AND fhirAction = 'SEARCH' | ||
// AND jsonb_array_length(filters) = 1 | ||
// AND filters->0->>'code' NOT IN ('_id', 'family') | ||
|
||
const requests = await global.RequestsRepository.createQueryBuilder('request') | ||
.where('request.sessionId = :sessionId', { sessionId: global.SESSION_ID }) | ||
.andWhere('request.resourceType = :resourceType', { resourceType: 'Patient' }) | ||
.andWhere('request.fhirAction = :action', { action: 'SEARCH' }) | ||
.andWhere('jsonb_array_length(request.filters) = 1') | ||
.andWhere("request.filters->0->>'code' NOT IN (:...availableSearchParams)", { availableSearchParams: ['_id', 'birthdate', 'family', 'gender', 'identifier', 'name', 'gender-identity', 'indigenous-status'] }) | ||
.getMany(); | ||
|
||
expect(requests.length).toBe(0); | ||
}); | ||
|
||
test('Should only have available combo search params', async () => { | ||
// NOTE: SQL query example | ||
// SELECT * | ||
// FROM request | ||
// WHERE sessionId = 123 | ||
// AND resourceType = 'Patient' | ||
// AND fhirAction = 'SEARCH' | ||
// AND jsonb_array_length(filters) > 1 | ||
// AND NOT filters_codes <@ array[array['birthdate','family'], array['birthdate','name']] | ||
const requests = await global.RequestsRepository.createQueryBuilder('request') | ||
.where('request.sessionId = :sessionId', { sessionId: global.SESSION_ID }) | ||
.andWhere('request.resourceType = :resourceType', { resourceType: 'Patient' }) | ||
.andWhere('request.fhirAction = :action', { action: 'SEARCH' }) | ||
.andWhere('jsonb_array_length(request.filters) > 1') | ||
.andWhere('NOT request.filters_codes <@ :codes', { | ||
codes: [ | ||
['birthdate', 'family'], | ||
['birthdate', 'name'], | ||
['gender', 'name'], | ||
['family', 'gender'], | ||
], | ||
}) | ||
.getMany(); | ||
|
||
expect(requests.length).toBe(0); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
packages/client-testing-demo-tests-standard/src/patientjs.spec.ts
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Request } from '@beda.software/app/src/modules/requests/request.entity'; | ||
import { isResourceValid } from '@beda.software/fhir-validator'; | ||
|
||
/** | ||
* Temporary function to check if a set is a subset of another set | ||
*/ | ||
function isSubsetOf<T>(setA: Set<T>, setB: Set<T>): boolean { | ||
if (setA.size > setB.size) { | ||
return false; | ||
} | ||
|
||
for (const elem of setA) { | ||
if (!setB.has(elem)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
describe('Patients test (2nd version)', () => { | ||
let requests: Request[] = []; | ||
beforeAll(async () => { | ||
requests = global.requests.filter( | ||
(request) => request.resourceType === 'Patient' && request.session.id === global.SESSION_ID, | ||
); | ||
}); | ||
|
||
test('Should only have available interactions', async () => { | ||
const availableInteractions = ['READ', 'SEARCH', 'CREATE', 'UPDATE']; | ||
const filteredRequests = requests.filter((request) => !availableInteractions.includes(request.fhirAction)); | ||
|
||
expect(filteredRequests.length).toBe(0); | ||
}); | ||
|
||
test('Should only have available search params', async () => { | ||
const availableSearchParams = new Set([ | ||
'_id', | ||
'birthdate', | ||
'family', | ||
'gender', | ||
'identifier', | ||
'name', | ||
'gender-identity', | ||
'indigenous-status', | ||
]); | ||
const filteredRequests = new Set( | ||
requests | ||
.filter((request) => request.filtersCodes.length === 1) | ||
.map((request) => request.filtersCodes[0]), | ||
); | ||
|
||
expect(isSubsetOf(filteredRequests, availableSearchParams)).toBe(true); | ||
}); | ||
|
||
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('+')), | ||
); | ||
|
||
expect(isSubsetOf(filteredRequests, availableComboSearchParams)).toBe(true); | ||
}); | ||
|
||
test('Should only have valid resources in CREATE action', async () => { | ||
const filteredRequests = requests.filter( | ||
(request) => request.fhirAction === 'CREATE' && request.requestBody?.resourceType === 'Patient', | ||
); | ||
const validationStatuses = await Promise.all( | ||
filteredRequests.map(async (request) => await isResourceValid(request.requestBody)), | ||
); | ||
const falseValidations = validationStatuses.filter((status) => status === false); | ||
|
||
expect(falseValidations.length).toBe(0); | ||
}); | ||
}); |