Skip to content

Commit

Permalink
ft : add reject order submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jabahum committed Nov 24, 2023
1 parent 150140f commit 22c87b0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
59 changes: 56 additions & 3 deletions src/reject-order/reject-order-dialog.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";

import {
Button,
Expand All @@ -18,9 +18,12 @@ import {
} from "@carbon/react";
import { useTranslation } from "react-i18next";
import styles from "./reject-order-dialog.scss";
import { Result } from "../work-list/work-list.resource";
import { RejectOrder } from "./reject-order-dialog.resource";
import { showNotification, showToast } from "@openmrs/esm-framework";

interface RejectOrderDialogProps {
order: string;
order: Result;
closeModal: () => void;
}

Expand All @@ -29,8 +32,38 @@ const RejectOrderDialog: React.FC<RejectOrderDialogProps> = ({
closeModal,
}) => {
const { t } = useTranslation();

const [notes, setNotes] = useState("");

const rejectOrder = async (event) => {
event.preventDefault();

const payload = {
fulfillerStatus: "DECLINED",
instructions: notes,
};
RejectOrder(order.uuid, payload).then(
(resp) => {
showToast({
critical: true,
title: t("rejectOrder", "Rejected Order"),
kind: "success",
description: t(
"successfullyrejected",
`You have successfully rejected an Order with OrderNumber ${order.orderNumber} `
),
});
closeModal();
},
(err) => {
showNotification({
title: t(`errorRejecting order', 'Error Rejecting a order`),
kind: "error",
critical: true,
description: err?.message,
});
}
);
};

return (
Expand All @@ -42,7 +75,27 @@ const RejectOrderDialog: React.FC<RejectOrderDialogProps> = ({
/>
<ModalBody>
<div className={styles.modalBody}>
<section className={styles.section}></section>
<section className={styles.section}>
<h5 className={styles.section}>
{order?.accessionNumber} &nbsp; · &nbsp;{order?.fulfillerStatus}{" "}
&nbsp; · &nbsp;
{order?.orderNumber}
&nbsp;
</h5>
</section>
<br />
<section className={styles.section}>
<TextArea
labelText={t("notes", "Enter instructions ")}
id="nextNotes"
name="nextNotes"
invalidText="Required"
helperText="Please enter notes"
maxCount={500}
enableCounter
onChange={(e) => setNotes(e.target.value)}
/>
</section>
</div>
</ModalBody>
<ModalFooter>
Expand Down
14 changes: 14 additions & 0 deletions src/reject-order/reject-order-dialog.resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FetchResponse, openmrsFetch, useConfig } from "@openmrs/esm-framework";

export async function RejectOrder(uuid: string, body: any) {
const abortController = new AbortController();

return openmrsFetch(`/ws/rest/v1/order/${uuid}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
signal: abortController.signal,
body: body,
});
}
4 changes: 2 additions & 2 deletions src/work-list/work-list.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface ResultsOrderProps {
}

interface RejectOrderProps {
order: string;
order: Result;
}

const WorkList: React.FC<WorklistProps> = ({ fulfillerStatus }) => {
Expand Down Expand Up @@ -174,7 +174,7 @@ const WorkList: React.FC<WorklistProps> = ({ fulfillerStatus }) => {
patientUuid={entry.patient.uuid}
order={paginatedWorkListEntries[index]}
/>
<RejectOrder order={paginatedWorkListEntries[index].uuid} />
<RejectOrder order={paginatedWorkListEntries[index]} />
</>
),
},
Expand Down

0 comments on commit 22c87b0

Please sign in to comment.