-
Notifications
You must be signed in to change notification settings - Fork 532
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
Changes from 2 commits
bf83af8
d396a76
b70cd3a
23af6b1
bdc50ab
486a660
5b3fa6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 - {prescription.dosage_instruction[0].route && (
+ {prescription.dosage_instruction?.length &&
+ prescription.dosage_instruction[0].route && (
<span> ... </span> 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
</span> | ||||||||||||||||||
)} | ||||||||||||||||||
</div> | ||||||||||||||||||
|
@@ -217,7 +217,7 @@ type DosageFrequencyInfoProps = { | |||||||||||||||||
export function DosageFrequencyInfo({ | ||||||||||||||||||
prescription, | ||||||||||||||||||
}: DosageFrequencyInfoProps) { | ||||||||||||||||||
const dosageInstruction = prescription.dosage_instruction; | ||||||||||||||||||
const dosageInstruction = prescription.dosage_instruction[0]; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add null-check for dosage_instruction array In - const dosageInstruction = prescription.dosage_instruction[0];
+ const dosageInstruction = prescription.dosage_instruction?.[0];
+ if (!dosageInstruction) {
+ return null; // or a placeholder
+ }
|
||||||||||||||||||
|
||||||||||||||||||
return ( | ||||||||||||||||||
<div className="flex justify-center"> | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ export default function PrescriptionDetailCard({ | |
{prescription.category === "discharge" && | ||
`${t("discharge")} `} | ||
{t( | ||
prescription.dosage_instruction.as_needed_boolean | ||
prescription.dosage_instruction[0].as_needed_boolean | ||
? "prn_prescription" | ||
: "prescription", | ||
)} | ||
|
@@ -146,30 +146,31 @@ export default function PrescriptionDetailCard({ | |
</div> | ||
</Detail> | ||
|
||
{prescription.dosage_instruction.dose_and_rate?.dose_range && ( | ||
{prescription.dosage_instruction[0].dose_and_rate?.dose_range && ( | ||
<> | ||
<Detail className="col-span-5" label={t("start_dosage")}> | ||
{displayQuantity( | ||
prescription.dosage_instruction.dose_and_rate?.dose_range | ||
prescription.dosage_instruction[0].dose_and_rate?.dose_range | ||
?.low as Quantity, | ||
)} | ||
</Detail> | ||
<Detail className="col-span-5" label={t("target_dosage")}> | ||
{displayQuantity( | ||
prescription.dosage_instruction.dose_and_rate?.dose_range | ||
prescription.dosage_instruction[0].dose_and_rate?.dose_range | ||
?.high as Quantity, | ||
)} | ||
</Detail> | ||
</> | ||
)} | ||
|
||
{prescription.dosage_instruction.dose_and_rate?.dose_quantity && ( | ||
{prescription.dosage_instruction[0].dose_and_rate | ||
?.dose_quantity && ( | ||
<Detail | ||
className="col-span-10 sm:col-span-6 md:col-span-4" | ||
label={t("dosage")} | ||
> | ||
{displayQuantity( | ||
prescription.dosage_instruction.dose_and_rate | ||
prescription.dosage_instruction[0].dose_and_rate | ||
?.dose_quantity as Quantity, | ||
)} | ||
</Detail> | ||
|
@@ -179,19 +180,19 @@ export default function PrescriptionDetailCard({ | |
className="col-span-10 break-all sm:col-span-6" | ||
label={t("route")} | ||
> | ||
{displayCode(prescription.dosage_instruction.route)} | ||
{displayCode(prescription.dosage_instruction[0].route)} | ||
</Detail> | ||
|
||
{prescription.dosage_instruction.as_needed_boolean ? ( | ||
{prescription.dosage_instruction[0].as_needed_boolean ? ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate PRN fields together Also applies to: 191-191 |
||
<Detail | ||
className="col-span-10 md:col-span-4" | ||
label={t("indicator")} | ||
> | ||
{displayCode(prescription.dosage_instruction.as_needed_for)} | ||
{displayCode(prescription.dosage_instruction[0].as_needed_for)} | ||
</Detail> | ||
) : ( | ||
<Detail className="col-span-5" label={t("frequency")}> | ||
{displayTiming(prescription.dosage_instruction.timing)} | ||
{displayTiming(prescription.dosage_instruction[0].timing)} | ||
</Detail> | ||
)} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,19 +91,19 @@ export default function PrescriptionsTable({ | |
...obj, | ||
medicine: displayCode(obj.medication), | ||
route__pretty: | ||
obj.dosage_instruction.route && | ||
displayCode(obj.dosage_instruction.route), | ||
obj.dosage_instruction[0].route && | ||
displayCode(obj.dosage_instruction[0].route), | ||
frequency__pretty: | ||
obj.dosage_instruction.timing && | ||
displayTiming(obj.dosage_instruction.timing), | ||
obj.dosage_instruction[0].timing && | ||
displayTiming(obj.dosage_instruction[0].timing), | ||
max_dose_per_period__pretty: | ||
obj.dosage_instruction.max_dose_per_period && | ||
obj.dosage_instruction[0].max_dose_per_period && | ||
displayDoseRange( | ||
obj.dosage_instruction.max_dose_per_period, | ||
obj.dosage_instruction[0].max_dose_per_period, | ||
), | ||
indicator: | ||
obj.dosage_instruction.as_needed_for && | ||
displayCode(obj.dosage_instruction.as_needed_for), | ||
obj.dosage_instruction[0].as_needed_for && | ||
displayCode(obj.dosage_instruction[0].as_needed_for), | ||
Comment on lines
+94
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Guard against empty dosage_instruction arrays All these references to - route__pretty:
- obj.dosage_instruction[0].route &&
- displayCode(obj.dosage_instruction[0].route),
+ route__pretty:
+ obj.dosage_instruction?.length &&
+ obj.dosage_instruction[0].route &&
+ displayCode(obj.dosage_instruction[0].route), Apply a similar pattern for the other properties (
|
||
})) || [] | ||
} | ||
objectKeys={Object.values(tkeys)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Check for potential index error when accessing the first dosage instruction
Referencing
dosage_instruction[0]
could lead to runtime errors if the array is empty. A simple guard check is recommended: