Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medication Request | Convert dosage instruction to array #9665

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Routers/routes/ConsultationRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import PatientConsentRecords from "@/components/Patient/PatientConsentRecords";

import { AppRoutes } from "@/Routers/AppRouter";
import { EncounterShow } from "@/pages/Encounters/EncounterShow";
import { PrintPrescription } from "@/pages/Encounters/PrintPrescription";

const consultationRoutes: AppRoutes = {
"/facility/:facilityId/encounter/:encounterId/prescriptions/print": ({
facilityId,
encounterId,
}) => <PrintPrescription facilityId={facilityId} encounterId={encounterId} />,
"/facility/:facilityId/encounter/:encounterId/:tab": ({
facilityId,
encounterId,
Expand Down
10 changes: 5 additions & 5 deletions src/components/Medicine/AdministerMedicine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function AdministerMedicine({ prescription, onClose }: Props) {
const encounterId = useSlug("encounter");
const { patient } = useEncounter();

const doseAndRate = prescription.dosage_instruction.dose_and_rate!;
const doseAndRate = prescription.dosage_instruction[0].dose_and_rate!;
const requiresDosage = doseAndRate.type === "calculated";

const formSchema = z
Expand Down Expand Up @@ -154,10 +154,10 @@ export default function AdministerMedicine({ prescription, onClose }: Props) {
occurrence_period_end: time.toISOString(),
note: values.note,
dosage: {
text: prescription.dosage_instruction.text,
site: prescription.dosage_instruction.site,
route: prescription.dosage_instruction.route,
method: prescription.dosage_instruction.method,
text: prescription.dosage_instruction[0].text,
site: prescription.dosage_instruction[0].site,
route: prescription.dosage_instruction[0].route,
method: prescription.dosage_instruction[0].method,
dose: {
value: doseValue!,
unit: doseUnit!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function MedicineAdministrationTable({
<span className="hidden px-2 text-center text-xs leading-none lg:block">
<p>{t("dosage")} &</p>
<p>
{!prescriptions[0]?.dosage_instruction.as_needed_boolean
{!prescriptions[0]?.dosage_instruction[0]?.as_needed_boolean
? t("frequency")
: t("indicator")}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ export default function MedicineAdministrationTableRow({
</span>
)}

{prescription.dosage_instruction.route && (
{prescription.dosage_instruction[0].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">
{displayCode(prescription.dosage_instruction.route)}
{displayCode(prescription.dosage_instruction[0].route)}
Comment on lines +148 to +150
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Safely access prescription.dosage_instruction[0].route

As with other components, ensure that the dosage_instruction array is not empty before accessing [0].

- {prescription.dosage_instruction[0].route && (
+ {prescription.dosage_instruction?.length &&
+  prescription.dosage_instruction[0].route && (
     <span> ... </span>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{prescription.dosage_instruction[0].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">
{displayCode(prescription.dosage_instruction.route)}
{displayCode(prescription.dosage_instruction[0].route)}
{prescription.dosage_instruction?.length &&
prescription.dosage_instruction[0].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">
{displayCode(prescription.dosage_instruction[0].route)}

</span>
)}
</div>
Expand Down Expand Up @@ -217,7 +217,7 @@ type DosageFrequencyInfoProps = {
export function DosageFrequencyInfo({
prescription,
}: DosageFrequencyInfoProps) {
const dosageInstruction = prescription.dosage_instruction;
const dosageInstruction = prescription.dosage_instruction[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add null-check for dosage_instruction array

In DosageFrequencyInfo, referencing prescription.dosage_instruction[0] directly can cause errors if the array is empty. Consider a guard to avoid potential runtime issues.

- const dosageInstruction = prescription.dosage_instruction[0];
+ const dosageInstruction = prescription.dosage_instruction?.[0];
+ if (!dosageInstruction) {
+   return null; // or a placeholder
+ }

Committable suggestion skipped: line range outside the PR's diff.


return (
<div className="flex justify-center">
Expand Down
Loading
Loading