Skip to content

Commit

Permalink
OZ-336: Voiding an obs in OpenMRS gets reflected in the observations …
Browse files Browse the repository at this point in the history
…dataset in Superset
  • Loading branch information
kdaud committed Feb 28, 2024
1 parent 58f2838 commit 25d868f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
46 changes: 45 additions & 1 deletion e2e/tests/testAnalyticsIntegration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.beforeEach(async ({ page }) => {

await expect(page).toHaveURL(/.*home/);
});

/*
test('Adding an OpenMRS patient syncs patient into patients table in Superset', async ({ page }) => {
// setup
const homePage = new HomePage(page);
Expand Down Expand Up @@ -498,6 +498,50 @@ test('Adding an OpenMRS appointment syncs appointment into appointments table in
await page.getByRole('tab', { name: 'Query history' }).click();
await homePage.clearSQLEditor();
});
*/
test('Voiding an obs in OpenMRS gets reflected in the observations dataset in Superset', async ({ page }) => {
// setup
const homePage = new HomePage(page);
await homePage.createPatient();
await homePage.startPatientVisit();
const patient_uuid = await homePage.getPatientUUID();
await homePage.addPatientBiometrics();

// replay
await homePage.goToSuperset();
await expect(page).toHaveURL(/.*superset/);
await homePage.selectDBSchema();
await homePage.clearSQLEditor();
let obsVoidedQuery = `SELECT obs_voided FROM Observations WHERE patient_uuid like '${patient_uuid}';`;

await page.getByRole('textbox').first().fill(obsVoidedQuery);
await homePage.runSQLQuery();

let firstObsState = await page.locator('div.virtual-table-cell:nth-child(1)');
let secondObsState = await page.locator('div.virtual-table-cell:nth-child(2)');
let thirdObsState = await page.locator('div.virtual-table-cell:nth-child(3)');
await expect(firstObsState).toContainText('false');
await expect(thirdObsState).toContainText('false');
await expect(secondObsState).toContainText('false');

await page.goto(`${E2E_BASE_URL}/openmrs/spa/home`);
await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await homePage.discontinueAnOpenMRSEncounter();

// verify
await page.goto(`${E2E_ANALYTICS_URL}/superset/sqllab`);
await homePage.clearSQLEditor();

await page.getByRole('textbox').first().fill(obsVoidedQuery);
await homePage.runSQLQuery();

await expect(firstObsState).toContainText('true');
await expect(thirdObsState).toContainText('true');
await expect(secondObsState).toContainText('true');

await page.getByRole('tab', { name: 'Results' }).click();
await homePage.clearSQLEditor();
});

test.afterEach(async ({ page }) => {
const homePage = new HomePage(page);
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/testSenaiteIntegration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ test('Voiding a synced lab order cancels corresponding analysis request in SENAI
// replay
await page.goto(`${E2E_BASE_URL}`);
await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await homePage.discontinueLabOrder();
await homePage.discontinueAnOpenMRSEncounter();

// verify
await homePage.goToSENAITE();
Expand Down
25 changes: 24 additions & 1 deletion e2e/utils/functions/testBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,29 @@ export class HomePage {
await expect(this.page.getByText('OpenMRS ID', {exact: true})).toBeVisible();
}

async extractUUIDFromURL(url) {
// Regular expression to match UUID in URL
var regex = /\/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\//;

var match = regex.exec(url);

// If a match is found, return the UUID, else return null
if (match && match.length > 1) {
return match[1].toString();
} else {
return null;
}
}

async getPatientUUID() {
await this.page.goto(`${E2E_BASE_URL}/openmrs/spa/home`);
await this.patientSearchIcon().click();
await this.patientSearchBar().type(`${patientName.firstName + ' ' + patientName.givenName}`);
await this.page.getByRole('link', { name: `${patientFullName}` }).first().click();
let url = await this.page.url();
return this.extractUUIDFromURL(url);
}

async startPatientVisit() {
await this.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`);
await this.page.getByRole('button', { name: 'Start a visit' }).click();
Expand Down Expand Up @@ -286,7 +309,7 @@ export class HomePage {
await delay(5000);
}

async discontinueLabOrder() {
async discontinueAnOpenMRSEncounter() {
await this.page.getByRole('link', { name: 'Visits' }).click();
await this.page.getByRole('tab', { name: 'All encounters' }).click();
await this.page.getByRole('button', { name: 'Options', exact: true }).click();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"proE2ETests": "npx playwright test",
"proE2ETests": "npx playwright test Analytics",
"fossE2ETests": "npx playwright test Odoo Senaite"
},
"keywords": [],
Expand Down

0 comments on commit 25d868f

Please sign in to comment.