From fb19237dbc388ba3b1b7d82d1d415139bbc8d262 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 26 Oct 2023 08:25:11 +0530 Subject: [PATCH] cleanup API routes --- src/Components/Facility/DischargeModal.tsx | 17 +---- .../Medicine/EditPrescriptionForm.tsx | 6 +- src/Redux/actions.tsx | 74 +------------------ src/Redux/api.tsx | 43 +---------- 4 files changed, 9 insertions(+), 131 deletions(-) diff --git a/src/Components/Facility/DischargeModal.tsx b/src/Components/Facility/DischargeModal.tsx index b069b371a72..138e74fb9b9 100644 --- a/src/Components/Facility/DischargeModal.tsx +++ b/src/Components/Facility/DischargeModal.tsx @@ -12,7 +12,7 @@ import DateFormField from "../Form/FormFields/DateFormField"; import DialogModal from "../Common/Dialog"; import { FieldChangeEvent } from "../Form/FormFields/Utils"; import { FieldLabel } from "../Form/FormFields/FormField"; -import { HCXActions, PrescriptionActions } from "../../Redux/actions"; +import { HCXActions } from "../../Redux/actions"; import { HCXClaimModel } from "../HCX/models"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; @@ -183,8 +183,6 @@ const DischargeModal = ({ }); }; - const prescriptionActions = PrescriptionActions(consultationData.id ?? ""); - const handleFacilitySelect = (selected: FacilityModel) => { setFacility(selected); const { id, name } = selected || {}; @@ -238,7 +236,7 @@ const DischargeModal = ({ setSelected={(selected) => handleFacilitySelect(selected as FacilityModel) } - selected={facility} + selected={facility ?? null} showAll freeText multiple={false} @@ -284,18 +282,11 @@ const DischargeModal = ({
Discharge Prescription Medications - +
Discharge PRN Prescriptions - +
)} diff --git a/src/Components/Medicine/EditPrescriptionForm.tsx b/src/Components/Medicine/EditPrescriptionForm.tsx index d5261f70c7e..cdf2e125dae 100644 --- a/src/Components/Medicine/EditPrescriptionForm.tsx +++ b/src/Components/Medicine/EditPrescriptionForm.tsx @@ -2,7 +2,6 @@ import { useState } from "react"; import Form from "../Form/Form"; import { Prescription } from "./models"; import request from "../../Utils/request/request"; -import routes from "../../Redux/api"; import * as Notification from "../../Utils/Notifications"; import useSlug from "../../Common/hooks/useSlug"; import { RequiredFieldValidator } from "../Form/FieldValidators"; @@ -16,6 +15,7 @@ import { import TextFormField from "../Form/FormFields/TextFormField"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; import { EditPrescriptionFormValidator } from "./validators"; +import MedicineRoutes from "./routes"; interface Props { initial: Prescription; @@ -27,7 +27,7 @@ const handleSubmit = async ( oldObj: Prescription, { discontinued_reason, ...newObj }: Prescription ) => { - const discontinue = await request(routes.discontinuePrescription, { + const discontinue = await request(MedicineRoutes.discontinuePrescription, { pathParams: { consultation_external_id, external_id: oldObj.id }, body: { discontinued_reason: discontinued_reason @@ -43,7 +43,7 @@ const handleSubmit = async ( return; } - const { res } = await request(routes.createPrescription, { + const { res } = await request(MedicineRoutes.createPrescription, { pathParams: { consultation_external_id }, body: { ...newObj, diff --git a/src/Redux/actions.tsx b/src/Redux/actions.tsx index 1d2d6f4f7b6..521a01e83b7 100644 --- a/src/Redux/actions.tsx +++ b/src/Redux/actions.tsx @@ -1,9 +1,5 @@ import { HCXClaimModel, HCXPolicyModel } from "../Components/HCX/models"; -import { - MedibaseMedicine, - MedicineAdministrationRecord, - Prescription, -} from "../Components/Medicine/models"; +import { MedibaseMedicine } from "../Components/Medicine/models"; import { fireRequest, fireRequestForFiles } from "./fireRequest"; export const getConfig = () => { @@ -879,74 +875,6 @@ export const getAssetAvailability = (id: string) => export const listPMJYPackages = (query?: string) => fireRequest("listPMJYPackages", [], { query }); -/** Prescription related actions */ -export const PrescriptionActions = (consultation_external_id: string) => { - const pathParams = { consultation_external_id }; - - return { - list: (query?: Record) => { - let altKey; - if (query?.is_prn !== undefined) { - altKey = query?.is_prn - ? "listPRNPrescriptions" - : "listNormalPrescriptions"; - } - return fireRequest("listPrescriptions", [], query, pathParams, altKey); - }, - - create: (obj: Prescription) => - fireRequest("createPrescription", [], obj, pathParams), - - listAdministrations: (query?: object) => - fireRequest("listAdministrations", [], query, pathParams), - - getAdministration: (external_id: string) => - fireRequest("getAdministration", [], {}, { ...pathParams, external_id }), - - /** Returns actions specific to a prescription */ - prescription(external_id: string) { - const pathParams = { consultation_external_id, external_id }; - - return { - /** Read a specific prescription of a consultation */ - get: () => fireRequest("getPrescription", [], {}, pathParams), - - /** Administer a prescription */ - administer: (obj: MedicineAdministrationRecord) => - fireRequest( - "administerPrescription", - [], - obj, - pathParams, - `administer-medicine-${external_id}` - ), - - listAdministrations: (query?: { - administered_date_after?: string; - administered_date_before?: string; - }) => - fireRequest( - "listAdministrations", - [], - { prescription: external_id, ...query }, - pathParams, - `list-administrations-${external_id}` - ), - - /** Discontinue a prescription */ - discontinue: (discontinued_reason: string | undefined) => - fireRequest( - "discontinuePrescription", - [], - { discontinued_reason }, - pathParams, - `discontinue-medicine-${external_id}` - ), - }; - }, - }; -}; - // HCX Actions export const HCXActions = { checkEligibility: (policy: string) => { diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 60d8ed1dae8..6ab8abbe7be 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -28,6 +28,7 @@ import { AssetUpdate, } from "../Components/Assets/AssetTypes"; import { + ConsultationModel, FacilityModel, LocationModel, WardModel, @@ -40,7 +41,6 @@ import { ILocalBodyByDistrict, IPartialUpdateExternalResult, } from "../Components/ExternalResult/models"; -import { Prescription } from "../Components/Medicine/models"; import { PatientModel } from "../Components/Patient/models"; import { UserModel } from "../Components/Users/models"; import { PaginatedResponse } from "../Utils/request/types"; @@ -1096,47 +1096,6 @@ const routes = { method: "GET", }, - // Prescription endpoints - - listPrescriptions: { - path: "/api/v1/consultation/{consultation_external_id}/prescriptions/", - method: "GET", - }, - - createPrescription: { - path: "/api/v1/consultation/{consultation_external_id}/prescriptions/", - method: "POST", - TBody: Type(), - TRes: Type(), - }, - - listAdministrations: { - path: "/api/v1/consultation/{consultation_external_id}/prescription_administration/", - method: "GET", - }, - - getAdministration: { - path: "/api/v1/consultation/{consultation_external_id}/prescription_administration/{external_id}/", - method: "GET", - }, - - getPrescription: { - path: "/api/v1/consultation/{consultation_external_id}/prescriptions/{external_id}/", - method: "GET", - }, - - administerPrescription: { - path: "/api/v1/consultation/{consultation_external_id}/prescriptions/{external_id}/administer/", - method: "POST", - }, - - discontinuePrescription: { - path: "/api/v1/consultation/{consultation_external_id}/prescriptions/{external_id}/discontinue/", - method: "POST", - TBody: Type<{ discontinued_reason: string }>(), - TRes: Type>(), - }, - // HCX Endpoints listPMJYPackages: {