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

Prefill Structured Data; Add Edit Links for Structured #9992

Merged
merged 36 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4e7325b
Prefill MedicationRequest; Add Edit Links for Structured
gigincg Jan 15, 2025
06fab59
Merge branch 'develop' into structured_prefills
gigincg Jan 15, 2025
fcb58c7
Fix types
gigincg Jan 15, 2025
4caed51
Remove EncounterContext; Add MedicationStatement prefill
gigincg Jan 15, 2025
3de35dd
Add Remove as entered-in-error
gigincg Jan 17, 2025
82c70b5
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 17, 2025
bd4ba61
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 20, 2025
4196a75
Symptom & DIagnosis
amjithtitus09 Jan 20, 2025
3356df6
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 20, 2025
ccb44f9
Fixed status option to match BE
amjithtitus09 Jan 20, 2025
93e2a0f
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 20, 2025
372b02c
Lint fix
amjithtitus09 Jan 20, 2025
c26ad27
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 20, 2025
b0be793
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 21, 2025
44bde9a
Fix cache issue after updating
amjithtitus09 Jan 21, 2025
7a51103
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 22, 2025
a3d2371
Rebuild questionnaireForm updateHandler to receive values instead of …
amjithtitus09 Jan 23, 2025
f22a067
Disable row when existing items are removed, date picker format, temp…
amjithtitus09 Jan 23, 2025
e59b0cd
Entered in error UI changes
amjithtitus09 Jan 24, 2025
747194e
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 24, 2025
ac45de1
Merge branch 'structured_prefills' of https://github.com/ohcnetwork/c…
amjithtitus09 Jan 24, 2025
5c2c484
MedicationStatement | Add missing encounter field
amjithtitus09 Jan 24, 2025
9f130a7
Removed console log
amjithtitus09 Jan 24, 2025
5d735e2
Update only selected fields
amjithtitus09 Jan 24, 2025
c54657f
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 24, 2025
fd5b993
Merge branch 'structured_prefills' of https://github.com/ohcnetwork/c…
amjithtitus09 Jan 24, 2025
7f821ce
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 25, 2025
7ceecf9
Merge branch 'structured_prefills' of https://github.com/ohcnetwork/c…
amjithtitus09 Jan 25, 2025
c43d4de
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 25, 2025
747b325
Merge branch 'structured_prefills' of https://github.com/ohcnetwork/c…
amjithtitus09 Jan 25, 2025
72e81ce
Fixed padding for allergy, symptom, diagnosis tables
amjithtitus09 Jan 25, 2025
cbfa87a
Merge pull request #10115 from ohcnetwork/questionnaire-update-rebuild
amjithtitus09 Jan 25, 2025
ba2a421
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 25, 2025
3403225
Invalidate queries
amjithtitus09 Jan 27, 2025
52c0c2f
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Jan 27, 2025
20ef2af
Remove Commented Code
gigincg Jan 27, 2025
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
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,7 @@
"next_week_short": "Next wk",
"no": "No",
"no_address_provided": "No address provided",
"no_allergies_recorded": "No allergies recorded",
"no_appointments": "No appointments found",
"no_attachments_found": "This communication has no attachments.",
"no_availabilities_yet": "No availabilities yet",
Expand Down
10 changes: 0 additions & 10 deletions src/Utils/request/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
AppointmentPatientRegister,
} from "@/pages/Patient/Utils";
import { Encounter, EncounterEditRequest } from "@/types/emr/encounter";
import { MedicationRequestRead } from "@/types/emr/medicationRequest";
import { MedicationStatement } from "@/types/emr/medicationStatement";
import { PartialPatientModel, Patient } from "@/types/emr/newPatient";
import {
Expand Down Expand Up @@ -645,15 +644,6 @@ const routes = {
},
},

// Medication
medicationRequest: {
list: {
path: "/api/v1/patient/{patientId}/medication/request/",
method: "GET",
TRes: Type<PaginatedResponse<MedicationRequestRead>>(),
},
},

medicationStatement: {
list: {
path: "/api/v1/patient/{patientId}/medication/statement/",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { t } from "i18next";
import { PencilIcon } from "lucide-react";
import { Link } from "raviger";
import { useState } from "react";

Expand All @@ -11,18 +13,17 @@ import { ScrollArea } from "@/components/ui/scroll-area";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";

import Loading from "@/components/Common/Loading";
import { useEncounter } from "@/components/Facility/ConsultationDetails/EncounterContext";

import useSlug from "@/hooks/useSlug";

import routes from "@/Utils/request/api";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import query from "@/Utils/request/query";
import { classNames } from "@/Utils/utils";
import { MedicationRequest } from "@/types/emr/medicationRequest";
import medicationRequestApi from "@/types/emr/medicationRequest/medicationRequestApi";

interface Props {
readonly?: boolean;
facilityId: string;
patientId: string;
encounterId: string;
}

const FREQUENCY_DISPLAY: Record<string, { code: string; meaning: string }> = {
Expand All @@ -45,21 +46,21 @@ function getFrequencyDisplay(
return FREQUENCY_DISPLAY[key];
}

const MedicineAdministrationSheet = ({ facilityId }: Props) => {
const encounterId = useSlug("encounter");
const { patient } = useEncounter();
export default function MedicationRequestTable({
facilityId,
patientId,
encounterId,
}: Props) {
const [searchQuery, setSearchQuery] = useState("");

const { data: medications, loading } = useTanStackQueryInstead(
routes.medicationRequest.list,
{
pathParams: { patientId: patient!.id },
query: {
encounter: encounterId,
limit: 100,
},
},
);
const { data: medications, isLoading: loading } = useQuery({
queryKey: ["medications", patientId],
queryFn: query(medicationRequestApi.list, {
pathParams: { patientId: patientId },
queryParams: { encounter: encounterId },
}),
enabled: !!patientId,
});
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 error handling for the API call.

The query setup looks good, but it's missing error handling for failed API calls and loading state management.

-const { data: medications, isLoading: loading } = useQuery({
+const { data: medications, isLoading: loading, error } = useQuery({
   queryKey: ["medications", patientId],
   queryFn: query(medicationRequestApi.list, {
     pathParams: { patientId: patientId },
     queryParams: { encounter: encounterId },
   }),
   enabled: !!patientId,
+  onError: (error) => {
+    toast.error(t("error_fetching_medications"));
+  },
 });

+if (error) {
+  return (
+    <div className="p-4 text-destructive">
+      {t("error_fetching_medications")}
+    </div>
+  );
+}

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


const filteredMedications = medications?.results?.filter(
(med: MedicationRequest) => {
Expand Down Expand Up @@ -103,6 +104,14 @@ const MedicineAdministrationSheet = ({ facilityId }: Props) => {
title="Prescriptions"
options={
<div className="flex items-center gap-2">
<Button asChild variant="outline" size="sm">
<Link
href={`/facility/${facilityId}/patient/${patientId}/encounter/${encounterId}/questionnaire/medication_request`}
>
<PencilIcon />
Edit
</Link>
</Button>
<Button asChild variant="outline" size="sm">
<Link
href={`/facility/${facilityId}/encounter/${encounterId}/prescriptions/print`}
Expand Down Expand Up @@ -185,7 +194,7 @@ const MedicineAdministrationSheet = ({ facilityId }: Props) => {
</div>
</div>
);
};
}

const PrescriptionEntry = ({
medication,
Expand Down Expand Up @@ -349,5 +358,3 @@ const PrescriptionEntry = ({
</div>
);
};

export default MedicineAdministrationSheet;
112 changes: 79 additions & 33 deletions src/components/Patient/allergy/list.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useQuery } from "@tanstack/react-query";
import { t } from "i18next";
import { PencilIcon } from "lucide-react";
import { Link } from "raviger";
import { ReactNode } from "react";

import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
Expand All @@ -20,11 +23,16 @@ import { AllergyIntolerance } from "@/types/emr/allergyIntolerance/allergyIntole
import allergyIntoleranceApi from "@/types/emr/allergyIntolerance/allergyIntoleranceApi";

interface AllergyListProps {
facilityId?: string;
patientId: string;
encounterId?: string;
}

export function AllergyList({ patientId, encounterId }: AllergyListProps) {
export function AllergyList({
facilityId,
patientId,
encounterId,
}: AllergyListProps) {
const { data: allergies, isLoading } = useQuery({
queryKey: ["allergies", patientId, encounterId],
queryFn: query(allergyIntoleranceApi.getAllergy, {
Expand All @@ -35,27 +43,29 @@ export function AllergyList({ patientId, encounterId }: AllergyListProps) {

if (isLoading) {
return (
<Card>
<CardHeader>
<CardTitle>Allergies</CardTitle>
</CardHeader>
<AllergyListLayout
facilityId={facilityId}
patientId={patientId}
encounterId={encounterId}
>
<CardContent>
<Skeleton className="h-[100px] w-full" />
</CardContent>
</Card>
</AllergyListLayout>
);
}

if (!allergies?.results?.length) {
return (
<Card>
<CardHeader>
<CardTitle>Allergies</CardTitle>
</CardHeader>
<AllergyListLayout
facilityId={facilityId}
patientId={patientId}
encounterId={encounterId}
>
<CardContent>
<p className="text-muted-foreground">No allergies recorded</p>
<p className="text-muted-foreground">{t("no_allergies_recorded")}</p>
</CardContent>
</Card>
</AllergyListLayout>
);
}

Expand Down Expand Up @@ -84,23 +94,30 @@ export function AllergyList({ patientId, encounterId }: AllergyListProps) {
};

return (
<Card className="p-0">
<CardHeader className="px-4 py-0 pt-4">
<CardTitle>{t("allergies")}</CardTitle>
</CardHeader>
<CardContent className="p-2">
<Table>
<TableHeader>
<TableRow>
<TableHead>{t("allergen")}</TableHead>
<TableHead>{t("category")}</TableHead>
<TableHead>{t("status")}</TableHead>
<TableHead>{t("criticality")}</TableHead>
<TableHead>{t("created_by")}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{allergies.results.map((allergy: AllergyIntolerance) => (
<AllergyListLayout
facilityId={facilityId}
patientId={patientId}
encounterId={encounterId}
>
<Table>
<TableHeader>
<TableRow>
<TableHead>{t("allergen")}</TableHead>
<TableHead>{t("category")}</TableHead>
<TableHead>{t("status")}</TableHead>
<TableHead>{t("criticality")}</TableHead>
<TableHead>{t("created_by")}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{allergies.results
.sort((a, _b) => {
if (a.clinical_status === "inactive") {
return 1;
}
return -1;
})
.map((allergy: AllergyIntolerance) => (
<TableRow key={allergy.id}>
<TableCell className="font-medium">
{allergy.code.display}
Expand Down Expand Up @@ -140,9 +157,38 @@ export function AllergyList({ patientId, encounterId }: AllergyListProps) {
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</CardContent>
</Card>
</TableBody>
</Table>
</AllergyListLayout>
);
}

const AllergyListLayout = ({
facilityId,
patientId,
encounterId,
children,
}: {
facilityId?: string;
patientId: string;
encounterId?: string;
children: ReactNode;
}) => {
return (
<Card>
<CardHeader className="px-4 py-0 pt-4 flex justify-between flex-row">
<CardTitle>{t("allergies")}</CardTitle>
{facilityId && encounterId && (
<Link
href={`/facility/${facilityId}/patient/${patientId}/encounter/${encounterId}/questionnaire/allergy_intolerance`}
className="flex items-center gap-1 text-sm hover:text-gray-500"
>
<PencilIcon size={12} />
{t("edit")}
</Link>
)}
</CardHeader>
{children}
</Card>
);
};
Loading
Loading