Skip to content

Commit

Permalink
Merge pull request ohcnetwork#7675 from coronasafe/issues/7672/titrat…
Browse files Browse the repository at this point in the history
…ed-prescription-patches2

Disable Discontinue, Administer, Archive Administration & Edit prescription for discharged patients; disallow titrated prescriptions for discharge prescriptions; and more...
  • Loading branch information
khavinshankar authored Apr 21, 2024
2 parents 1b565fe + dfede2c commit 83f64d6
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 140 deletions.
41 changes: 21 additions & 20 deletions src/Components/Medicine/CreatePrescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,27 @@ export default function CreatePrescriptionForm(props: {
{...field("medicine_object", RequiredFieldValidator())}
required
/>
{props.prescription.dosage_type !== "PRN" && (
<CheckBoxFormField
label={t("titrate_dosage")}
name="Titrate Dosage"
value={field("dosage_type").value === "TITRATED"}
onChange={(e) => {
if (e.value) {
field("dosage_type").onChange({
name: "dosage_type",
value: "TITRATED",
});
} else {
field("dosage_type").onChange({
name: "dosage_type",
value: "REGULAR",
});
}
}}
/>
)}
{props.prescription.dosage_type !== "PRN" &&
props.prescription.prescription_type !== "DISCHARGE" && (
<CheckBoxFormField
label={t("titrate_dosage")}
name="Titrate Dosage"
value={field("dosage_type").value === "TITRATED"}
onChange={(e) => {
if (e.value) {
field("dosage_type").onChange({
name: "dosage_type",
value: "TITRATED",
});
} else {
field("dosage_type").onChange({
name: "dosage_type",
value: "REGULAR",
});
}
}}
/>
)}
<div className="flex flex-wrap items-center gap-x-4">
<SelectFormField
className="flex-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ interface Props {
interval: { start: Date; end: Date };
prescription: Prescription;
refetch: () => void;
readonly?: boolean;
}

export default function AdministrationEventCell({
administrations,
interval: { start, end },
prescription,
refetch,
readonly,
}: Props) {
const [showTimeline, setShowTimeline] = useState(false);
// Check if cell belongs to an administered prescription (including start and excluding end)
Expand Down Expand Up @@ -56,6 +58,7 @@ export default function AdministrationEventCell({
prescription={prescription}
showPrescriptionDetails
onRefetch={refetch}
readonly={readonly}
/>
</DialogModal>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ interface Props {
prescriptions: Prescription[];
pagination: ReturnType<typeof useRangePagination>;
onRefetch: () => void;
readonly: boolean;
}

export default function MedicineAdministrationTable({
readonly,
pagination,
prescriptions,
onRefetch,
Expand Down Expand Up @@ -101,6 +103,7 @@ export default function MedicineAdministrationTable({
prescription={obj}
intervals={pagination.slots!}
refetch={onRefetch}
readonly={readonly}
/>
))}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface Props {
prescription: Prescription;
intervals: { start: Date; end: Date }[];
refetch: () => void;
readonly: boolean;
}

export default function MedicineAdministrationTableRow({
Expand Down Expand Up @@ -54,12 +55,7 @@ export default function MedicineAdministrationTableRow({
);

return (
<tr
className={classNames(
"group transition-all duration-200 ease-in-out",
loading ? "bg-gray-300" : "bg-white hover:bg-primary-100",
)}
>
<>
{showDiscontinue && (
<DiscontinuePrescription
prescription={prescription}
Expand Down Expand Up @@ -96,42 +92,46 @@ export default function MedicineAdministrationTableRow({
onClick={() => setShowDetails(false)}
label={t("close")}
/>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
variant="danger"
onClick={() => setShowDiscontinue(true)}
>
<CareIcon icon="l-ban" className="text-lg" />
{t("discontinue")}
</Submit>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
variant="secondary"
border
onClick={() => {
setShowDetails(false);
setShowEdit(true);
}}
>
<CareIcon icon="l-pen" className="text-lg" />
{t("edit")}
</Submit>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
onClick={() => setShowAdminister(true)}
>
<CareIcon icon="l-syringe" className="text-lg" />
{t("administer")}
</Submit>
{!props.readonly && (
<>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
variant="danger"
onClick={() => setShowDiscontinue(true)}
>
<CareIcon icon="l-ban" className="text-lg" />
{t("discontinue")}
</Submit>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
variant="secondary"
border
onClick={() => {
setShowDetails(false);
setShowEdit(true);
}}
>
<CareIcon icon="l-pen" className="text-lg" />
{t("edit")}
</Submit>
<Submit
disabled={
prescription.discontinued ||
prescription.prescription_type === "DISCHARGE"
}
onClick={() => setShowAdminister(true)}
>
<CareIcon icon="l-syringe" className="text-lg" />
{t("administer")}
</Submit>
</>
)}
</div>
</div>
</DialogModal>
Expand Down Expand Up @@ -166,93 +166,104 @@ export default function MedicineAdministrationTableRow({
/>
</DialogModal>
)}
<td
className="bg-gray-white sticky left-0 z-10 cursor-pointer bg-white py-3 pl-4 text-left transition-all duration-200 ease-in-out group-hover:bg-primary-100"
onClick={() => setShowDetails(true)}
<tr
className={classNames(
"group transition-all duration-200 ease-in-out",
loading ? "bg-gray-300" : "bg-white hover:bg-primary-100",
)}
>
<div className="flex flex-col gap-1 lg:flex-row lg:justify-between lg:gap-2">
<div className="flex items-center gap-2">
<span
className={classNames(
"text-sm font-semibold",
prescription.discontinued ? "text-gray-700" : "text-gray-900",
<td
className="bg-gray-white sticky left-0 z-10 cursor-pointer bg-white py-3 pl-4 text-left transition-all duration-200 ease-in-out group-hover:bg-primary-100"
onClick={() => setShowDetails(true)}
>
<div className="flex flex-col gap-1 lg:flex-row lg:justify-between lg:gap-2">
<div className="flex items-center gap-2">
<span
className={classNames(
"text-sm font-semibold",
prescription.discontinued ? "text-gray-700" : "text-gray-900",
)}
>
{prescription.medicine_object?.name ??
prescription.medicine_old}
</span>

{prescription.discontinued && (
<span className="hidden rounded-full border border-gray-500 bg-gray-200 px-1.5 text-xs font-medium text-gray-700 lg:block">
{t("discontinued")}
</span>
)}
>
{prescription.medicine_object?.name ?? prescription.medicine_old}
</span>

{prescription.discontinued && (
<span className="hidden rounded-full border border-gray-500 bg-gray-200 px-1.5 text-xs font-medium text-gray-700 lg:block">
{t("discontinued")}
</span>
)}
{prescription.route && (
<span className="hidden rounded-full border border-blue-500 bg-blue-100 px-1.5 text-xs font-medium text-blue-700 lg:block">
{t(prescription.route)}
</span>
)}
</div>

{prescription.route && (
<span className="hidden rounded-full border border-blue-500 bg-blue-100 px-1.5 text-xs font-medium text-blue-700 lg:block">
{t(prescription.route)}
</span>
)}
</div>
<div className="flex gap-1 text-xs font-semibold text-gray-900 lg:flex-col lg:px-2 lg:text-center">
{prescription.dosage_type !== "TITRATED" ? (
<p>{prescription.base_dosage}</p>
) : (
<p>
{prescription.base_dosage} - {prescription.target_dosage}
</p>
)}

<div className="flex gap-1 text-xs font-semibold text-gray-900 lg:flex-col lg:px-2 lg:text-center">
{prescription.dosage_type !== "TITRATED" ? (
<p>{prescription.base_dosage}</p>
) : (
<p>
{prescription.base_dosage} - {prescription.target_dosage}
{prescription.dosage_type !== "PRN"
? t("PRESCRIPTION_FREQUENCY_" + prescription.frequency)
: prescription.indicator}
</p>
)}

<p>
{prescription.dosage_type !== "PRN"
? t("PRESCRIPTION_FREQUENCY_" + prescription.frequency)
: prescription.indicator}
</p>
</div>
</div>
</div>
</td>
</td>

<td />
<td />

{/* Administration Cells */}
{props.intervals.map(({ start, end }, index) => (
<>
<td key={`event-seperator-${index}`}>
<AdministrationEventSeperator date={start} />
</td>
{/* Administration Cells */}
{props.intervals.map(({ start, end }, index) => (
<>
<td key={`event-seperator-${index}`}>
<AdministrationEventSeperator date={start} />
</td>

<td key={`event-socket-${index}`} className="text-center">
{!data?.results ? (
<CareIcon
icon="l-spinner"
className="animate-spin text-lg text-gray-500"
/>
) : (
<AdministrationEventCell
administrations={data.results}
interval={{ start, end }}
prescription={prescription}
refetch={refetch}
/>
)}
</td>
</>
))}
<td />
<td key={`event-socket-${index}`} className="text-center">
{!data?.results ? (
<CareIcon
icon="l-spinner"
className="animate-spin text-lg text-gray-500"
/>
) : (
<AdministrationEventCell
administrations={data.results}
interval={{ start, end }}
prescription={prescription}
refetch={refetch}
readonly={props.readonly}
/>
)}
</td>
</>
))}
<td />

{/* Action Buttons */}
<td className="space-x-1 pr-2 text-right">
<ButtonV2
type="button"
size="small"
disabled={prescription.discontinued}
ghost
border
onClick={() => setShowAdminister(true)}
>
{t("administer")}
</ButtonV2>
</td>
</tr>
{/* Action Buttons */}
<td className="space-x-1 pr-2 text-right">
{!props.readonly && (
<ButtonV2
type="button"
size="small"
disabled={prescription.discontinued}
ghost
border
onClick={() => setShowAdminister(true)}
>
{t("administer")}
</ButtonV2>
)}
</td>
</tr>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => {
refetch();
discontinuedPrescriptions.refetch();
}}
readonly={readonly || false}
/>
)}
</>
Expand Down
Loading

0 comments on commit 83f64d6

Please sign in to comment.