Skip to content

Commit

Permalink
OZ-554: E2E tests for handling voided entities when streaming with An…
Browse files Browse the repository at this point in the history
…alytics
  • Loading branch information
kdaud committed May 20, 2024
1 parent 25b6352 commit f4dd61d
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 4 deletions.
178 changes: 176 additions & 2 deletions e2e/tests/openmrs-superset-flows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test.beforeEach(async ({ page }) => {
await openmrs.login();
await expect(page).toHaveURL(/.*home/);
});

/*
test('Creating an OpenMRS patient creates the patient in Superset patients table.', async ({ page }) => {
// replay
await superset.open();
Expand Down Expand Up @@ -420,8 +420,182 @@ test('Voiding an OpenMRS obs updates the observation in Superset observations ta
await page.getByRole('tab', { name: 'Results' }).click();
await superset.clearSQLEditor();
});
*/
test('Voiding an OpenMRS patient updates the patient in Superset patients table.', async ({ page }) => {
// setup
await openmrs.createPatient();
await openmrs.searchPatientId();
const patientIdentifier = await page.locator('#demographics section p:nth-child(2)').textContent();

test.afterEach(async ({ page }) => {
// replay
await superset.open();
await expect(page).toHaveURL(/.*superset/);
await superset.selectDBSchema();
await superset.clearSQLEditor();

let personVoidedQuery = `SELECT person_voided FROM patients where identifiers like 'OpenMRS ID: ${patientIdentifier}';`;
await page.getByRole('textbox').first().fill(personVoidedQuery);
await superset.runSQLQuery();
let patientVoidedState = await page.locator('div.virtual-table-cell');

await expect(patientVoidedState).toContainText('false');
await openmrs.deletePatient();

// verify
await page.goto(`${SUPERSET_URL}/superset/sqllab`);
await superset.clearSQLEditor();
await page.getByRole('textbox').first().fill(personVoidedQuery);
await superset.runSQLQuery();

await expect(patientVoidedState).toContainText('true');
await superset.clearSQLEditor();
});

test('Voiding an OpenMRS condition update the condition in Superset conditions table.', async ({ page }) => {
// setup
await openmrs.createPatient();
await openmrs.searchPatientId();
const patientIdentifier = await page.locator('#demographics section p:nth-child(2)').textContent();
await openmrs.startPatientVisit();
await openmrs.addPatientCondition();

// replay
await superset.open();
await expect(page).toHaveURL(/.*superset/);
await superset.selectDBSchema();
await superset.clearSQLEditor();

let patientIdQuery = `SELECT patient_id FROM patients WHERE identifiers like 'OpenMRS ID: ${patientIdentifier}';`;
await page.getByRole('textbox').first().fill(patientIdQuery);
await superset.runSQLQuery();
let patientId = await page.locator('div.virtual-table-cell').textContent();
const patientIdValue = Number(patientId);
await superset.clearSQLEditor();

let conditionVoidedQuery = `SELECT voided FROM conditions WHERE patient_id=${patientIdValue};`;
await page.getByRole('textbox').first().fill(conditionVoidedQuery);
await superset.runSQLQuery();
let conditionVoidedState = await page.locator('div.virtual-table-cell');

await expect(conditionVoidedState).toContainText('false');
await superset.clearSQLEditor();

await page.goto(`${O3_URL}`);
await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await openmrs.voidPatientCondition();

// verify
await page.goto(`${SUPERSET_URL}/superset/sqllab`);
await superset.clearSQLEditor();
await page.getByRole('textbox').first().fill(conditionVoidedQuery);
await superset.runSQLQuery();

await expect(conditionVoidedState).toContainText('true');
await superset.clearSQLEditor();
await openmrs.deletePatient();
});

test('Voiding an OpenMRS encounter updates the encounter in Superset encounters table.', async ({ page }) => {
// setup
await openmrs.createPatient();
await openmrs.searchPatientId();
const patientIdentifier = await page.locator('#demographics section p:nth-child(2)').textContent();
await openmrs.startPatientVisit();
await openmrs.goToLabOrderForm();
await page.getByRole('button', { name: 'Add', exact: true }).click();
await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
await openmrs.saveLabOrder();

await superset.open();
await expect(page).toHaveURL(/.*superset/);
await superset.selectDBSchema();
await superset.clearSQLEditor();
let patientIdQuery = `SELECT patient_id FROM patients WHERE identifiers like 'OpenMRS ID: ${patientIdentifier}';`;
await page.getByRole('textbox').first().fill(patientIdQuery);
await superset.runSQLQuery();
let patientId = await page.locator('div.virtual-table-cell').textContent();
const patientIdValue = Number(patientId);
await page.getByRole('tab', { name: 'Results' }).click();
await superset.clearSQLEditor();
let encounterIdQuery = `SELECT encounter_id FROM orders WHERE patient_id=${patientIdValue};`;
await page.getByRole('textbox').first().fill(encounterIdQuery);
await superset.runSQLQuery();
let encounterId = await page.locator('div.virtual-table-cell').textContent();
const encounterIdValue = Number(encounterId);
await page.getByRole('tab', { name: 'Query history' }).click();
await superset.clearSQLEditor();
let encounterTypeUuidQuery = `SELECT encounter_type_uuid FROM orders WHERE patient_id=${patientIdValue};`;
await page.getByRole('textbox').fill(encounterTypeUuidQuery);
await superset.runSQLQuery();
let encounterTypeUuidValue = await page.locator('div.virtual-table-cell').textContent();
await page.getByRole('tab', { name: 'Results' }).click();
await superset.clearSQLEditor();
let encounterVoidedQuery = `SELECT encounter_voided FROM encounters WHERE encounter_id=${encounterIdValue} AND encounter_type_uuid like '${encounterTypeUuidValue}';`;
await page.getByRole('textbox').first().fill(encounterVoidedQuery);
await superset.runSQLQuery();
let encounterVoidedState = await page.locator('div.virtual-table-cell');

await expect(encounterVoidedState).toContainText('false');
await superset.clearSQLEditor();

// replay
await page.goto(`${O3_URL}`);
await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await openmrs.voidEncounter();

// verify
await page.goto(`${SUPERSET_URL}/superset/sqllab`);
await superset.clearSQLEditor();
await page.getByRole('textbox').first().fill(encounterVoidedQuery);
await superset.runSQLQuery();

await expect(encounterVoidedState).toContainText('true');
await superset.clearSQLEditor();
await openmrs.deletePatient();
});

test('Cancelling an OpenMRS appointment updates the appointment in Superset appointments table.', async ({ page }) => {
// setup
await openmrs.createPatient();
await openmrs.searchPatientId();
const patientIdentifier = await page.locator('#demographics section p:nth-child(2)').textContent();
await openmrs.startPatientVisit();
await openmrs.addPatientAppointment();
await superset.open();
await expect(page).toHaveURL(/.*superset/);
await superset.selectDBSchema();
await superset.clearSQLEditor();
let patientIdQuery = `SELECT patient_id FROM patients WHERE identifiers like 'OpenMRS ID: ${patientIdentifier}';`;
await page.getByRole('textbox').first().fill(patientIdQuery);
await superset.runSQLQuery();
let patientId = await page.locator('div.virtual-table-cell').textContent();
const patientIdValue = Number(patientId);
await page.getByRole('tab', { name: 'Results' }).click();
await superset.clearSQLEditor();
let appointmentStatusQuery = `SELECT status FROM appointments WHERE patient_id=${patientIdValue};`;
await page.getByRole('textbox').first().fill(appointmentStatusQuery);
await superset.runSQLQuery();
let appointmentStatus = await page.locator('div.virtual-table-cell');

await expect(appointmentStatus).toContainText('Scheduled');
await superset.clearSQLEditor();

// replay
await page.goto(`${O3_URL}`);
await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await openmrs.cancelPatientAppointment();

// verify
await page.goto(`${SUPERSET_URL}/superset/sqllab`);
await superset.clearSQLEditor();
await page.getByRole('textbox').first().fill(appointmentStatusQuery);
await superset.runSQLQuery();

await expect(appointmentStatus).toContainText('Cancelled');
await superset.clearSQLEditor();
await openmrs.deletePatient();
});

test.afterEach(async ({ page }) => {
await page.close();
});
18 changes: 17 additions & 1 deletion e2e/utils/functions/openmrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export class OpenMRS {
await this.page.getByRole('button', { name: 'Delete Patient', exact: true }).click();
const message = await this.page.locator('//*[@id="patientFormVoided"]').textContent();
await expect(message?.includes('This patient has been deleted')).toBeTruthy();
await this.page.getByRole('link', { name: 'Log out' }).click();
}

async addPatientCondition() {
Expand All @@ -170,6 +169,14 @@ export class OpenMRS {
await this.page.getByRole('button', { name: 'Close', exact: true }).click();
}

async voidPatientCondition() {
await this.page.getByRole('link', { name: 'Conditions' }).click();
await this.page.getByRole('button', { name: 'Options' }).click();
await this.page.getByRole('menuitem', { name: 'Delete' }).click();
await this.page.getByRole('button', { name: 'Delete' }).click();
await expect(this.page.getByText('Condition Deleted')).toBeVisible();
}

async addPatientBiometrics() {
await this.page.getByRole('link', { name: 'Vitals & Biometrics' }).click();
await this.page.getByText('Record biometrics').click();
Expand Down Expand Up @@ -201,6 +208,15 @@ export class OpenMRS {
await expect(appointmentStatus).toHaveText('Scheduled');
}

async cancelPatientAppointment() {
await this.page.getByRole('link', { name: 'Appointments' }).click();
await this.page.getByRole('tab', { name: 'Today' }).click();
await this.page.getByRole('button', { name: 'Options' }).click();
await this.page.getByRole('menuitem', { name: 'Cancel' }).click();
await this.page.getByRole('button', { name: 'Cancel appointment' }).click();
await expect(this.page.getByText('Appointment cancelled successfully')).toBeVisible();
}

async goToLabOrderForm() {
await this.page.getByLabel('Clinical forms').click();
await delay(3000);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"!playwright-report/"
],
"scripts": {
"e2e-tests-pro": "npx playwright test",
"e2e-tests-pro": "npx playwright test openmrs-superset",
"e2e-tests-foss": "npx playwright test odoo-openmrs openmrs-senaite"
},
"publishConfig": {
Expand Down

0 comments on commit f4dd61d

Please sign in to comment.