Skip to content

Commit

Permalink
Merge branch 'develop' into migrate-consultation-feed-to-newer-compon…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
rithviknishad committed May 7, 2024
2 parents e718b46 + ca4040e commit 05869a0
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 58 deletions.
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,33 @@ Authenticate to staging API with any of the following credentials

#### 🧪 Run cypress tests

Ensure that the development server is running and then run the cypress tests in either of the ways described below.
To run cypress tests locally, you'll need to setup the backend to run locally and load dummy data required for cypress to the database. See [docs](https://github.com/coronasafe/care#self-hosting).

Once backend is running locally, you'll have to ensure your local front-end is connected to local backend, by setting the `CARE_API` env.

```env
#.env
CARE_API=http://127.0.0.1:9000
```

Once done, start the development server by running

```sh
npm run dev
```

Once development server is running, then run the cypress tests in either of the ways described below.

```sh
npm run cypress:run # To run all tests in headless mode.
```

```sh
npm run cypress:run:gui # To run all tests in headed mode.
```

```sh
$ npm run cypress:run # To run all tests in headless mode.
$ npm run cypress:run:gui # To run all tests in headed mode.
$ npm run cypress:open # To debug and run tests individually.
npm run cypress:open # To debug and run tests individually.
```

- Failed test screenshots are saved in `cypress/screenshots`
Expand Down
32 changes: 32 additions & 0 deletions cypress/e2e/patient_spec/patient_logupdate.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,38 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => {
cy.verifyContentPresence("#basic-information", [additionalSymptoms]);
});

it("Create a normal log update to verify MEWS Score Functionality", () => {
patientPage.visitPatient(domicilaryPatient);
patientConsultationPage.clickEditConsultationButton();
patientConsultationPage.selectPatientSuggestion("Domiciliary Care");
cy.submitButton("Update Consultation");
cy.verifyNotification("Consultation updated successfully");
cy.closeNotification();
patientLogupdate.clickLogupdate();
// Verify the MEWS Score reflection
patientLogupdate.selectPatientCategory(patientCategory);
patientLogupdate.typeSystolic(patientSystolic);
patientLogupdate.typeDiastolic(patientDiastolic);
patientLogupdate.typePulse(patientPulse);
patientLogupdate.typeTemperature(patientTemperature);
patientLogupdate.typeRespiratory(patientRespiratory);
cy.get("#consciousness_level-2").click();
cy.submitButton("Save");
cy.verifyNotification("Consultation Updates details created successfully");
cy.closeNotification();
cy.verifyContentPresence("#consultation-buttons", ["9"]);
// Verify the Incomplete data will give blank info
patientLogupdate.clickLogupdate();
patientLogupdate.selectPatientCategory(patientCategory);
patientLogupdate.typeSystolic(patientSystolic);
patientLogupdate.typeDiastolic(patientDiastolic);
patientLogupdate.typePulse(patientPulse);
cy.submitButton("Save");
cy.verifyNotification("Consultation Updates details created successfully");
cy.closeNotification();
cy.verifyContentPresence("#consultation-buttons", ["-"]);
});

afterEach(() => {
cy.saveLocalStorage();
});
Expand Down
15 changes: 0 additions & 15 deletions cypress/e2e/patient_spec/patient_manage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ 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";
import PatientPrescription from "../../pageobject/Patient/PatientPrescription";

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

before(() => {
loginPage.loginAsDisctrictAdmin();
Expand Down Expand Up @@ -45,19 +43,6 @@ describe("Patient", () => {
cy.verifyNotification("Note added successfully");
});

it("Edit prescription for an already created patient", () => {
patientPage.visitPatient("Dummy Patient 4");
patientPrescription.visitEditPrescriptionPage();
patientPrescription.clickAddPrescription();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine("DOLO");
patientPrescription.enterDosage("4");
patientPrescription.selectDosageFrequency("Twice daily");
cy.submitButton("Submit");
cy.verifyNotification("Medicine prescribed");
});

afterEach(() => {
cy.saveLocalStorage();
});
Expand Down
49 changes: 49 additions & 0 deletions cypress/e2e/patient_spec/patient_prescription.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import PatientPrescription from "../../pageobject/Patient/PatientPrescription";
import LoginPage from "../../pageobject/Login/LoginPage";
import { PatientPage } from "../../pageobject/Patient/PatientCreation";

const patientPrescription = new PatientPrescription();
const loginPage = new LoginPage();
const patientPage = new PatientPage();

describe("Patient Medicine Administration", () => {
before(() => {
loginPage.loginAsDisctrictAdmin();
cy.saveLocalStorage();
});

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/patients");
});

it("Add a new medicine for a patient and verify the duplicate medicine validation", () => {
patientPage.visitPatient("Dummy Patient 4");
patientPrescription.visitMedicineTab();
patientPrescription.clickAddPrescription();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine("DOLO");
patientPrescription.enterDosage("4");
patientPrescription.selectDosageFrequency("Twice daily");
cy.submitButton("Submit");
cy.verifyNotification("Medicine prescribed");
cy.closeNotification();
// verify the duplicate medicine error message
patientPrescription.clickAddPrescription();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine("DOLO");
patientPrescription.enterDosage("4");
patientPrescription.selectDosageFrequency("Twice daily");
cy.submitButton("Submit");
cy.verifyNotification(
"Medicine - This medicine is already prescribed to this patient. Please discontinue the existing prescription to prescribe again.",
);
});

afterEach(() => {
cy.saveLocalStorage();
});
});
10 changes: 5 additions & 5 deletions cypress/pageobject/Patient/PatientPrescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export class PatientPrescription {
selectMedicine(medicine: string) {
cy.searchAndSelectOption(
"div#medicine_object input[placeholder='Select'][role='combobox']",
medicine
medicine,
);
}

selectMedicinebox() {
cy.get(
"div#medicine_object input[placeholder='Select'][role='combobox']"
"div#medicine_object input[placeholder='Select'][role='combobox']",
).click();
}

Expand All @@ -37,21 +37,21 @@ export class PatientPrescription {
clickReturnToDashboard() {
cy.verifyAndClickElement(
"[data-testid='return-to-patient-dashboard']",
"Return to Patient Dashboard"
"Return to Patient Dashboard",
);
}

discontinuePreviousPrescription() {
cy.intercept(
"POST",
"**/api/v1/consultation/*/prescriptions/*/discontinue/"
"**/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() {
visitMedicineTab() {
cy.get("#consultation_tab_nav").scrollIntoView();
cy.get("#consultation_tab_nav").contains("Medicines").click();
cy.get("a[href='prescriptions']").first().click();
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ExternalResult/ResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default function ResultList() {
});
}

if (loading) {
if (loading || !data) {
manageResults = (
<tr className="bg-white">
<td colSpan={5}>
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import ConfirmDialog from "../Common/ConfirmDialog.js";
import request from "../../Utils/request/request.js";
import routes from "../../Redux/api.js";
import useQuery from "../../Utils/request/useQuery.js";
import { t } from "i18next";

const Loading = lazy(() => import("../Common/Loading"));
const PageTitle = lazy(() => import("../Common/PageTitle"));
Expand Down Expand Up @@ -1477,7 +1478,7 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => {
>
<UserAutocompleteFormField
name={"treating_physician"}
label="Treating Physician"
label={t("treating_doctor")}
placeholder="Attending Doctors Name and Designation"
required
value={
Expand Down
25 changes: 17 additions & 8 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import CircularProgress from "../Common/components/CircularProgress";
import { FacilitySelect } from "../Common/FacilitySelect";
import { FacilityModel } from "./models";
import dayjs from "../../Utils/dayjs";
import { FieldError } from "../Form/FieldValidators";

interface PreDischargeFormInterface {
new_discharge_reason: number | null;
Expand Down Expand Up @@ -121,15 +122,22 @@ const DischargeModal = ({

if (
preDischargeForm.new_discharge_reason ==
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id &&
!preDischargeForm.discharge_notes.trim()
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
) {
setErrors({
...errors,
discharge_notes: "Please enter the cause of death",
});
setIsSendingDischargeApi(false);
return;
const newErrors: Record<string, FieldError> = {};

if (!preDischargeForm.discharge_notes.trim()) {
newErrors["discharge_notes"] = "Please enter the cause of death";
}
if (!preDischargeForm.death_confirmed_doctor?.trim()) {
newErrors["death_confirmed_doctor"] = "Field is required";
}

if (Object.entries(newErrors).length) {
setErrors({ ...errors, ...newErrors });
setIsSendingDischargeApi(false);
return;
}
}

const dischargeDetails = {
Expand Down Expand Up @@ -310,6 +318,7 @@ const DischargeModal = ({
<TextFormField
name="death_confirmed_by"
label="Confirmed By"
error={errors.death_confirmed_doctor}
value={preDischargeForm.death_confirmed_doctor ?? ""}
onChange={(e) => {
setPreDischargeForm((form) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Medicine/CreatePrescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function CreatePrescriptionForm(props: {
optionValue={(key) => key}
/>
{field("dosage_type").value === "TITRATED" ? (
<div className="flex w-full gap-4">
<div className="flex w-full flex-[2] gap-4">
<DosageFormField
className="flex-1"
label={t("start_dosage")}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Medicine/EditPrescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default function EditPrescriptionForm(props: Props) {
optionValue={(key) => key}
/>
{field("dosage_type").value === "TITRATED" ? (
<div className="flex w-full gap-4">
<div className="flex w-full flex-[2] gap-4">
<DosageFormField
className="flex-1"
label={t("start_dosage")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default function MedicineAdministrationTableRow({
<span>{t("edit_caution_note")}</span>
</div>
}
className="w-full max-w-3xl lg:min-w-[600px]"
className="w-full max-w-4xl lg:min-w-[768px]"
>
<EditPrescriptionForm
initial={prescription}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Medicine/PrescriptionBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default function PrescriptionBuilder({
<span>{t("modification_caution_note")}</span>
</div>
}
className="w-full max-w-3xl lg:min-w-[600px]"
className="w-full max-w-4xl lg:min-w-[768px]"
>
<CreatePrescriptionForm
prescription={
Expand Down
14 changes: 8 additions & 6 deletions src/Components/Medicine/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const PRESCRIPTION_COMPARE_FIELDS: (keyof Prescription)[] = [
"medicine",
"days",
"discontinued",
"target_dosage",
"base_dosage",
"frequency",
"indicator",
Expand Down Expand Up @@ -77,11 +78,12 @@ export const AdministrationDosageValidator = (
if (value?.split(" ")[1] !== base_dosage?.split(" ")[1])
return "Unit must be the same as start and target dosage's unit";

if (
baseDosage &&
targetDosage &&
(valueDosage < baseDosage || valueDosage > targetDosage)
)
return "Dosage should be between start and target dosage";
if (baseDosage && targetDosage) {
const [min, max] = [baseDosage, targetDosage].sort((a, b) => a - b);

if (!(min <= valueDosage && valueDosage <= max)) {
return "Dosage should be between start and target dosage";
}
}
};
};
2 changes: 1 addition & 1 deletion src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export default function PatientInfoCard(props: {
consultation?.deprecated_verified_by) && (
<div className="text-sm" id="treating-physician">
<span className="font-semibold leading-relaxed">
Treating Physician:{" "}
{t("treating_doctor")}:{" "}
</span>
{consultation?.treating_physician_object
? `${consultation?.treating_physician_object.first_name} ${consultation?.treating_physician_object.last_name}`
Expand Down

0 comments on commit 05869a0

Please sign in to comment.