Skip to content

Commit

Permalink
Merge branch 'coronasafe:develop' into Fix-ohcnetwork#7708
Browse files Browse the repository at this point in the history
  • Loading branch information
AshrafMd-1 authored May 21, 2024
2 parents 5be6262 + f71075d commit 8d90202
Show file tree
Hide file tree
Showing 27 changed files with 252 additions and 514 deletions.
56 changes: 50 additions & 6 deletions cypress/e2e/patient_spec/patient_prescription.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { PatientPage } from "../../pageobject/Patient/PatientCreation";
const patientPrescription = new PatientPrescription();
const loginPage = new LoginPage();
const patientPage = new PatientPage();
const medicineName = "DOLO";
const medicineBaseDosage = "4";
const medicineTargetDosage = "9";
const medicineFrequency = "Twice daily";
const medicineAdministerNote = "Medicine Administration Note";

describe("Patient Medicine Administration", () => {
before(() => {
Expand All @@ -18,25 +23,64 @@ describe("Patient Medicine Administration", () => {
cy.awaitUrl("/patients");
});

it("Add a new titrated medicine for a patient | Individual Administeration |", () => {
patientPage.visitPatient("Dummy Patient 5");
patientPrescription.visitMedicineTab();
patientPrescription.visitEditPrescription();
patientPrescription.clickAddPrescription();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine(medicineName);
patientPrescription.clickTitratedDosage();
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.enterTargetDosage(medicineTargetDosage);
patientPrescription.selectDosageFrequency(medicineFrequency);
cy.submitButton("Submit");
cy.verifyNotification("Medicine prescribed");
cy.closeNotification();
// Administer the medicine in edit form
patientPrescription.clickAdministerButton();
patientPrescription.enterAdministerDosage(medicineBaseDosage);
patientPrescription.enterAdministerNotes(medicineAdministerNote);
cy.submitButton("Administer Medicine");
cy.verifyNotification("Medicine(s) administered");
cy.closeNotification();
// Verify the Reflection on the Medicine
cy.verifyContentPresence("#medicine-preview", [
medicineName,
medicineBaseDosage,
medicineTargetDosage,
]);
patientPrescription.clickReturnToDashboard();
// Go to medicine tab and administer it again
patientPrescription.visitMedicineTab();
cy.verifyAndClickElement("#0", medicineName);
cy.submitButton("Administer");
patientPrescription.enterAdministerDosage(medicineBaseDosage);
cy.submitButton("Administer Medicine");
cy.verifyNotification("Medicine(s) administered");
});

it("Add a new medicine for a patient and verify the duplicate medicine validation", () => {
patientPage.visitPatient("Dummy Patient 4");
patientPrescription.visitMedicineTab();
patientPrescription.visitEditPrescription();
patientPrescription.clickAddPrescription();
patientPrescription.interceptMedibase();
patientPrescription.selectMedicinebox();
patientPrescription.selectMedicine("DOLO");
patientPrescription.enterDosage("4");
patientPrescription.selectDosageFrequency("Twice daily");
patientPrescription.selectMedicine(medicineName);
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.selectDosageFrequency(medicineFrequency);
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");
patientPrescription.selectMedicine(medicineName);
patientPrescription.enterDosage(medicineBaseDosage);
patientPrescription.selectDosageFrequency(medicineFrequency);
cy.submitButton("Submit");
cy.verifyNotification(
"Medicine - This medicine is already prescribed to this patient. Please discontinue the existing prescription to prescribe again.",
Expand Down
7 changes: 2 additions & 5 deletions cypress/e2e/shifting_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("Shifting section filter", () => {
shiftingPage.filterByFacility(
"Dummy Shifting",
"Dummy Shifting",
"District"
"District",
);

shiftingPage.facilityAssignedBadge().should("exist");
Expand All @@ -32,13 +32,10 @@ describe("Shifting section filter", () => {
"ASC Created Date",
"yes",
"yes",
"POSITIVE",
"no",
"MODERATE",
"9999999999"
"9999999999",
);

shiftingPage.diseaseStatusBadge().should("exist");
shiftingPage.orderingBadge().should("exist");
shiftingPage.breathlessnessLevelBadge().should("exist");
shiftingPage.phoneNumberBadge().should("exist");
Expand Down
34 changes: 30 additions & 4 deletions cypress/pageobject/Patient/PatientPrescription.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export class PatientPrescription {
clickAddPrescription() {
cy.contains("button", "Add Prescription Medication")
.should("be.visible")
.click();
cy.get("#add-prescription").scrollIntoView();
cy.verifyAndClickElement(
"#add-prescription",
"Add Prescription Medication",
);
}

interceptMedibase() {
Expand All @@ -16,6 +18,15 @@ export class PatientPrescription {
);
}

clickTitratedDosage() {
cy.get("#titrated-dosage").click();
}

clickAdministerButton() {
cy.get("#administer-medicine").should("be.visible");
cy.verifyAndClickElement("#administer-medicine", "Administer");
}

selectMedicinebox() {
cy.get(
"div#medicine_object input[placeholder='Select'][role='combobox']",
Expand All @@ -30,6 +41,18 @@ export class PatientPrescription {
cy.get("#base_dosage").type(doseAmount, { force: true });
}

enterAdministerDosage(dosage: string) {
cy.get("#dosage").type(dosage);
}

enterAdministerNotes(notes: string) {
cy.get("#administration_notes").type(notes);
}

enterTargetDosage(targetDosage: string) {
cy.get("#target_dosage").type(targetDosage, { force: true });
}

selectDosageFrequency(frequency: string) {
cy.clickAndSelectOption("#frequency", frequency);
}
Expand All @@ -54,7 +77,10 @@ export class PatientPrescription {
visitMedicineTab() {
cy.get("#consultation_tab_nav").scrollIntoView();
cy.get("#consultation_tab_nav").contains("Medicines").click();
cy.get("a[href='prescriptions']").first().click();
}

visitEditPrescription() {
cy.get("#edit-prescription").click();
}
}
export default PatientPrescription;
18 changes: 3 additions & 15 deletions cypress/pageobject/Shift/ShiftFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class ShiftingPage {
return cy.get("#is-up-shift");
}

diseaseStatusInput() {
return cy.get("#disease-status");
}

isAntenatalInput() {
return cy.get("#is-antenatal");
}
Expand Down Expand Up @@ -63,10 +59,6 @@ class ShiftingPage {
return cy.get("[data-testid='Current facility']");
}

diseaseStatusBadge() {
return cy.get("[data-testid='Disease status']");
}

orderingBadge() {
return cy.get("[data-testid='Ordering']");
}
Expand Down Expand Up @@ -98,7 +90,7 @@ class ShiftingPage {
filterByFacility(
origin_facility: string,
assigned_facility: string,
assigned_to: string
assigned_to: string,
) {
this.originFacilityInput().click().type(origin_facility);
cy.get("[role='option']").contains(origin_facility).click();
Expand All @@ -116,10 +108,9 @@ class ShiftingPage {
ordering: string,
emergency: string,
is_up_shift: string,
disease_status: string,
is_antenatal: string,
breathlessness_level: string,
patient_phone_number: string
patient_phone_number: string,
) {
this.orderingInput().click();
cy.get("[role='option']").contains(ordering).click();
Expand All @@ -130,9 +121,6 @@ class ShiftingPage {
this.isUpShiftInput().click();
cy.get("[role='option']").contains(is_up_shift).click();

this.diseaseStatusInput().click();
cy.get("[role='option']").contains(disease_status).click();

this.isAntenatalInput().click();
cy.get("[role='option']").contains(is_antenatal).click();

Expand All @@ -148,7 +136,7 @@ class ShiftingPage {
created_date_start: string,
created_date_end: string,
modified_date_start: string,
modified_date_end: string
modified_date_end: string,
) {
this.createdDateStartInput().click();
cy.get("[id^='headlessui-popover-panel-'] .care-l-angle-left-b")
Expand Down
7 changes: 0 additions & 7 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,6 @@ export const SAMPLE_FLOW_RULES = {
RECEIVED_AT_LAB: ["COMPLETED"],
};

export const DISEASE_STATUS = [
"POSITIVE",
"SUSPECTED",
"NEGATIVE",
"RECOVERED",
];

export const TEST_TYPE = [
"UNK",
"ANTIGEN",
Expand Down
55 changes: 55 additions & 0 deletions src/Common/hooks/useNotificationSubscriptionState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { useEffect, useState } from "react";
import routes from "../../Redux/api";
import request from "../../Utils/request/request";
import useAuthUser from "./useAuthUser";
import * as Sentry from "@sentry/browser";

export type NotificationSubscriptionState =
| "unsubscribed"
| "subscribed"
| "subscribed_on_other_device"
| "subscribed"
| "pending"
| "error";

/**
* This is a temporary hook and will be removed in the future.
*
* This hook is used to get the initial notification subscription state of the user.
* @returns NotificationSubscriptionState
*/
export default function useNotificationSubscriptionState(
dependencies: any[] = [],
) {
const { username } = useAuthUser();
const [subscriptionState, setSubscriptionState] =
useState<NotificationSubscriptionState>("pending");

const getSubscriptionState = async () => {
try {
const res = await request(routes.getUserPnconfig, {
pathParams: { username },
});

const reg = await navigator.serviceWorker.ready;
const subscription = await reg.pushManager.getSubscription();

if (!subscription && !res.data?.pf_endpoint) {
setSubscriptionState("unsubscribed");
} else if (subscription?.endpoint !== res.data?.pf_endpoint) {
setSubscriptionState("subscribed_on_other_device");
} else {
setSubscriptionState("subscribed");
}
} catch (error) {
setSubscriptionState("error");
Sentry.captureException(error);
}
};

useEffect(() => {
getSubscriptionState();
}, [username, ...dependencies]);

return subscriptionState;
}
15 changes: 14 additions & 1 deletion src/Components/ABDM/ABDMFacilityRecords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import useQuery from "../../Utils/request/useQuery";
import { formatDateTime } from "../../Utils/utils";
import Loading from "../Common/Loading";
import Page from "../Common/components/Page";
import CareIcon from "../../CAREUI/icons/CareIcon";
import ButtonV2 from "../Common/components/ButtonV2";

interface IProps {
facilityId: string;
Expand All @@ -21,7 +23,11 @@ const TableHeads = [
];

export default function ABDMFacilityRecords({ facilityId }: IProps) {
const { data: consentsResult, loading } = useQuery(routes.abha.listConsents, {
const {
data: consentsResult,
loading,
refetch,
} = useQuery(routes.abha.listConsents, {
query: { facility: facilityId, ordering: "-created_date" },
});

Expand Down Expand Up @@ -53,6 +59,13 @@ export default function ABDMFacilityRecords({ facilityId }: IProps) {
scope="col"
className="sticky right-0 top-0 py-3.5 pl-3 pr-4 sm:pr-6"
>
<ButtonV2
onClick={() => refetch()}
ghost
className="max-w-2xl text-sm text-gray-700 hover:text-gray-900"
>
<CareIcon icon="l-refresh" /> Refresh
</ButtonV2>
<span className="sr-only">View</span>
</th>
</tr>
Expand Down
Loading

0 comments on commit 8d90202

Please sign in to comment.