From d98b9de059a6310869def333a5888d0da0e611ad Mon Sep 17 00:00:00 2001 From: Amjith Titus Date: Thu, 20 Feb 2025 16:29:47 +0530 Subject: [PATCH 1/2] Location Prefill --- .../QuestionTypes/LocationQuestion.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/Questionnaire/QuestionTypes/LocationQuestion.tsx b/src/components/Questionnaire/QuestionTypes/LocationQuestion.tsx index 5d2e1391d6c..834e4a800f5 100644 --- a/src/components/Questionnaire/QuestionTypes/LocationQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/LocationQuestion.tsx @@ -1,3 +1,4 @@ +import { useQuery } from "@tanstack/react-query"; import { format } from "date-fns"; import React, { useState } from "react"; @@ -5,6 +6,9 @@ import { Input } from "@/components/ui/input"; import { LocationSearch } from "@/components/Location/LocationSearch"; +import api from "@/Utils/request/api"; +import query from "@/Utils/request/query"; +import { Encounter } from "@/types/emr/encounter"; import { LocationAssociationQuestion } from "@/types/location/association"; import { LocationList } from "@/types/location/location"; import { @@ -34,8 +38,16 @@ export function LocationQuestion({ facilityId, encounterId, }: LocationQuestionProps) { + const { data: encounter } = useQuery({ + queryKey: ["encounter", encounterId], + queryFn: query(api.encounter.get, { + pathParams: { id: encounterId }, + queryParams: { facility: facilityId }, + }), + }); + const [selectedLocation, setSelectedLocation] = useState( - null, + encounter?.current_location || null, ); const values = From eb0e0761c8ae409604b5e41f4bb75dd194a452ed Mon Sep 17 00:00:00 2001 From: Amjith Titus Date: Thu, 20 Feb 2025 16:47:37 +0530 Subject: [PATCH 2/2] Use useeffect instead --- .../Questionnaire/QuestionTypes/LocationQuestion.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/Questionnaire/QuestionTypes/LocationQuestion.tsx b/src/components/Questionnaire/QuestionTypes/LocationQuestion.tsx index 834e4a800f5..9f809b6ed52 100644 --- a/src/components/Questionnaire/QuestionTypes/LocationQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/LocationQuestion.tsx @@ -1,6 +1,6 @@ import { useQuery } from "@tanstack/react-query"; import { format } from "date-fns"; -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import { Input } from "@/components/ui/input"; @@ -47,9 +47,15 @@ export function LocationQuestion({ }); const [selectedLocation, setSelectedLocation] = useState( - encounter?.current_location || null, + null, ); + useEffect(() => { + if (encounter?.current_location) { + setSelectedLocation(encounter.current_location); + } + }, [encounter]); + const values = (questionnaireResponse.values?.[0] ?.value as unknown as LocationAssociationQuestion[]) || [];