Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-management into patient-registration
  • Loading branch information
ayush-AI committed Jun 29, 2023
2 parents 2d4786b + 541a7fb commit a3f1432
Show file tree
Hide file tree
Showing 76 changed files with 2,548 additions and 1,821 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIRequestContext, expect } from '@playwright/test';
import { Patient } from './patientOperations';
import { Patient } from './patient-operations';

export interface CohortType {
uuid: string;
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions e2e/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './patientOperations';
export * from './encounterOperations';
export * from './visitOperations';
export * from './providerOperations';
export * from './cohortOperations';
export * from './patient-operations';
export * from './encounter-operations';
export * from './visit-operations';
export * from './provider-operations';
export * from './cohort-operations';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions e2e/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './homePage';
export * from './registrationAndEditPage';
export * from './patientListsPage';
export * from './home-page';
export * from './registration-and-edit-page';
export * from './patient-lists-page';
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions e2e/specs/active-visits.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect } from '@playwright/test';
import { Visit } from '@openmrs/esm-framework';
import { test } from '../core';
import type { Provider } from '../../packages/esm-appointments-app/src/types/index';
import type { Encounter } from '../../packages/esm-active-visits-app/src/visits-summary/visit.resource';
import {
createEncounter,
deleteEncounter,
deletePatient,
endVisit,
generateRandomPatient,
Patient,
startVisit,
getProvider,
} from '../commands';
import { HomePage } from '../pages';

let patient: Patient;
let visit: Visit;
let encounter: Encounter;
let provider: Provider;
const encounterNote = 'This is a test note';

test.beforeEach(async ({ api }) => {
patient = await generateRandomPatient(api);
visit = await startVisit(api, patient.uuid);
provider = await getProvider(api);
encounter = await createEncounter(api, patient.uuid, provider.uuid, encounterNote);
});

test('View active visits', async ({ page }) => {
const homePage = new HomePage(page);
const openmrsIdentifier = patient.identifiers[0].display.split('=')[1].trim();
const firstName = patient.person.display.split(' ')[0];
const lastName = patient.person.display.split(' ')[1];

await test.step('When I visit the home page', async () => {
await homePage.goto();
});

await test.step("And I click on a patient's name in the active visits table", async () => {
await homePage.clickOnActiveVisitPatient(patient.uuid);
});

await test.step('Then I should see data about the active visit such as the encounters recorded during their visit and their observations and a summary of the diagnoses, notes, and medications recorded', async () => {
// Checks the visit details
await expect(page.getByTestId(`${visit.uuid}:idNumber`)).toContainText(openmrsIdentifier);
await expect(page.getByTestId(`${visit.uuid}:name`)).toContainText(`${firstName} ${lastName}`);
await expect(page.getByTestId(`${visit.uuid}:visitType`)).toContainText(visit.visitType.display);
// Checks for the encounter
await expect(page.getByTestId(`${encounter.uuid}:encounterType`)).toContainText(encounter.encounterType.display);
await expect(page.getByTestId(`${encounter.uuid}:provider`)).toContainText('Super User: Clinician');
// Checks for the visit note
await homePage.clickOnVisitSummaryTab();
await expect(page.getByTestId('note')).toContainText(encounterNote);
});
});

test.afterEach(async ({ api }) => {
await endVisit(api, patient.uuid);
await deleteEncounter(api, encounter.uuid);
await deletePatient(api, patient.uuid);
});
59 changes: 0 additions & 59 deletions e2e/specs/activeVisits.spec.ts

This file was deleted.

63 changes: 63 additions & 0 deletions e2e/specs/edit-patient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import dayjs from 'dayjs';
import { expect } from '@playwright/test';
import { test } from '../core';
import { deletePatient, generateRandomPatient, getPatient, Patient } from '../commands';
import { PatientRegistrationFormValues, RegistrationAndEditPage } from '../pages';

let patient: Patient;
test.beforeEach(async ({ api }) => {
patient = await generateRandomPatient(api);
});

// TODO: Add email field after fixing O3-1883 (https://issues.openmrs.org/browse/O3-1883)
const formValues: PatientRegistrationFormValues = {
givenName: `Johnny`,
middleName: 'Donny',
familyName: `Ronny`,
sex: 'male',
birthdate: '01/02/2020',
postalCode: '',
address1: 'Bom Jesus Street',
address2: '',
country: 'Brazil',
countyDistrict: 'Antônio dos Santos',
stateProvince: 'Pernambuco',
cityVillage: 'Recife',
phone: '5555551234',
};

test('Edit a patient', async ({ page, api }) => {
test.setTimeout(5 * 60 * 1000);
const patientEditPage = new RegistrationAndEditPage(page);

await test.step("When I visit the registration page to a patient's details", async () => {
await patientEditPage.goto(patient.uuid);
});

await test.step('And then I click on fill new values into the registration form and then click the `Submit` button', async () => {
await expect(patientEditPage.givenNameInput()).not.toHaveValue('', { timeout: 2 * 60 * 1000 });

await patientEditPage.fillPatientRegistrationForm(formValues);
});

await test.step("Then I should be redirected to the patient's chart page and the patient object should have updated information", async () => {
await expect(page).toHaveURL(`${process.env.E2E_BASE_URL}/spa/patient/${patient.uuid}/chart/Patient Summary`);
const updatedPatient = await getPatient(api, patient.uuid);
const { person } = updatedPatient;
const { givenName, middleName, familyName, sex } = formValues;

await expect(person.display).toBe(`${givenName} ${middleName} ${familyName}`);
await expect(person.gender).toBe(sex[0].toUpperCase());
await expect(dayjs(person.birthdate).format('DD/MM/YYYY')).toBe(formValues.birthdate);
await expect(person.preferredAddress.address1).toBe(formValues.address1);
await expect(person.preferredAddress.cityVillage).toBe(formValues.cityVillage);
await expect(person.preferredAddress.stateProvince).toBe(formValues.stateProvince);
await expect(person.preferredAddress.country).toBe(formValues.country);
await expect(person.preferredAddress.countyDistrict).toBe(formValues.countyDistrict);
await expect(person.attributes[0].display).toBe(`Telephone Number = ${formValues.phone}`);
});
});

test.afterEach(async ({ api }) => {
await deletePatient(api, patient.uuid);
});
103 changes: 103 additions & 0 deletions e2e/specs/patient-list.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { test } from '../core';
import { PatientListsPage } from '../pages';
import { expect } from '@playwright/test';
import {
type Cohort,
type CohortMember,
type Patient,
addPatientToCohort,
deleteCohort,
deletePatient,
generateRandomCohort,
generateRandomPatient,
removePatientFromCohort,
} from '../commands';

let createdCohortMember: CohortMember;
let createdCohortUuid: string;
let cohort: Cohort;
let patient: Patient;

test.beforeEach(async ({ api }) => {
patient = await generateRandomPatient(api);
cohort = await generateRandomCohort(api);
});

test('Create and edit a patient list', async ({ page }) => {
const patientListPage = new PatientListsPage(page);

await test.step('When I visit the patient lists page', async () => {
await patientListPage.goto();
});

// Create a new patient list
const patientListName = `Cohort ${Math.floor(Math.random() * 10000)}`;
const patientListDescription = `Cohort Description ${Math.floor(Math.random() * 10000)}`;

await test.step('Then I create a new list', async () => {
await patientListPage.addNewPatientList(patientListName, patientListDescription);
});

await test.step("And then I navigate to the new list's page", async () => {
await patientListPage.allListsButton().click();
await patientListPage.searchPatientList(patientListName);
await patientListPage.patientListsTable().getByText(patientListName).click();
});

await test.step('Then I should see the information about the list', async () => {
await expect(page).toHaveURL(new RegExp('^[\\w\\d:\\/.-]+\\/patient-lists\\/[\\w\\d-]+$'));
createdCohortUuid = /patient-lists\/([\w\d-]+)/.exec(page.url())?.[1] ?? null;

await expect(patientListPage.patientListHeader()).toHaveText(new RegExp(patientListName));
await expect(patientListPage.patientListHeader()).toHaveText(new RegExp(patientListDescription));
await expect(patientListPage.patientListHeader()).toHaveText(/0 patients/);
});

// Edit the patient list
const editedPatientListName = patientListName + ' edited';
const editedPatientListDescription = patientListDescription + ' edited';

await test.step("When I edit the list's details", async () => {
await patientListPage.editPatientList(editedPatientListName, editedPatientListDescription);
});

await test.step('Then I should see the updated information about the list', async () => {
await expect(patientListPage.patientListHeader()).toHaveText(new RegExp(editedPatientListName));
await expect(patientListPage.patientListHeader()).toHaveText(new RegExp(editedPatientListDescription));
});
});

test('Manage patients in a list', async ({ api, page }) => {
await test.step("When I visit a specific patient list's page", async () => {
const patientListPage = new PatientListsPage(page);
await patientListPage.goto(cohort.uuid);
});

await test.step('Then I should be able to add and remove patients from that list', async () => {
const patientListPage = new PatientListsPage(page);

// Add a patient to the list
createdCohortMember = await addPatientToCohort(api, cohort.uuid, patient.uuid);
await patientListPage.goto(cohort.uuid);
await expect(patientListPage.patientListHeader()).toHaveText(/1 patients/);
await expect(patientListPage.patientsTable()).toHaveText(new RegExp(patient.person.display));

// Remove a patient from the list
await removePatientFromCohort(api, createdCohortMember.uuid);
await patientListPage.goto(cohort.uuid);
await expect(patientListPage.patientListHeader()).toHaveText(/0 patients/);
await expect(patientListPage.patientsTable()).not.toHaveText(new RegExp(patient.person.display));
createdCohortMember = null;
});
});

test.afterEach(async ({ api }) => {
if (createdCohortMember) {
await removePatientFromCohort(api, createdCohortMember.uuid);
}
if (createdCohortUuid) {
await deleteCohort(api, createdCohortUuid);
}
await deletePatient(api, patient.uuid);
await deleteCohort(api, cohort.uuid);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@playwright/test';
import { test } from '../core';
import { HomePage } from '../pages';
import { expect } from '@playwright/test';
import { generateRandomPatient, deletePatient, Patient } from '../commands';

let patient: Patient;
Expand Down Expand Up @@ -31,11 +31,11 @@ test('Search patient by patient identifier', async ({ page, api }) => {
await expect(homePage.floatingSearchResultsContainer()).toHaveText(new RegExp(openmrsIdentifier));
});

await test.step('When I click on the patient', async () => {
await test.step('When I click on the patient record', async () => {
await homePage.clickOnPatientResult(firstName);
});

await test.step("Then I should be in the patient's chart page", async () => {
await test.step("Then I should be redirected to the patient's chart page", async () => {
await expect(homePage.page).toHaveURL(
`${process.env.E2E_BASE_URL}/spa/patient/${patient.uuid}/chart/Patient Summary`,
);
Expand Down
57 changes: 0 additions & 57 deletions e2e/specs/patientEdit.spec.ts

This file was deleted.

Loading

0 comments on commit a3f1432

Please sign in to comment.