From 86d110a7fdd7fe9de0e720a032f6a52754c465fe Mon Sep 17 00:00:00 2001 From: Amjith Titus Date: Wed, 15 Jan 2025 17:42:19 +0530 Subject: [PATCH 1/4] Print Prescription cleanup (#9991) --- public/locale/en.json | 7 + src/CAREUI/misc/PrintPreview.tsx | 2 +- src/Utils/request/api.tsx | 4 +- src/pages/Encounters/PrintPrescription.tsx | 326 ++++++++++----------- 4 files changed, 164 insertions(+), 175 deletions(-) diff --git a/public/locale/en.json b/public/locale/en.json index a8211b379a4..6b1d2e0558d 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -593,6 +593,7 @@ "comments": "Comments", "communication__sent_to_hcx": "Sent communication to HCX", "completed": "Completed", + "computer_generated_prescription": "This is a computer generated prescription.", "configure": "Configure", "configure_facility": "Configure Facility", "confirm": "Confirm", @@ -865,6 +866,7 @@ "encounter_class__obsenc": "Observation", "encounter_class__planned": "Planned", "encounter_class__vr": "Virtual", + "encounter_date": "Encounter Date", "encounter_date_field_label__A": "Date & Time of Admission to the Facility", "encounter_date_field_label__DC": "Date & Time of Domiciliary Care commencement", "encounter_date_field_label__DD": "Date & Time of Consultation", @@ -1064,6 +1066,7 @@ "general_info_detail": "Provide the patient's personal details, including name, date of birth, gender, and contact information for accurate identification and communication.", "generate_link_abha": "Generate/Link ABHA Number", "generate_report": "Generate Report", + "generated_on": "Generated on:", "generated_summary_caution": "This is a computer generated summary using the information captured in the CARE system.", "generating": "Generating", "generating_discharge_summary": "Generating discharge summary", @@ -1288,6 +1291,7 @@ "medication_taken_between": "Medication Taken Between", "medicine": "Medicine", "medicine_administration_history": "Medicine Administration History", + "medicine_prescription": "Medicine Prescription", "medicines_administered": "Medicine(s) administered", "medicines_administered_error": "Error administering medicine(s)", "member_id_required": "Member Id is required", @@ -1370,6 +1374,7 @@ "no_log_update_delta": "No changes since previous log update", "no_log_updates": "No log updates found", "no_medical_history_available": "No Medical History Available", + "no_medications_found_for_this_encounter": "No medications found for this encounter.", "no_notices_for_you": "No notices for you.", "no_observations": "No Observations", "no_ongoing_medications": "No Ongoing Medications", @@ -1613,6 +1618,7 @@ "prescription_logs": "Prescription Logs", "prescription_medication": "Prescription Medication", "prescription_medications": "Prescription Medications", + "prescriptions": "Prescriptions", "prescriptions__dosage_frequency": "Dosage & Frequency", "prescriptions__medicine": "Medicine", "prescriptions__route": "Route", @@ -1627,6 +1633,7 @@ "principal": "Principal", "principal_diagnosis": "Principal diagnosis", "print": "Print", + "print_prescriptions": "Print Prescriptions", "print_referral_letter": "Print Referral Letter", "priority": "Priority", "prn_prescription": "PRN Prescription", diff --git a/src/CAREUI/misc/PrintPreview.tsx b/src/CAREUI/misc/PrintPreview.tsx index daf79ecbb34..c34c75f3299 100644 --- a/src/CAREUI/misc/PrintPreview.tsx +++ b/src/CAREUI/misc/PrintPreview.tsx @@ -29,7 +29,7 @@ export default function PrintPreview(props: Props) { return ( -
+
- } - /> +
+ + + {t("more_details")} + + } + /> +
-
- - - )) - )} -
+ + + )) + )} + + )} + ); From 31aac7389b43fd62076c4234450c60502ecead5f Mon Sep 17 00:00:00 2001 From: Abhimanyu Rajeesh <63541653+abhimanyurajeesh@users.noreply.github.com> Date: Wed, 15 Jan 2025 20:07:34 +0530 Subject: [PATCH 3/4] Removed unused feature flag handling and migrated to TanStack's query (#9892) --- src/App.tsx | 5 +- src/Utils/featureFlags.tsx | 81 ------------------------------ src/Utils/request/api.tsx | 1 + src/components/Facility/models.tsx | 3 -- src/components/Users/models.tsx | 2 - src/pages/Apps/PlugConfigEdit.tsx | 76 ++++++++++++---------------- src/pages/Apps/PlugConfigList.tsx | 10 ++-- 7 files changed, 42 insertions(+), 136 deletions(-) delete mode 100644 src/Utils/featureFlags.tsx diff --git a/src/App.tsx b/src/App.tsx index e1afe64e966..51e33c2209d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -17,7 +17,6 @@ import PluginEngine from "@/PluginEngine"; import AuthUserProvider from "@/Providers/AuthUserProvider"; import HistoryAPIProvider from "@/Providers/HistoryAPIProvider"; import Routers from "@/Routers"; -import { FeatureFlagsProvider } from "@/Utils/featureFlags"; import { handleHttpError } from "@/Utils/request/errorHandler"; import { PubSubProvider } from "./Utils/pubsubContext"; @@ -48,9 +47,7 @@ const App = () => { unauthorized={} otpAuthorized={} > - - - + {/* Integrations */} diff --git a/src/Utils/featureFlags.tsx b/src/Utils/featureFlags.tsx deleted file mode 100644 index 98d1cbebbf7..00000000000 --- a/src/Utils/featureFlags.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import { createContext, useContext, useEffect, useState } from "react"; - -import { FacilityModel } from "@/components/Facility/models"; - -import useAuthUser from "@/hooks/useAuthUser"; - -import routes from "@/Utils/request/api"; -import useTanStackQueryInstead from "@/Utils/request/useQuery"; - -export type FeatureFlag = "SCRIBE_ENABLED"; // "HCX_ENABLED" | "ABDM_ENABLED" | - -export interface FeatureFlagsResponse { - user_flags: FeatureFlag[]; - facility_flags: { - facility: string; - features: FeatureFlag[]; - }[]; -} - -const defaultFlags: FeatureFlag[] = []; - -const FeatureFlagsContext = createContext({ - user_flags: defaultFlags, - facility_flags: [], -}); - -export const FeatureFlagsProvider = (props: { children: React.ReactNode }) => { - const [featureFlags, setFeatureFlags] = useState({ - user_flags: defaultFlags, - facility_flags: [], - }); - - const user = useAuthUser(); - - useEffect(() => { - if (user.user_flags) { - setFeatureFlags((ff) => ({ - ...ff, - user_flags: [...defaultFlags, ...(user.user_flags || [])], - })); - } - }, [user]); - - return ( - - {props.children} - - ); -}; - -export const useFeatureFlags = (facility?: FacilityModel | string) => { - const [facilityObject, setFacilityObject] = useState< - FacilityModel | undefined - >(typeof facility === "string" ? undefined : facility); - - const context = useContext(FeatureFlagsContext); - if (context === undefined) { - throw new Error( - "useFeatureFlags must be used within a FeatureFlagsProvider", - ); - } - - const facilityQuery = useTanStackQueryInstead(routes.getPermittedFacility, { - pathParams: { - id: typeof facility === "string" ? facility : "", - }, - prefetch: false, - silent: true, - onResponse: (res) => { - setFacilityObject(res.data); - }, - }); - - const facilityFlags = facilityObject?.facility_flags || []; - - useEffect(() => { - facilityQuery.refetch(); - }, [facility]); - - return [...context.user_flags, ...facilityFlags]; -}; diff --git a/src/Utils/request/api.tsx b/src/Utils/request/api.tsx index 46b7ad2bedd..68e3a926e6b 100644 --- a/src/Utils/request/api.tsx +++ b/src/Utils/request/api.tsx @@ -417,6 +417,7 @@ const routes = { path: "/api/v1/plug_config/{slug}/", method: "DELETE", TRes: Type>(), + TBody: Type(), }, }, getQuestionnaireResponses: { diff --git a/src/components/Facility/models.tsx b/src/components/Facility/models.tsx index aba560973ea..33c8b2d5b94 100644 --- a/src/components/Facility/models.tsx +++ b/src/components/Facility/models.tsx @@ -1,7 +1,5 @@ import { UserBareMinimum } from "@/components/Users/models"; -import { FeatureFlag } from "@/Utils/featureFlags"; - export interface FacilityModel { id?: string; name?: string; @@ -20,7 +18,6 @@ export interface FacilityModel { created_date?: string; geo_organization?: string; pincode?: string; - facility_flags?: FeatureFlag[]; latitude?: string; longitude?: string; is_public?: boolean; diff --git a/src/components/Users/models.tsx b/src/components/Users/models.tsx index 5335255c298..43c3f6a2ec3 100644 --- a/src/components/Users/models.tsx +++ b/src/components/Users/models.tsx @@ -2,7 +2,6 @@ import { Gender, UserType } from "@/components/Users/UserFormValidations"; import { GENDER_TYPES } from "@/common/constants"; -import { FeatureFlag } from "@/Utils/featureFlags"; import { Organization } from "@/types/organization/organization"; export type UpdatePasswordForm = { @@ -46,7 +45,6 @@ export type UserModel = UserBareMinimum & { doctor_experience_commenced_on?: string; doctor_medical_council_registration?: string; weekly_working_hours?: string | null; - user_flags?: FeatureFlag[]; facilities?: UserFacilityModel[]; organizations?: Organization[]; permissions: string[]; diff --git a/src/pages/Apps/PlugConfigEdit.tsx b/src/pages/Apps/PlugConfigEdit.tsx index 778f44a06b6..353a1796b88 100644 --- a/src/pages/Apps/PlugConfigEdit.tsx +++ b/src/pages/Apps/PlugConfigEdit.tsx @@ -1,4 +1,5 @@ -import { navigate } from "raviger"; +import { useMutation, useQuery } from "@tanstack/react-query"; +import { useNavigate } from "raviger"; import { useEffect, useState } from "react"; import CareIcon from "@/CAREUI/icons/CareIcon"; @@ -21,19 +22,22 @@ import { Textarea } from "@/components/ui/textarea"; import Loading from "@/components/Common/Loading"; import routes from "@/Utils/request/api"; -import request from "@/Utils/request/request"; -import useQuery from "@/Utils/request/useQuery"; +import mutate from "@/Utils/request/mutate"; +import query from "@/Utils/request/query"; interface Props { slug: string; } export function PlugConfigEdit({ slug }: Props) { + const navigate = useNavigate(); const isNew = slug === "new"; - const { data: existingConfig, loading } = useQuery( - routes.plugConfig.getPlugConfig, - { pathParams: { slug }, prefetch: !isNew }, - ); + + const { data: existingConfig, isLoading } = useQuery({ + queryKey: ["plug-config", slug], + queryFn: query(routes.plugConfig.getPlugConfig, { pathParams: { slug } }), + enabled: !isNew, + }); const [config, setConfig] = useState({ slug: "", @@ -49,40 +53,32 @@ export function PlugConfigEdit({ slug }: Props) { } }, [existingConfig]); + const { mutate: upsertConfig } = useMutation({ + mutationFn: isNew + ? mutate(routes.plugConfig.createPlugConfig) + : mutate(routes.plugConfig.updatePlugConfig, { pathParams: { slug } }), + onSuccess: () => navigate("/apps"), + }); + + const { mutate: deleteConfig } = useMutation({ + mutationFn: mutate(routes.plugConfig.deletePlugConfig, { + pathParams: { slug }, + }), + onSuccess: () => navigate("/apps"), + }); + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - // Meta is parsed to a JSON object to clear whitespaces when saving const meta = JSON.parse(config.meta); const configPayload = { ...config, meta }; - try { - if (isNew) { - await request(routes.plugConfig.createPlugConfig, { - body: configPayload, - }); - } else { - await request(routes.plugConfig.updatePlugConfig, { - pathParams: { slug }, - body: configPayload, - }); - } - navigate("/apps"); - } catch (error) { - console.error("Error saving config:", error); - } + upsertConfig(configPayload); }; - const handleDelete = async () => { - try { - await request(routes.plugConfig.deletePlugConfig, { - pathParams: { slug }, - }); - navigate("/apps"); - } catch (error) { - console.error("Error deleting config:", error); - } + const handleDelete = () => { + deleteConfig(); }; - if (loading) { + if (isLoading) { return ; } @@ -128,27 +124,21 @@ export function PlugConfigEdit({ slug }: Props) { - setConfig((prev) => ({ - ...prev, - slug: e.target.value, - })) + setConfig((prev) => ({ ...prev, slug: e.target.value })) } required /> -