Skip to content

Commit

Permalink
Merge branch 'abdm-improvements' of github.com:coronasafe/care_fe int…
Browse files Browse the repository at this point in the history
…o abdm-improvements
  • Loading branch information
khavinshankar committed May 20, 2024
2 parents 68a3aa6 + 67eb40f commit 6b3abdb
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 33 deletions.
2 changes: 2 additions & 0 deletions cypress/e2e/patient_spec/patient_logupdate.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => {
cy.verifyNotification("Normal Log Updates details created successfully");
cy.closeNotification();
// edit the card and verify the data.
cy.contains("Daily Rounds").click();
patientLogupdate.clickLogupdateCard("#dailyround-entry", patientCategory);
cy.verifyContentPresence("#consultation-preview", [
patientCategory,
Expand All @@ -109,6 +110,7 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => {
patientLogupdate.typeDiastolic(patientModifiedDiastolic);
cy.submitButton("Continue");
cy.verifyNotification("Normal Log Updates details updated successfully");
cy.contains("Daily Rounds").click();
patientLogupdate.clickLogupdateCard("#dailyround-entry", patientCategory);
cy.verifyContentPresence("#consultation-preview", [
patientModifiedDiastolic,
Expand Down
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
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;
11 changes: 11 additions & 0 deletions src/Components/ABDM/ABDMRecordsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ export default function ABDMRecordsTab({ patientId }: IProps) {
<Loading />;
}

if (!data?.results.length) {
return (
<div className="mt-12 flex flex-col items-center justify-center gap-2.5">
<p className="font-semibold text-gray-600">No Records found</p>
<p className="text-sm text-gray-600">
Raise a consent request to fetch patient records over ABDM
</p>
</div>
);
}

return (
<div className="mt-6 flex flex-col gap-6">
{data?.results.map((record) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
const [ventilatorSocketUrl, setVentilatorSocketUrl] = useState<string>();
const [monitorBedData, setMonitorBedData] = useState<AssetBedModel>();
const [ventilatorBedData, setVentilatorBedData] = useState<AssetBedModel>();
const [showEvents, setShowEvents] = useState(false);
const [showEvents, setShowEvents] = useState(true);

const vitals = useVitalsAspectRatioConfig({
default: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export default function EventsList() {
isLast={items.indexOf(item) == items.length - 1}
>
{(() => {
const values = Object.entries(item.value).filter(
([_, value]) => value !== null && value !== undefined,
const entries = Object.entries(item.value).filter(
([_, value]) => value != null && value !== "",
);

if (values.length === 0) {
if (entries.length === 0) {
return (
<div className="flex w-full flex-col items-center gap-2 md:flex-row">
<span className="text-xs uppercase text-gray-700">
Expand All @@ -61,6 +61,8 @@ export default function EventsList() {
);
}

const values = Object.fromEntries(entries);

switch (item.event_type.name) {
case "INTERNAL_TRANSFER":
case "CLINICAL":
Expand Down
42 changes: 25 additions & 17 deletions src/Components/Facility/ConsultationDetails/Events/GenericEvent.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { ReactNode } from "react";
interface IProps {
values: Record<string, any>;
values: Record<string, unknown>;
}

/**
* object - array, date
*/

const formatValue = (value: unknown, key?: string): ReactNode => {
if (value === undefined || value === null) {
if (value == null) {
return "N/A";
}

Expand All @@ -17,11 +16,11 @@ const formatValue = (value: unknown, key?: string): ReactNode => {
}

if (typeof value === "number") {
return value;
return value % 1 ? value.toFixed(2) : value;
}

if (typeof value === "string") {
const trimmed = value.trim();
const trimmed = value.trim().replaceAll(/_/g, " ");

if (trimmed === "") {
return "Empty";
Expand All @@ -41,26 +40,36 @@ const formatValue = (value: unknown, key?: string): ReactNode => {
if (typeof value === "object") {
if (Array.isArray(value)) {
if (value.length === 0) {
return `No ${key?.replace(/_/g, " ")}`;
return `No ${key?.replaceAll(/_/g, " ")}`;
}

return value.map((v) => formatValue(v, key)).join(", ");
return (
<ul className="list-disc space-y-2 pl-4">
{value.map((v) => (
<li>{formatValue(v, key)}</li>
))}
</ul>
);
}

if (value instanceof Date) {
return value.toLocaleString();
}

if (Object.entries(value).length === 0) {
return `No ${key?.replace(/_/g, " ")}`;
const entries = Object.entries(value).filter(
([_, value]) => value != null && value !== "",
);

if (entries.length === 0) {
return `No ${key?.replaceAll(/_/g, " ")}`;
}

return Object.entries(value).map(([key, value]) => (
return entries.map(([key, value]) => (
<div className="flex flex-col items-center gap-2 md:flex-row">
<span className="text-xs uppercase text-gray-700">
{key.replace(/_/g, " ")}
{key.replaceAll(/_/g, " ")}
</span>
<span className="text-sm font-semibold text-gray-700">
<span className="text-sm font-semibold capitalize text-gray-700">
{formatValue(value, key)}
</span>
</div>
Expand All @@ -70,14 +79,13 @@ const formatValue = (value: unknown, key?: string): ReactNode => {
return JSON.stringify(value);
};

export default function GenericEvent({ values }: IProps) {
console.log("value", values);
export default function GenericEvent(props: IProps) {
return (
<div className="flex w-full flex-col gap-4 rounded-lg border border-gray-400 p-4 @container">
{values.map(([key, value]: [string, any]) => (
<div className="flex w-full flex-col items-center gap-2 md:flex-row">
{Object.entries(props.values).map(([key, value]) => (
<div className="flex w-full flex-col items-start gap-2">
<span className="text-xs uppercase text-gray-700">
{key.replace(/_/g, " ")}
{key.replaceAll(/_/g, " ")}
</span>
<span className="break-all text-sm font-semibold text-gray-700">
{formatValue(value, key)}
Expand Down
5 changes: 5 additions & 0 deletions src/Components/Facility/ConsultationDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ export const ConsultationDetails = (props: any) => {
)
return null; // Hide feed tab
}

if (p.text === "ABDM" && !patientData.abha_number) {
return null;
}

return (
<Link
key={p.text}
Expand Down
1 change: 1 addition & 0 deletions src/Components/Medicine/CreatePrescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function CreatePrescriptionForm(props: {
{props.prescription.dosage_type !== "PRN" &&
props.prescription.prescription_type !== "DISCHARGE" && (
<CheckBoxFormField
id="titrated-dosage"
label={t("titrate_dosage")}
name="Titrate Dosage"
value={field("dosage_type").value === "TITRATED"}
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Medicine/ManagePrescriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export default function ManagePrescriptions() {

return (
<Page title={t("manage_prescriptions")}>
<div className="mx-auto flex w-full max-w-4xl flex-col gap-10 rounded bg-white p-6 transition-all sm:rounded-xl sm:p-12">
<div
className="mx-auto flex w-full max-w-4xl flex-col gap-10 rounded bg-white p-6 transition-all sm:rounded-xl sm:p-12"
id="medicine-preview"
>
<div className="flex flex-col gap-10 divide-y-2 divide-dashed divide-gray-600">
<div>
<h3 className="mb-4 text-lg font-semibold">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default function AdministrationEventCell({
/>
</DialogModal>
<button
id="administration-symbol"
className="scale-100 transition-transform duration-200 ease-in-out hover:scale-110"
onClick={() => setShowTimeline(true)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => {
!!data?.results && (
<>
<ButtonV2
id="edit-prescription"
variant="secondary"
border
href="prescriptions"
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 @@ -82,7 +82,7 @@ export default function PrescriptionBuilder({
className="mt-4 w-full bg-gray-200 text-gray-700 hover:bg-gray-300 hover:text-gray-900 focus:bg-gray-100 focus:text-gray-900"
disabled={disabled}
>
<div className="flex w-full justify-start gap-2">
<div className="flex w-full justify-start gap-2" id="add-prescription">
<CareIcon icon="l-plus" className="text-lg" />
<span className="font-bold">
{t(is_prn ? "add_prn_prescription" : "add_prescription_medication")}
Expand Down
1 change: 1 addition & 0 deletions src/Components/Medicine/PrescriptionDetailCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function PrescriptionDetailCard({
prescription.prescription_type !== "DISCHARGE" && (
<div className="flex flex-col-reverse items-end gap-2 sm:flex-row">
<ButtonV2
id="administer-medicine"
disabled={prescription.discontinued}
onClick={props.onAdministerClick}
type="button"
Expand Down

0 comments on commit 6b3abdb

Please sign in to comment.