Skip to content

Commit

Permalink
cleanup API routes
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Oct 26, 2023
1 parent 999693c commit fb19237
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 131 deletions.
17 changes: 4 additions & 13 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -183,8 +183,6 @@ const DischargeModal = ({
});
};

const prescriptionActions = PrescriptionActions(consultationData.id ?? "");

const handleFacilitySelect = (selected: FacilityModel) => {
setFacility(selected);
const { id, name } = selected || {};
Expand Down Expand Up @@ -238,7 +236,7 @@ const DischargeModal = ({
setSelected={(selected) =>
handleFacilitySelect(selected as FacilityModel)
}
selected={facility}
selected={facility ?? null}
showAll
freeText
multiple={false}
Expand Down Expand Up @@ -284,18 +282,11 @@ const DischargeModal = ({

<div className="mb-4">
<FieldLabel>Discharge Prescription Medications</FieldLabel>
<PrescriptionBuilder
actions={prescriptionActions}
prescription_type="DISCHARGE"
/>
<PrescriptionBuilder prescription_type="DISCHARGE" />
</div>
<div className="mb-4">
<FieldLabel>Discharge PRN Prescriptions</FieldLabel>
<PrescriptionBuilder
actions={prescriptionActions}
prescription_type="DISCHARGE"
is_prn
/>
<PrescriptionBuilder prescription_type="DISCHARGE" is_prn />
</div>
</div>
)}
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Medicine/EditPrescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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,
Expand Down
74 changes: 1 addition & 73 deletions src/Redux/actions.tsx
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down Expand Up @@ -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<string, any>) => {
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) => {
Expand Down
43 changes: 1 addition & 42 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
AssetUpdate,
} from "../Components/Assets/AssetTypes";
import {
ConsultationModel,
FacilityModel,
LocationModel,
WardModel,
Expand All @@ -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";
Expand Down Expand Up @@ -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<Prescription>(),
TRes: Type<Prescription>(),
},

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<Record<string, never>>(),
},

// HCX Endpoints

listPMJYPackages: {
Expand Down

0 comments on commit fb19237

Please sign in to comment.