Skip to content

Commit

Permalink
Added test of patient_crud.cy.ts (#6135)
Browse files Browse the repository at this point in the history
* Added test for importing and configuring an asset

* Revert few changes

* nits

* Migrated to POM approach

* Migrated patient_crud to POM approach

* reverted some chnages

* FIx

* Merge conflicts

* Fixed test

* Added test for patient_test

* nits

* add responsiveness to virtual nursing assistant card (#6130)

* allow use stock as well (#6115)

* fixed responsive issue of 'Update Log' button in patient consultation page (#6113)

* fix multiple bed bug (#6111)

* Fixed typo in Date format in Asset management (#6105)

* Added padding to count block on patients page

* fixed date format in asset manage page

* show only items with no min value (#6103)

* check for id in response (#6100)

* Added Responsiveness to File upload (#6096)

* add responsiveness

* refactor

* remove overlap (#6094)

* fixed failing test

* Fix

* Fixed comments

* fix comments

* Fixed all comments

* Migrated test to new test suite

* Added upload file test

* fixed failing test

* Fix failing test

* Revert unwanted changes

* fixed conflict

* random failure fixed

* temporary fixed medicine selection

---------

Co-authored-by: Pranshu Aggarwal <[email protected]>
Co-authored-by: Gokulram A <[email protected]>
Co-authored-by: Kshitij Verma <[email protected]>
Co-authored-by: Mohammed Nihal <[email protected]>
  • Loading branch information
5 people authored Oct 20, 2023
1 parent 33f103d commit e452bb5
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 4 deletions.
17 changes: 16 additions & 1 deletion cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,27 @@ describe("Patient Creation with consultation", () => {
patientConsultationPage.interceptMediaBase();
patientConsultationPage.selectMedicinebox();
patientConsultationPage.waitForMediabaseStatusCode();
patientConsultationPage.prescribeMedicine();
patientConsultationPage.prescribefirstMedicine();
patientConsultationPage.enterDosage("3");
patientConsultationPage.selectDosageFrequency("Twice daily");
patientConsultationPage.submitPrescriptionAndReturn();
});

it("Edit created consultation to existing patient", () => {
updatePatientPage.visitUpdatedPatient();
patientConsultationPage.visitEditConsultationPage();
patientConsultationPage.fillIllnessHistory("editted");
patientConsultationPage.selectConsultationStatus(
"Referred from other hospital"
);
patientConsultationPage.updateSymptoms("FEVER");
patientConsultationPage.setSymptomsDate("01082023");
patientConsultationPage.updateConsultation();
patientConsultationPage.verifySuccessNotification(
"Consultation updated successfully"
);
});

afterEach(() => {
cy.saveLocalStorage();
});
Expand Down
78 changes: 78 additions & 0 deletions cypress/e2e/patient_spec/patient_manage.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress";
import LoginPage from "../../pageobject/Login/LoginPage";
import { PatientConsultationPage } from "../../pageobject/Patient/PatientConsultation";
import { PatientPage } from "../../pageobject/Patient/PatientCreation";

describe("Patient", () => {
const loginPage = new LoginPage();
const patientPage = new PatientPage();
const patientConsultationPage = new PatientConsultationPage();

before(() => {
loginPage.loginAsDisctrictAdmin();
cy.saveLocalStorage();
});

beforeEach(() => {
cy.restoreLocalStorage();
cy.awaitUrl("/patients");
});

// it("Create Patient shift requests.", () => {
// patientPage.visitPatient();
// patientConsultationPage.visitShiftRequestPage();
// patientConsultationPage.enterPatientShiftDetails(
// "Test User",
// phone_number,
// "Dummy Shifting",
// "Reason"
// );
// patientConsultationPage.createShiftRequest();
// patientConsultationPage.verifySuccessNotification(
// "Shift request created successfully"
// );
// });
// commented out the shifting request, as logic need to be re-visited

it("Post doctor notes for an already created patient", () => {
patientPage.visitPatient();
patientConsultationPage.visitDoctorNotesPage();
patientConsultationPage.addDoctorsNotes("Test Doctor Notes");
patientConsultationPage.postDoctorNotes();
patientConsultationPage.verifySuccessNotification(
"Note added successfully"
);
});

it("Edit prescription for an already created patient", () => {
patientPage.visitPatient();
patientConsultationPage.visitEditPrescriptionPage();
patientConsultationPage.clickAddPrescription();
patientConsultationPage.interceptMediaBase();
patientConsultationPage.selectMedicinebox();
patientConsultationPage.waitForMediabaseStatusCode();
patientConsultationPage.prescribesecondMedicine();
patientConsultationPage.enterDosage("4");
patientConsultationPage.selectDosageFrequency("Twice daily");
patientConsultationPage.submitPrescription();
});

it("Upload consultations file ", () => {
patientPage.visitPatient();
patientConsultationPage.visitFilesPage();
patientConsultationPage.uploadFile();
patientConsultationPage.clickUploadFile();
});

it("Discharge a patient", () => {
patientPage.visitPatient();
patientConsultationPage.clickDischargePatient();
patientConsultationPage.selectDischargeReason("Recovered");
patientConsultationPage.addDischargeNotes("Discharge notes");
patientConsultationPage.confirmDischarge();
});

afterEach(() => {
cy.saveLocalStorage();
});
});
146 changes: 144 additions & 2 deletions cypress/pageobject/Patient/PatientConsultation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export class PatientConsultationPage {
selectConsultationStatus(status: string) {
cy.get("#consultation_status").scrollIntoView();
cy.get("#consultation_status").should("be.visible");
cy.get("#consultation_status")
.click()
.then(() => {
Expand Down Expand Up @@ -83,10 +85,18 @@ export class PatientConsultationPage {
cy.intercept("GET", "**/api/v1/medibase/**").as("getMediaBase");
}

prescribeMedicine() {
prescribefirstMedicine() {
cy.get("div#medicine_object input[placeholder='Select'][role='combobox']")
.click()
.type("dolo{enter}");
.type("dolo")
.type("{downarrow}{enter}");
}

prescribesecondMedicine() {
cy.get("div#medicine_object input[placeholder='Select'][role='combobox']")
.click()
.type("dolo")
.type("{downarrow}{downarrow}{enter}");
}

selectMedicinebox() {
Expand All @@ -95,6 +105,23 @@ export class PatientConsultationPage {
).click();
}

visitFilesPage() {
cy.get("a").contains("Files").click();
}

uploadFile() {
cy.get("#file_upload_patient").selectFile(
"cypress/fixtures/sampleAsset.xlsx",
{ force: true }
);
}

clickUploadFile() {
cy.intercept("POST", "**/api/v1/files/").as("uploadFile");
cy.get("#upload_file_button").click();
cy.wait("@uploadFile").its("response.statusCode").should("eq", 201);
}

waitForMediabaseStatusCode() {
cy.wait("@getMediaBase").its("response.statusCode").should("eq", 200);
}
Expand All @@ -119,4 +146,119 @@ export class PatientConsultationPage {
cy.get("[data-testid='return-to-patient-dashboard']").click();
cy.wait("@submitPrescription").its("response.statusCode").should("eq", 201);
}

visitEditConsultationPage() {
cy.get("#view_consulation_updates").click();
cy.get("button").contains("Edit Consultation Details").click();
}

setSymptomsDate(date: string) {
cy.get("#symptoms_onset_date")
.click()
.then(() => {
cy.get("[placeholder='DD/MM/YYYY']").type(date);
});
}

updateConsultation() {
cy.intercept("PUT", "**/api/v1/consultation/**").as("updateConsultation");
cy.get("#submit").contains("Update Consultation").click();
cy.wait("@updateConsultation").its("response.statusCode").should("eq", 200);
}

verifySuccessNotification(message: string) {
cy.verifyNotification(message);
}

updateSymptoms(symptoms: string) {
this.selectSymptoms(symptoms);
cy.get("#symptoms").click();
}

visitShiftRequestPage() {
cy.get("#create_shift_request").click();
}

enterPatientShiftDetails(
name: string,
phone_number: string,
facilityName: string,
reason: string
) {
cy.get("#refering_facility_contact_name").type(name);
cy.get("#refering_facility_contact_number").type(phone_number);
cy.get("input[name='assigned_facility']")
.type(facilityName)
.then(() => {
cy.get("[role='option']").first().click();
});
cy.get("#reason").type(reason);
}

createShiftRequest() {
cy.intercept("POST", "**/api/v1/shift/").as("createShiftRequest");
cy.get("#submit").click();
cy.wait("@createShiftRequest").its("response.statusCode").should("eq", 201);
}

visitDoctorNotesPage() {
cy.get("#patient_doctor_notes").click();
}

addDoctorsNotes(notes: string) {
cy.get("#doctor_notes_textarea").type(notes);
}

postDoctorNotes() {
cy.intercept("POST", "**/api/v1/patient/*/notes").as("postDoctorNotes");
cy.get("#submit").contains("Post Your Note").click();
cy.wait("@postDoctorNotes").its("response.statusCode").should("eq", 201);
}

clickDischargePatient() {
cy.get("#discharge_patient_from_care").click();
}

selectDischargeReason(reason: string) {
cy.get("#discharge_reason")
.click()
.then(() => {
cy.get("[role='option']").contains(reason).click();
});
}

addDischargeNotes(notes: string) {
cy.get("#discharge_notes").type(notes);
}

confirmDischarge() {
cy.intercept("POST", "**/api/v1/consultation/*/discharge_patient/").as(
"dischargePatient"
);
cy.get("#submit").contains("Confirm Discharge").click();
cy.wait("@dischargePatient").its("response.statusCode").should("eq", 200);
}

discontinuePreviousPrescription() {
cy.intercept(
"POST",
"**/api/v1/consultation/*/prescriptions/*/discontinue/"
).as("deletePrescription");
cy.get("button").contains("Discontinue").click();
cy.get("#submit").contains("Discontinue").click();
cy.wait("@deletePrescription").its("response.statusCode").should("eq", 200);
}

visitEditPrescriptionPage() {
cy.get("#consultation_tab_nav").contains("Medicines").click();
cy.get("a[href='prescriptions']").first().click();
}

submitPrescription() {
cy.intercept("POST", "**/api/v1/consultation/*/prescriptions/").as(
"submitPrescription"
);
cy.get("#submit").contains("Submit").click();
cy.wait("@submitPrescription").its("response.statusCode").should("eq", 201);
}
}
6 changes: 6 additions & 0 deletions cypress/pageobject/Patient/PatientCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export class PatientPage {
cy.wait("@getFacilities").its("response.statusCode").should("eq", 200);
}

visitPatient() {
cy.intercept("GET", "**/api/v1/consultation/**").as("getPatient");
cy.get("[data-cy='patient']").first().click();
cy.wait("@getPatient").its("response.statusCode").should("eq", 200);
}

selectFacility(facilityName: string) {
cy.get("input[name='facilities']")
.type(facilityName)
Expand Down
1 change: 1 addition & 0 deletions src/Components/Facility/ConsultationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const ConsultationCard = (props: ConsultationProps) => {
</div>
<div className="mt-4 flex w-full flex-col justify-between gap-1 md:flex-row">
<ButtonV2
id="view_consulation_updates"
className="h-auto whitespace-pre-wrap border border-gray-500 bg-white text-black hover:bg-gray-300"
onClick={() =>
navigate(
Expand Down
8 changes: 7 additions & 1 deletion src/Components/Facility/ConsultationDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export const ConsultationDetails = (props: any) => {
</ButtonV2>
) : (
<ButtonV2
id="create_shift_request"
onClick={() =>
navigate(
`/facility/${patientData.facility}/patient/${patientData.id}/shift/new`
Expand Down Expand Up @@ -352,6 +353,7 @@ export const ConsultationDetails = (props: any) => {
Patient Details
</Link>
<Link
id="patient_doctor_notes"
href={`/facility/${patientData.facility}/patient/${patientData.id}/notes`}
className="btn btn-primary m-1 w-full hover:text-white"
>
Expand Down Expand Up @@ -450,6 +452,7 @@ export const ConsultationDetails = (props: any) => {
</ButtonV2>

<ButtonV2
id="discharge_patient_from_care"
onClick={() => setOpenDischargeDialog(true)}
disabled={!!consultationData.discharge_date}
>
Expand Down Expand Up @@ -496,7 +499,10 @@ export const ConsultationDetails = (props: any) => {
<div className="mt-4 w-full border-b-2 border-gray-200">
<div className="overflow-x-auto sm:flex sm:items-baseline">
<div className="mt-4 sm:mt-0">
<nav className="flex space-x-6 overflow-x-auto pb-2 pl-2 ">
<nav
className="flex space-x-6 overflow-x-auto pb-2 pl-2 "
id="consultation_tab_nav"
>
{CONSULTATION_TABS.map((p: OptionsType) => {
if (p.text === "FEED") {
if (
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Patient/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ export const FileUpload = (props: FileUploadProps) => {
<CareIcon className="care-l-file-upload-alt text-lg" />
{t("choose_file")}
<input
id="file_upload_patient"
title="changeFile"
onChange={onFileChange}
type="file"
Expand All @@ -1542,6 +1543,7 @@ export const FileUpload = (props: FileUploadProps) => {
Open Camera
</ButtonV2>
<ButtonV2
id="upload_file_button"
authorizeFor={NonReadOnlyUsers}
disabled={!file || !uploadFileName || !isActive}
onClick={() => handleUpload({ status })}
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Patient/PatientNotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const PatientNotes = (props: PatientNotesProps) => {
/>
<h3 className="pl-10 text-lg">Add new notes</h3>
<textarea
id="doctor_notes_textarea"
rows={3}
value={noteField}
placeholder="Type your Note"
Expand All @@ -122,6 +123,7 @@ const PatientNotes = (props: PatientNotesProps) => {
/>
<div className="flex w-full justify-end pr-10">
<ButtonV2
id="submit"
authorizeFor={NonReadOnlyUsers}
onClick={onAddNote}
disabled={!patientActive}
Expand Down

0 comments on commit e452bb5

Please sign in to comment.