Skip to content

Commit

Permalink
Allergy intolerance Cleanup (#9812)
Browse files Browse the repository at this point in the history
  • Loading branch information
amjithtitus09 authored Jan 7, 2025
1 parent 97cf466 commit bd8ac7e
Show file tree
Hide file tree
Showing 13 changed files with 397 additions and 239 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";

import CareIcon from "@/CAREUI/icons/CareIcon";
import PaginatedList from "@/CAREUI/misc/PaginatedList";

import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";

import routes from "@/Utils/request/api";
Expand All @@ -13,8 +11,6 @@ import { Encounter } from "@/types/emr/encounter";
import { Question } from "@/types/questionnaire/question";
import { QuestionnaireResponse } from "@/types/questionnaire/questionnaireResponse";

import { StructuredResponseView } from "./StructuredResponseView";

interface Props {
encounter: Encounter;
}
Expand Down Expand Up @@ -128,21 +124,6 @@ function QuestionGroup({

export default function QuestionnaireResponsesList({ encounter }: Props) {
const { t } = useTranslation();
const [expandedResponseIds, setExpandedResponseIds] = useState<Set<string>>(
new Set(),
);

const toggleResponse = (id: string) => {
setExpandedResponseIds((prev) => {
const next = new Set(prev);
if (next.has(id)) {
next.delete(id);
} else {
next.add(id);
}
return next;
});
};

return (
<PaginatedList
Expand Down Expand Up @@ -204,74 +185,63 @@ export default function QuestionnaireResponsesList({ encounter }: Props) {
<CareIcon icon="l-clock" className="h-3 w-3" />
<span>{formatDateTime(item.created_date)}</span>
<span className="mt-0.5 text-xs text-muted-foreground">
by {item.created_by?.first_name || ""}{" "}
{item.created_by?.last_name || ""}
{` (${item.created_by?.user_type})`}
{!item.questionnaire && (
<>
{Object.values(
item.structured_responses ?? {},
)[0]?.submit_type === "CREATE"
? "Created"
: "Updated"}{" "}
</>
)}
{
<>
by {item.created_by?.first_name || ""}{" "}
{item.created_by?.last_name || ""}
{item.created_by?.user_type &&
` (${item.created_by?.user_type})`}
</>
}
</span>
</div>
</div>
</div>
<Button
variant="outline"
size="sm"
onClick={() => toggleResponse(item.id)}
>
{expandedResponseIds.has(item.id) ? "Hide" : "View"}
</Button>
</div>

{expandedResponseIds.has(item.id) && (
{item.questionnaire && (
<div className="mt-3 border-t pt-3">
{item.questionnaire ? (
// Existing questionnaire response rendering
<div className="space-y-4">
{item.questionnaire?.questions.map(
(question: Question) => {
// Skip structured questions for now as they need special handling
if (question.type === "structured") return null;

const response = item.responses.find(
(r) => r.question_id === question.id,
);
<div className="space-y-4">
{item.questionnaire?.questions.map(
(question: Question) => {
// Skip structured questions for now as they need special handling
if (question.type === "structured") return null;

if (question.type === "group") {
return (
<QuestionGroup
key={question.id}
group={question}
responses={item.responses}
/>
);
}

if (!response) return null;
const response = item.responses.find(
(r) => r.question_id === question.id,
);

if (question.type === "group") {
return (
<QuestionResponseValue
<QuestionGroup
key={question.id}
question={question}
response={response}
group={question}
responses={item.responses}
/>
);
},
)}
</div>
) : item.structured_responses ? (
// New structured response rendering
Object.entries(item.structured_responses).map(
([type, response]) => {
}

if (!response) return null;

return (
<StructuredResponseView
key={response.id}
type={type}
id={response.id}
patientId={encounter.patient.id}
encounterId={encounter.id}
<QuestionResponseValue
key={question.id}
question={question}
response={response}
/>
);
},
)
) : null}
)}
</div>
</div>
)}
</Card>
Expand Down

This file was deleted.

6 changes: 4 additions & 2 deletions src/components/Patient/allergy/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import allergyIntoleranceApi from "@/types/emr/allergyIntolerance/allergyIntoler

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

export function AllergyList({ patientId }: AllergyListProps) {
export function AllergyList({ patientId, encounterId }: AllergyListProps) {
const { data: allergies, isLoading } = useQuery({
queryKey: ["allergies", patientId],
queryKey: ["allergies", patientId, encounterId],
queryFn: query(allergyIntoleranceApi.getAllergy, {
pathParams: { patientId },
queryParams: encounterId ? { encounter: encounterId } : undefined,
}),
});

Expand Down
3 changes: 3 additions & 0 deletions src/components/Questionnaire/QuestionRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface QuestionRendererProps {
activeGroupId?: string;
encounterId?: string;
facilityId: string;
patientId: string;
}

export function QuestionRenderer({
Expand All @@ -28,6 +29,7 @@ export function QuestionRenderer({
activeGroupId,
encounterId,
facilityId,
patientId,
}: QuestionRendererProps) {
const questionRefs = useRef<{ [key: string]: HTMLDivElement | null }>({});

Expand Down Expand Up @@ -70,6 +72,7 @@ export function QuestionRenderer({
clearError={clearError}
disabled={disabled}
activeGroupId={activeGroupId}
patientId={patientId}
/>
</div>
))}
Expand Down
Loading

0 comments on commit bd8ac7e

Please sign in to comment.