diff --git a/imports/api/_dev/populate/eids.ts b/imports/api/_dev/populate/eids.ts index 93a244e1d..4eb5d99d8 100644 --- a/imports/api/_dev/populate/eids.ts +++ b/imports/api/_dev/populate/eids.ts @@ -54,27 +54,54 @@ export const newEidData = makeTemplate({ }); export const exampleEidXML = (options?: { + nationalnumber?: string; + dateofbirth?: string; name?: string; firstname?: string; middlenames?: string; nationality?: string; placeofbirth?: string; + gender?: 'male' | 'female'; + photo?: string; + streetandnumber?: string; + zip?: string; + municipality?: string; }) => { - const {name, firstname, middlenames, nationality, placeofbirth} = { + const { + nationalnumber, + dateofbirth, + name, + firstname, + middlenames, + nationality, + placeofbirth, + gender, + photo, + streetandnumber, + zip, + municipality, + } = { + nationalnumber: '70010112345', + dateofbirth: '19700101', name: 'Name', firstname: 'First Name', middlenames: 'M', nationality: 'Belge', placeofbirth: 'Bruxelles', + gender: 'female', + photo: randomPNGBase64(), + streetandnumber: 'Rue de la montagne 58 ', + zip: '1000', + municipality: 'Bruxelles', ...options, }; // TODO: Generalizes and escape values. return ` ${name} @@ -82,7 +109,7 @@ export const exampleEidXML = (options?: { ${middlenames} ${nationality} ${placeofbirth} - ${randomPNGBase64()} + ${photo} Bruxelles
- Rue de la montagne 58 - 1000 - Bruxelles + ${streetandnumber} + ${zip} + ${municipality}
ROOT diff --git a/imports/api/eidParseXML.ts b/imports/api/eidParseXML.ts index 12a41e3ac..9e62baeda 100644 --- a/imports/api/eidParseXML.ts +++ b/imports/api/eidParseXML.ts @@ -5,7 +5,7 @@ import schema from '../lib/schema'; import {type EidFields} from './collection/eids'; const text = schema.object({ - _text: schema.string(), + _text: schema.string().optional(), }); export const eidXml = schema.object({ diff --git a/test/app/client/patient/eids.app-tests.ts b/test/app/client/patient/eids.app-tests.ts index 0cde8dd45..7f56119a9 100644 --- a/test/app/client/patient/eids.app-tests.ts +++ b/test/app/client/patient/eids.app-tests.ts @@ -1,17 +1,18 @@ import {fireEvent} from '@testing-library/dom'; +import call from '../../../../imports/api/endpoint/call'; +import insert from '../../../../imports/api/endpoint/patients/insert'; +import createUserWithPassword from '../../../../imports/api/user/createUserWithPassword'; + import {exampleEidXML} from '../../../../imports/api/_dev/populate/eids'; +import {newPatientFormData} from '../../../../imports/api/_dev/populate/patients'; import { client, randomPassword, randomUserId, } from '../../../../imports/_test/fixtures'; -import { - setupApp, - createUserWithPasswordAndLogin, - searchForPatient, -} from '../fixtures'; +import {setupApp, searchForPatient} from '../fixtures'; type Item = string | File; @@ -95,7 +96,7 @@ client(__filename, () => { const username = randomUserId(); const password = randomPassword(); const app = setupApp(); - await createUserWithPasswordAndLogin(app, username, password); + await createUserWithPassword(username, password); const {findByRole, findByText, user} = app; @@ -112,7 +113,7 @@ client(__filename, () => { const username = randomUserId(); const password = randomPassword(); const app = setupApp(); - await createUserWithPasswordAndLogin(app, username, password); + await createUserWithPassword(username, password); const {findByRole, user} = app; @@ -132,8 +133,105 @@ client(__filename, () => { await findByRole('button', {name: 'Create a new patient'}), ); - await searchForPatient(app, `Jane Doe`, { - name: `Jane Doe`, + await searchForPatient(app, 'Jane Doe', { + name: 'Jane Doe', + }); + }); + + it('should allow to open a patient from eid', async () => { + const username = randomUserId(); + const password = randomPassword(); + const app = setupApp(); + await createUserWithPassword(username, password); + + const {findAllByRole, findByRole, findByText, user} = app; + + const sex = 'female'; + + const formData = newPatientFormData({sex}); + + const { + niss, + firstname, + lastname, + birthdate, + photo, + streetandnumber, + zip, + municipality, + } = formData; + + const patientId = await call(insert, formData); + + const eidXML = exampleEidXML({ + nationalnumber: niss, + dateofbirth: birthdate.replaceAll('-', ''), + photo, + name: lastname, + gender: sex, + firstname, + streetandnumber, + zip, + municipality, }); + + await dropFiles(app, eidXML); + + await findByRole('heading', {name: 'Select record to work with.'}); + + const buttons = await findAllByRole('button', { + name: new RegExp(` ${lastname} ${firstname} `, 'i'), + }); + await user.click(buttons[0]!); + + await user.click(await findByRole('button', {name: 'Next (1)'})); + + await user.click( + await findByText(/^open$/i, {selector: 'button:not([disabled])'}), + ); + + await findByRole('heading', {name: `/patient/${patientId}`}); + }); + + it('should allow to update a patient from eid', async () => { + const username = randomUserId(); + const password = randomPassword(); + const app = setupApp(); + await createUserWithPassword(username, password); + + const {findAllByRole, findByRole, findByText, user} = app; + + const formData = newPatientFormData({ + streetandnumber: 'streetandnumber-initial', + }); + + const {firstname, lastname} = formData; + + const patientId = await call(insert, formData); + + const eidXML = exampleEidXML({ + name: lastname, + firstname, + streetandnumber: 'streetandnumber-eid', + }); + + await dropFiles(app, eidXML); + + await findByRole('heading', {name: 'Select record to work with.'}); + + const buttons = await findAllByRole('button', { + name: new RegExp(` ${lastname} ${firstname} `, 'i'), + }); + await user.click(buttons[0]!); + + await user.click(await findByRole('button', {name: 'Next (1)'})); + + await user.click(await findByRole('button', {name: 'Next'})); + + await user.click(await findByRole('button', {name: 'Update'})); + + await findByRole('heading', {name: `/patient/${patientId}`}); + + await findByText('streetandnumber-eid'); }); });