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

(test) O3-2943: Edit E2E test for the immunization recording workflow #1768

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 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
70 changes: 63 additions & 7 deletions e2e/commands/patient-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ export interface Identifier {
}

export const generateRandomPatient = async (api: APIRequestContext): Promise<Patient> => {
const identifierRes = await api.post('idgen/identifiersource/8549f706-7e85-4c1d-9424-217d50a2988b/identifier', {
data: {},
});
const identifierRes = await api.post(
'rest/v1/idgen/identifiersource/8549f706-7e85-4c1d-9424-217d50a2988b/identifier',
{
data: {},
},
);
await expect(identifierRes.ok()).toBeTruthy();
const { identifier } = await identifierRes.json();

const patientRes = await api.post('patient', {
// TODO: This is not configurable right now. It probably should be.
const patientRes = await api.post('rest/v1/patient', {
data: {
identifiers: [
{
Expand Down Expand Up @@ -96,10 +98,64 @@ export const generateRandomPatient = async (api: APIRequestContext): Promise<Pat
};

export const getPatient = async (api: APIRequestContext, uuid: string): Promise<Patient> => {
const patientRes = await api.get(`patient/${uuid}?v=full`);
const patientRes = await api.get(`rest/v1/patient/${uuid}?v=full`);
return await patientRes.json();
};

export const deletePatient = async (api: APIRequestContext, uuid: string) => {
await api.delete(`patient/${uuid}`, { data: {} });
await api.delete(`rest/v1/patient/${uuid}`, { data: {} });
};

export const createImmunizations = async (api: APIRequestContext, uuid: string, visit: string) => {
const immunizationData = {
resourceType: 'Immunization',
status: 'completed',
vaccineCode: {
coding: [
{
code: '783AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
display: 'Hepatitis B vaccination',
},
],
},
patient: {
type: 'Patient',
reference: `Patient/${uuid}`,
},
encounter: {
type: 'Encounter',
reference: `Encounter/${visit}`,
},
occurrenceDateTime: '2024-06-10T13:50:00.000Z',
expirationDate: '2052-06-29T18:30:00.000Z',
location: {
type: 'Location',
reference: `Location/${process.env.E2E_LOGIN_DEFAULT_LOCATION_UUID}`,
},
performer: [
{
actor: {
type: 'Practitioner',
reference: 'Practitioner/f39e57d8-1185-4199-8567-6f1eeb160f05',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a chat with Ian, and it has nothing to do with the encounter but we suspect this is what causing issue as this UUID doesn't exist. Let me update the PR.

These are the valid values: https://github.com/openmrs/openmrs-module-referencedemodata/blob/2.x/api/src/main/java/org/openmrs/module/referencedemodata/ReferenceDemoDataConstants.java

},
},
],
manufacturer: {
display: 'Sanofi Pasteur SA',
},
lotNumber: 'POLIO-001',
protocolApplied: [
{
doseNumberPositiveInt: 1,
series: null,
},
],
};

const immunizationRes = await api.post('fhir2/R4/Immunization?_summary=data', {
data: immunizationData,
});
await expect(immunizationRes.ok()).toBeTruthy();
const immunization = await immunizationRes.json();
return immunization;
};
4 changes: 2 additions & 2 deletions e2e/commands/visit-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type Visit } from '@openmrs/esm-framework';
import dayjs from 'dayjs';

export const startVisit = async (api: APIRequestContext, patientId: string): Promise<Visit> => {
const visitRes = await api.post('visit', {
const visitRes = await api.post('rest/v1/visit', {
data: {
startDatetime: dayjs().subtract(1, 'D').format('YYYY-MM-DDTHH:mm:ss.SSSZZ'),
patient: patientId,
Expand All @@ -18,7 +18,7 @@ export const startVisit = async (api: APIRequestContext, patientId: string): Pro
};

export const endVisit = async (api: APIRequestContext, uuid: string) => {
const visitRes = await api.post(`visit/${uuid}`, {
const visitRes = await api.post(`rest/v1/visit/${uuid}`, {
data: {
location: process.env.E2E_LOGIN_DEFAULT_LOCATION_UUID,
startDatetime: dayjs().subtract(1, 'D').format('YYYY-MM-DDTHH:mm:ss.SSSZZ'),
Expand Down
2 changes: 1 addition & 1 deletion e2e/fixtures/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { type APIRequestContext, type PlaywrightWorkerArgs, type WorkerFixture }
*/
export const api: WorkerFixture<APIRequestContext, PlaywrightWorkerArgs> = async ({ playwright }, use) => {
const ctx = await playwright.request.newContext({
baseURL: `${process.env.E2E_BASE_URL}/ws/rest/v1/`,
baseURL: `${process.env.E2E_BASE_URL}/ws/`,
httpCredentials: {
username: process.env.E2E_USER_ADMIN_USERNAME,
password: process.env.E2E_USER_ADMIN_PASSWORD,
Expand Down
50 changes: 50 additions & 0 deletions e2e/specs/edit-immunizations.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect } from '@playwright/test';
import { type Visit } from '@openmrs/esm-framework';
import { generateRandomPatient, type Patient, startVisit, deletePatient, createImmunizations } from '../commands';
import { test } from '../core';
import { ImmunizationsPage } from '../pages';

let patient: Patient;
let visit: Visit;

test.beforeEach(async ({ api }) => {
patient = await generateRandomPatient(api);
const visit = await startVisit(api, patient.uuid);

await createImmunizations(api, patient.uuid, visit.uuid);
});

test('Edit an immunization', async ({ page }) => {
const immunizationsPage = new ImmunizationsPage(page);

await test.step('When I go to the Immunizations page', async () => {
await immunizationsPage.goTo(patient.uuid);
});

await test.step('And I edit the Immunization', async () => {
await page.getByRole('button', { name: 'Expand current row' }).click();
await page.getByRole('button', { name: 'Edit' }).click();
});

await test.step('Then I should see the Immunization form launch in the workspace', async () => {
await expect(page.getByText(/immunization form/i)).toBeVisible();
});

await test.step('When I set `21/03/2024` as the vaccination date', async () => {
await page.getByLabel(/vaccination date/i).clear();
await page.getByLabel(/vaccination date/i).fill('21/03/2024');
await page.getByLabel(/vaccination date/i).press('Tab');
});

await test.step('And I set `Polio vaccination, oral` as the immunization', async () => {
await page.getByText(/polio vaccination, oral/i).click();
});

await test.step('And I click on the `Save` button', async () => {
await page.getByRole('button', { name: /save/i }).click();
});
});

test.afterEach(async ({ api }) => {
await deletePatient(api, patient.uuid);
});
Loading