Skip to content

Commit

Permalink
Add Authored On field (#10094)
Browse files Browse the repository at this point in the history
  • Loading branch information
amjithtitus09 authored Jan 22, 2025
1 parent 9f2d856 commit a894ce6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@
"audit_log": "Audit Log",
"auth_login_title": "Authorized Login",
"auth_method_unsupported": "This authentication method is not supported, please try a different method",
"authored_on": "Authored On",
"authorize_shift_delete": "Authorize shift delete",
"auto_generated_for_care": "Auto Generated for Care",
"autofilled_fields": "Autofilled Fields",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import { DateTimePicker } from "@/components/ui/date-time-picker";
import { Dialog, DialogContent } from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
Expand Down Expand Up @@ -84,6 +85,7 @@ export function MedicationRequestQuestion({
...medications,
{
...parseMedicationStringToRequest(medication),
authored_on: new Date().toISOString(),
},
];
updateQuestionnaireResponseCB({
Expand Down Expand Up @@ -166,12 +168,12 @@ export function MedicationRequestQuestion({
<div className="md:overflow-x-auto w-auto pb-2">
<div className="min-w-fit">
<div
className={cn("max-w-[2144px] relative lg:border rounded-md", {
className={cn("max-w-[2304px] relative lg:border rounded-md", {
"bg-gray-50/50": !desktopLayout,
})}
>
{/* Header - Only show on desktop */}
<div className="hidden lg:grid grid-cols-[280px,180px,170px,160px,300px,180px,250px,180px,160px,200px,48px] bg-gray-50 border-b text-sm font-medium text-gray-500">
<div className="hidden lg:grid grid-cols-[280px,180px,170px,160px,300px,180px,250px,180px,160px,200px,180px,48px] bg-gray-50 border-b text-sm font-medium text-gray-500">
<div className="font-semibold text-gray-600 p-3 border-r">
{t("medicine")}
</div>
Expand Down Expand Up @@ -199,6 +201,9 @@ export function MedicationRequestQuestion({
<div className="font-semibold text-gray-600 p-3 border-r">
{t("intent")}
</div>
<div className="font-semibold text-gray-600 p-3 border-r">
{t("authored_on")}
</div>
<div className="font-semibold text-gray-600 p-3 border-r">
{t("notes")}
</div>
Expand Down Expand Up @@ -438,7 +443,7 @@ const MedicationRequestGridRow: React.FC<MedicationRequestGridRowProps> = ({
};

return (
<div className="grid grid-cols-1 lg:grid-cols-[280px,180px,170px,160px,300px,180px,250px,180px,160px,200px,48px] border-b hover:bg-gray-50/50">
<div className="grid grid-cols-1 lg:grid-cols-[280px,180px,170px,160px,300px,180px,250px,180px,160px,200px,180px,48px] border-b hover:bg-gray-50/50">
{/* Medicine Name */}
<div className="lg:p-4 lg:px-2 lg:py-1 flex items-center justify-between lg:justify-start lg:col-span-1 lg:border-r font-medium overflow-hidden text-sm">
<span className="break-words line-clamp-2 hidden lg:block">
Expand Down Expand Up @@ -742,6 +747,24 @@ const MedicationRequestGridRow: React.FC<MedicationRequestGridRowProps> = ({
</SelectContent>
</Select>
</div>
{/* Authored On */}
<div className="lg:px-1 lg:py-1 lg:border-r overflow-hidden">
<Label className="mb-1.5 block text-sm lg:hidden">
{t("authored_on")}
</Label>
<DateTimePicker
value={
medication.authored_on
? new Date(medication.authored_on)
: undefined
}
onChange={(date) => {
if (!date) return;
onUpdate?.({ authored_on: date.toISOString() });
}}
disabled={disabled}
/>
</div>
{/* Notes */}
<div className="lg:px-2 lg:py-1 lg:border-r overflow-hidden">
<Label className="mb-1.5 block text-sm lg:hidden">{t("notes")}</Label>
Expand Down Expand Up @@ -775,6 +798,7 @@ const MedicationRequestGridRow: React.FC<MedicationRequestGridRowProps> = ({
/>
)}
</div>

{/* Remove Button */}
<div className="hidden lg:flex lg:px-2 lg:py-1 items-center justify-center sticky right-0 bg-white shadow-[-12px_0_15px_-4px_rgba(0,0,0,0.15)] w-12">
<Button
Expand Down
33 changes: 18 additions & 15 deletions src/components/ui/date-time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,27 @@ export function DateTimePicker({

const handleTimeChange = (
type: "hour" | "minute" | "ampm",
value: string,
selectedValue: string,
) => {
if (value) {
const newDate = new Date(value);
if (type === "hour") {
newDate.setHours(
(parseInt(value) % 12) + (newDate.getHours() >= 12 ? 12 : 0),
);
} else if (type === "minute") {
newDate.setMinutes(parseInt(value));
} else if (type === "ampm") {
const currentHours = newDate.getHours();
newDate.setHours(
value === "PM" ? currentHours + 12 : currentHours - 12,
);
if (!value) return;
const newDate = new Date(value);

if (type === "hour") {
newDate.setHours(
(parseInt(selectedValue) % 12) + (newDate.getHours() >= 12 ? 12 : 0),
);
} else if (type === "minute") {
newDate.setMinutes(parseInt(selectedValue));
} else if (type === "ampm") {
const currentHours = newDate.getHours();
const isPM = selectedValue === "PM";
if (isPM && currentHours < 12) {
newDate.setHours(currentHours + 12);
} else if (!isPM && currentHours >= 12) {
newDate.setHours(currentHours - 12);
}
onChange?.(newDate);
}
onChange?.(newDate);
};

return (
Expand Down
3 changes: 3 additions & 0 deletions src/types/emr/medicationRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export interface MedicationRequest {
encounter?: string; // UUID
dosage_instruction: MedicationRequestDosageInstruction[];
note?: string;
authored_on: string;
}

export interface MedicationRequestRead {
Expand All @@ -179,6 +180,7 @@ export interface MedicationRequestRead {
modified_date: string;
created_by: UserBareMinimum;
updated_by: UserBareMinimum;
authored_on: string;
}

export const MEDICATION_REQUEST_TIMING_OPTIONS: Record<
Expand Down Expand Up @@ -519,6 +521,7 @@ export function parseMedicationStringToRequest(
intent: "order",
category: "inpatient",
priority: "routine",
authored_on: new Date().toISOString(),
};

return medicationRequest;
Expand Down

0 comments on commit a894ce6

Please sign in to comment.