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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,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 @@ -646,15 +645,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,
});

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