diff --git a/src/Common/constants.tsx b/src/Common/constants.tsx index 70b5bc78e23..d46473bfd2d 100644 --- a/src/Common/constants.tsx +++ b/src/Common/constants.tsx @@ -1156,68 +1156,6 @@ export const AssetImportSchema: SchemaType = { }, }; -export const ExternalResultImportSchema: SchemaType = { - District: { prop: "district", type: "any" }, - "SRF ID": { prop: "srf_id", type: "string" }, - Name: { prop: "name", type: "string" }, - Age: { prop: "age", type: "number" }, - "Age in": { prop: "age_in", type: "string" }, - Gender: { prop: "gender", type: "string" }, - "Mobile Number": { prop: "mobile_number", type: "any" }, - Address: { prop: "address", type: "string" }, - Ward: { prop: "ward", type: "number" }, - "Local Body": { prop: "local_body", type: "string" }, - "Local Body Type": { prop: "local_body_type", type: "string" }, - Source: { prop: "source", type: "string" }, - "Sample Collection Date": { - prop: "sample_collection_date", - type: "string", - parse: (date: string) => { - if (!date) return null; - if (isNaN(Date.parse(date))) { - const parsed = new Date(date); - if (String(parsed) === "Invalid Date") { - throw new Error("Invalid Date: " + date); - } - return dateQueryString(parsed); - } else { - const parsed = new Date(date); - if (String(parsed) === "Invalid Date") { - throw new Error("Invalid Date: " + date); - } - return dateQueryString(parsed); - } - }, - }, - "Result Date": { - prop: "result_date", - type: "string", - parse: (date: string) => { - if (!date) return null; - if (isNaN(Date.parse(date))) { - const parsed = new Date(date); - if (String(parsed) === "Invalid Date") { - throw new Error("Invalid Date: " + date); - } - return dateQueryString(parsed); - } else { - const parsed = new Date(date); - if (String(parsed) === "Invalid Date") { - throw new Error("Invalid Date: " + date); - } - return dateQueryString(parsed); - } - }, - }, - "Test Type": { prop: "test_type", type: "string" }, - "Lab Name": { prop: "lab_name", type: "string" }, - "Sample Type": { prop: "sample_type", type: "string" }, - "Patient Status": { prop: "patient_status", type: "string" }, - "Is Repeat": { prop: "is_repeat", type: "string" }, - "Patient Category": { prop: "patient_category", type: "string" }, - Result: { prop: "result", type: "string" }, -}; - // ABDM export const ABDM_CONSENT_PURPOSE = [ { value: "CAREMGT", label: "Care Management" }, diff --git a/src/Components/Common/Breadcrumbs.tsx b/src/Components/Common/Breadcrumbs.tsx index 1ef56316890..c092ecbbc93 100644 --- a/src/Components/Common/Breadcrumbs.tsx +++ b/src/Components/Common/Breadcrumbs.tsx @@ -12,7 +12,6 @@ const MENU_TAGS: { [key: string]: string } = { sample: "Sample Tests", shifting: "Shiftings", resource: "Resources", - external_results: "External Results", users: "Users", notice_board: "Notice Board", }; diff --git a/src/Components/Common/Sidebar/Sidebar.tsx b/src/Components/Common/Sidebar/Sidebar.tsx index f7044d84b02..0e9ee34b715 100644 --- a/src/Components/Common/Sidebar/Sidebar.tsx +++ b/src/Components/Common/Sidebar/Sidebar.tsx @@ -7,7 +7,6 @@ import CareIcon, { IconName } from "../../../CAREUI/icons/CareIcon"; import SlideOver from "../../../CAREUI/interactive/SlideOver"; import { classNames } from "../../../Utils/utils"; import { Link } from "raviger"; -import useAuthUser from "../../../Common/hooks/useAuthUser"; import careConfig from "@careConfig"; export const SIDEBAR_SHRINK_PREFERENCE_KEY = "sidebarShrinkPreference"; @@ -33,8 +32,6 @@ const StatelessSidebar = ({ setShrinked, onItemClick, }: StatelessSidebarProps) => { - const authUser = useAuthUser(); - const NavItems: { text: string; to: string; @@ -46,17 +43,6 @@ const StatelessSidebar = ({ { text: "Sample Test", to: "/sample", icon: "l-medkit" }, { text: "Shifting", to: "/shifting", icon: "l-ambulance" }, { text: "Resource", to: "/resource", icon: "l-heart-medical" }, - ...(!["Nurse", "NurseReadOnly", "Staff", "StaffReadOnly"].includes( - authUser.user_type, - ) - ? ([ - { - text: "External Results", - to: "/external_results", - icon: "l-clipboard-notes", - }, - ] as const) - : []), { text: "Users", to: "/users", icon: "l-users-alt" }, { text: "Notice Board", to: "/notice_board", icon: "l-meeting-board" }, ]; diff --git a/src/Components/ExternalResult/Commons.tsx b/src/Components/ExternalResult/Commons.tsx deleted file mode 100644 index 6a7dfcd8e77..00000000000 --- a/src/Components/ExternalResult/Commons.tsx +++ /dev/null @@ -1,25 +0,0 @@ -export const externalResultFormatter = (props: any) => { - const data = props.map((el: any) => { - return { - Id: el.id, - Name: el.name, - Address: el.address, - Age: el.age, - Gender: el.gender, - Mobile: el.mobile_number, - Ward: el.ward_object?.name || "NILL", - Local_Body: el.local_body_object?.name || "NILL", - District: el.district_object?.name, - Result: el.result, - Test_Type: el.test_type, - Patient_Status: el.patient_status, - Patient_Category: el.patient_category, - SRF_ID: el.srf_id, - Sample_Type: el.sample_type, - Lab_Name: el.lab_name, - Sample_Collection_Date: el.sample_collection_date, - Result_Date: el.result_date, - }; - }); - return data; -}; diff --git a/src/Components/ExternalResult/ExternalResultImportModal.tsx b/src/Components/ExternalResult/ExternalResultImportModal.tsx deleted file mode 100644 index cd896b285ff..00000000000 --- a/src/Components/ExternalResult/ExternalResultImportModal.tsx +++ /dev/null @@ -1,112 +0,0 @@ -import * as _ from "lodash-es"; -import { navigate } from "raviger"; -import { useEffect, useState, lazy } from "react"; -import * as Notification from "../../Utils/Notifications.js"; -import request from "../../Utils/request/request"; -import routes from "../../Redux/api"; -import { ExternalResultImportSchema } from "../../Common/constants"; -import DialogModal from "../Common/Dialog"; -import { IExternalResult } from "./models"; -import careConfig from "@careConfig"; -const ExcelFileDragAndDrop = lazy( - () => import("../Common/ExcelFIleDragAndDrop"), -); - -interface Props { - open: boolean; - onClose: () => void; -} - -export default function ExternalResultImportModal({ open, onClose }: Props) { - const [loading, setLoading] = useState(false); - - const fetchUser = async () => { - const { data: user } = await request(routes.currentUser, { - pathParams: {}, - }); - - ExternalResultImportSchema.Address.parse = (value: string) => { - if ( - user?.user_type === "StateAdmin" || - user?.user_type === "StateLabAdmin" - ) { - if (value.split(",").pop()?.trim() === user?.state_object?.name) { - return value; - } else { - throw new Error("State should be the same as the user's state"); - } - } - return value; - }; - - ExternalResultImportSchema.District.parse = (value: string) => { - if ( - user?.user_type === "StateAdmin" || - user?.user_type === "StateLabAdmin" - ) { - return value; - } else if (value !== user?.district_object?.name) { - throw new Error("District should be the same as the user's district"); - } - }; - }; - - useEffect(() => { - fetchUser(); - }, []); - - const handleSubmit = async (data: IExternalResult[]) => { - setLoading(true); - - if (data.length !== 0) { - try { - const { res } = await request(routes.externalResultUploadCsv, { - body: { - sample_tests: data, - }, - }); - - if (res && res.status === 202) { - setLoading(false); - navigate("/external_results"); - Notification.Success({ - msg: "External Results imported successfully", - }); - } else { - Notification.Error({ - msg: "Something went wrong", - }); - setLoading(false); - } - } catch (error) { - Notification.Error({ - msg: "Something went wrong: " + error, - }); - setLoading(false); - } finally { - setLoading(false); - onClose(); - } - } else { - setLoading(false); - } - }; - - return ( - - - - ); -} diff --git a/src/Components/ExternalResult/ListFilter.tsx b/src/Components/ExternalResult/ListFilter.tsx deleted file mode 100644 index 5beb1fe6e20..00000000000 --- a/src/Components/ExternalResult/ListFilter.tsx +++ /dev/null @@ -1,255 +0,0 @@ -import { useState } from "react"; -import useMergeState from "../../Common/hooks/useMergeState"; -import { useTranslation } from "react-i18next"; -import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; -import TextFormField from "../Form/FormFields/TextFormField"; -import { MultiSelectFormField } from "../Form/FormFields/SelectFormField"; -import DateRangeFormField from "../Form/FormFields/DateRangeFormField"; -import dayjs from "dayjs"; -import { dateQueryString, compareBy } from "../../Utils/utils"; -import useAuthUser from "../../Common/hooks/useAuthUser"; -import useQuery from "../../Utils/request/useQuery"; -import routes from "../../Redux/api"; -import Loading from "../Common/Loading"; -import { LocalBodyModel, WardModel } from "../Facility/models"; - -const getDate = (value: any) => - value && dayjs(value).isValid() && dayjs(value).toDate(); - -export default function ListFilter(props: any) { - const { filter, onChange, closeFilter, dataList, removeFilters } = props; - const [wardList, setWardList] = useState([]); - const [lsgList, setLsgList] = useState([]); - const [wards, setWards] = useState([]); - const [selectedLsgs, setSelectedLsgs] = useState([]); - const authUser = useAuthUser(); - const [filterState, setFilterState] = useMergeState({ - created_date_before: filter.created_date_before || null, - created_date_after: filter.created_date_after || null, - result_date_before: filter.result_date_before || null, - result_date_after: filter.result_date_after || null, - sample_collection_date_before: filter.sample_collection_date_before || null, - sample_collection_date_after: filter.sample_collection_date_after || null, - srf_id: filter.srf_id || null, - }); - const { t } = useTranslation(); - - const { loading } = useQuery(routes.getAllLocalBodyByDistrict, { - pathParams: { id: String(authUser.district) }, - onResponse: ({ res, data }) => { - if (res && data) { - const allWards: any[] = []; - const allLsgs: any[] = []; - - if (res && data) { - data.forEach((local: any) => { - allLsgs.push({ id: local.id, name: local.name }); - if (local.wards) { - local.wards.forEach((ward: any) => { - allWards.push({ - id: ward.id, - name: ward.number + ": " + ward.name, - panchayath: local.name, - number: ward.number, - local_body_id: local.id, - }); - }); - } - }); - } - - allWards.sort(compareBy("number")); - allLsgs.sort(compareBy("name")); - - setWardList(allWards); - setLsgList(allLsgs); - - const filteredWard = filter?.wards?.split(",").map(Number); - const selectedWards: any = - filteredWard && allWards - ? allWards.filter(({ id }: { id: number }) => { - return filteredWard.includes(id); - }) - : []; - setWards(selectedWards); - - const filteredLsgs = filter?.local_bodies?.split(",").map(Number); - const selectedLsgs: any = - filteredLsgs && allLsgs - ? allLsgs.filter(({ id }: { id: number }) => { - return filteredLsgs.includes(id); - }) - : []; - setSelectedLsgs(selectedLsgs); - } - }, - }); - - const handleDateRangeChange = ( - startDateId: string, - endDateId: string, - e: any, - ) => { - const filterData: any = { ...filterState }; - filterData[startDateId] = e.value.start?.toString(); - filterData[endDateId] = e.value.end?.toString(); - - setFilterState(filterData); - }; - - const field = (name: string) => ({ - name, - label: t(name), - value: filterState[name], - onChange: handleChange, - errorClassName: "hidden", - }); - - const applyFilter = () => { - const selectedWardIds = wards.map(function (obj) { - return obj.id; - }); - - const selectedLsgIds = selectedLsgs.map(function (obj) { - return obj.id; - }); - - const { - created_date_before, - created_date_after, - result_date_before, - result_date_after, - sample_collection_date_after, - sample_collection_date_before, - srf_id, - } = filterState; - - const data = { - state: authUser.state, - district: authUser.district, - wards: selectedWardIds.length ? selectedWardIds : "", - local_bodies: selectedLsgIds.length ? selectedLsgIds : "", - created_date_before: dateQueryString(created_date_before), - created_date_after: dateQueryString(created_date_after), - result_date_before: dateQueryString(result_date_before), - result_date_after: dateQueryString(result_date_after), - sample_collection_date_after: dateQueryString( - sample_collection_date_after, - ), - sample_collection_date_before: dateQueryString( - sample_collection_date_before, - ), - srf_id: srf_id, - }; - onChange(data); - dataList(selectedLsgs, wards); - }; - - const filterWards = () => { - const selectedLsgIds: any = selectedLsgs.map((e) => { - return e.id; - }); - const selectedwards: any = - selectedLsgIds.length === 0 - ? wardList - : wardList.filter(({ local_body_id }: { local_body_id: number }) => { - return selectedLsgIds.includes(local_body_id); - }); - - return selectedwards; - }; - - const handleChange = (event: any) => { - const { name, value } = event.target; - const filterData: any = { ...filterState }; - filterData[name] = value; - setFilterState(filterData); - }; - - if (loading) { - ; - } - - return ( - { - removeFilters(); - closeFilter(); - }} - > - option.name} - optionDescription={(option) => option.localbody_code} - onChange={({ value }) => setSelectedLsgs(value)} - /> - - option.name} - optionDescription={(option) => option.panchayath} - onChange={({ value }) => setWards(value)} - /> - - handleDateRangeChange("created_date_after", "created_date_before", e) - } - label={t("created_date")} - /> - - handleDateRangeChange("result_date_after", "result_date_before", e) - } - label={t("result_date")} - /> - - handleDateRangeChange( - "sample_collection_date_after", - "sample_collection_date_before", - e, - ) - } - label={t("sample_collection_date")} - /> - -
- -
-
- ); -} diff --git a/src/Components/ExternalResult/ResultItem.tsx b/src/Components/ExternalResult/ResultItem.tsx deleted file mode 100644 index 44f40e3248d..00000000000 --- a/src/Components/ExternalResult/ResultItem.tsx +++ /dev/null @@ -1,218 +0,0 @@ -import { useState, lazy } from "react"; -import * as Notification from "../../Utils/Notifications.js"; -import { navigate } from "raviger"; -import { useTranslation } from "react-i18next"; -import Page from "../Common/components/Page"; -import ConfirmDialog from "../Common/ConfirmDialog"; -import useQuery from "../../Utils/request/useQuery"; -import routes from "../../Redux/api"; -import request from "../../Utils/request/request"; -import CareIcon from "../../CAREUI/icons/CareIcon.js"; - -const Loading = lazy(() => import("../Common/Loading")); - -export default function ResultItem(props: any) { - const [showDeleteAlert, setShowDeleteAlert] = useState(false); - const { t } = useTranslation(); - - const { data: resultItemData, loading } = useQuery(routes.externalResult, { - pathParams: { id: props.id }, - }); - - const handleDelete = async () => { - if (showDeleteAlert) { - const { res, data } = await request(routes.deleteExternalResult, { - pathParams: { id: props.id }, - }); - - if (res?.status === 204) { - Notification.Success({ - msg: t("record_has_been_deleted_successfully"), - }); - } else { - Notification.Error({ - msg: t("error_while_deleting_record") + ": " + (data?.detail || ""), - }); - } - setShowDeleteAlert(false); - navigate("/external_results"); - } - }; - - if (loading || !resultItemData) { - return ; - } - - return ( - - { - handleDelete(); - }} - onClose={() => setShowDeleteAlert(false)} - /> -
-
- - -
-
-
-

- {resultItemData.name} -{" "} - {resultItemData.age}{" "} - {resultItemData.age_in} |{" "} - {resultItemData.result} -

-

- {t("srf_id")}: {resultItemData.srf_id} -

-

- {t("care_external_results_id")}: {resultItemData.id} -

- {resultItemData.patient_created ? ( - - {t("patient_created")} - - ) : null} -
-
-
-
-
- {t("gender")} -
-
- {resultItemData.gender} -
-
-
-
- {t("address")} -
-
- {resultItemData.address} - - {resultItemData.ward_object && ( -
- Ward: {resultItemData.ward_object.number}{" "} - {resultItemData.ward_object.name} -
- )} - {resultItemData.local_body_object && ( -
- {resultItemData.local_body_object.name} -
- )} -
-
-
-
- {t("mobile_number")} -
-
- {resultItemData.mobile_number} -
-
-
-
- Repeat? -
-
- {resultItemData.is_repeat ? t("yes") : t("no")} -
-
-
-
- {t("patient_status")} -
-
- {resultItemData.patient_status} -
-
-
-
- {t("sample_type")} -
-
- {resultItemData.sample_type} -
-
-
-
- {t("test_type")} -
-
- {resultItemData.test_type} -
-
-
-
- {t("sample_collection_date")} -
-
- {resultItemData.sample_collection_date || "-"} -
-
-
-
- {t("result_date")} -
-
- {resultItemData.result_date || "-"} -
-
-
-
- {t("result")} -
-
- {resultItemData.result} -
-
-
-
- {t("source")} -
-
- {resultItemData.source} -
-
- -
-
- {t("patient_category")} -
-
- {resultItemData.patient_category} -
-
-
-
-
-
-
- ); -} diff --git a/src/Components/ExternalResult/ResultList.tsx b/src/Components/ExternalResult/ResultList.tsx deleted file mode 100644 index 74c4655104d..00000000000 --- a/src/Components/ExternalResult/ResultList.tsx +++ /dev/null @@ -1,369 +0,0 @@ -import ButtonV2 from "../Common/components/ButtonV2"; -import { navigate } from "raviger"; -import { lazy, useState } from "react"; -import ListFilter from "./ListFilter"; -import FacilitiesSelectDialogue from "./FacilitiesSelectDialogue"; -import { FacilityModel } from "../Facility/models"; -import SearchInput from "../Form/SearchInput"; -import useFilters from "../../Common/hooks/useFilters"; -import CareIcon from "../../CAREUI/icons/CareIcon"; -import ExportMenu from "../Common/Export"; -import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField"; -import CountBlock from "../../CAREUI/display/Count"; -import { AdvancedFilterButton } from "../../CAREUI/interactive/FiltersSlideover"; -import Page from "../Common/components/Page"; -import routes from "../../Redux/api"; -import useQuery from "../../Utils/request/useQuery"; -import { parsePhoneNumber } from "../../Utils/utils"; -import useAuthUser from "../../Common/hooks/useAuthUser"; -import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; -import ExternalResultImportModal from "./ExternalResultImportModal"; -import request from "../../Utils/request/request"; - -const Loading = lazy(() => import("../Common/Loading")); - -export default function ResultList() { - const authUser = useAuthUser(); - const { - qParams, - updateQuery, - Pagination, - FilterBadges, - advancedFilter, - resultsPerPage, - } = useFilters({ - limit: 14, - cacheBlacklist: ["mobile_number", "name"], - }); - const [importModalOpen, setImportModalOpen] = useState(false); - const [showDialog, setShowDialog] = useState(false); - const [selectedFacility, setSelectedFacility] = useState({ - name: "", - }); - const [resultId, setResultId] = useState(-1); - const [dataList, setDataList] = useState({ lsgList: [], wardList: [] }); - - const [phone_number, setPhoneNumber] = useState(""); - const [phoneNumberError, setPhoneNumberError] = useState(""); - - const setPhoneNum = (mobile_number: string) => { - setPhoneNumber(mobile_number); - if (mobile_number.length >= 13) { - setPhoneNumberError(""); - updateQuery({ mobile_number }); - return; - } - - if (mobile_number === "+91" || mobile_number === "") { - setPhoneNumberError(""); - updateQuery({ mobile_number: "" }); - return; - } - - setPhoneNumberError("Enter a valid number"); - }; - const params = { - page: qParams.page || 1, - name: qParams.name || "", - mobile_number: qParams.mobile_number - ? (parsePhoneNumber(qParams.mobile_number) ?? "") - : "", - wards: qParams.wards || undefined, - local_bodies: qParams.local_bodies || undefined, - created_date_before: qParams.created_date_before || undefined, - created_date_after: qParams.created_date_after || undefined, - result_date_before: qParams.result_date_before || undefined, - result_date_after: qParams.result_date_after || undefined, - sample_collection_date_after: - qParams.sample_collection_date_after || undefined, - sample_collection_date_before: - qParams.sample_collection_date_before || undefined, - offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, - srf_id: qParams.srf_id || undefined, - }; - - const { data, loading } = useQuery(routes.externalResultList, { - query: params, - }); - - let manageResults: any = null; - - const removeLSGFilter = (paramKey: any, id: any) => { - const updatedLsgList = dataList.lsgList.filter((x: any) => x.id !== id); - const lsgParams = updatedLsgList.map((x: any) => x.id); - const updatedWardList = dataList.wardList.filter( - (x: any) => x.local_body_id !== id, - ); - const wardParams = updatedWardList.map((x: any) => x.id); - updateQuery({ [paramKey]: lsgParams, ["wards"]: wardParams }); - setDataList({ lsgList: updatedLsgList, wardList: updatedWardList }); - }; - - const removeWardFilter = (paramKey: any, id: any) => { - const updatedList = dataList.wardList.filter((x: any) => x.id !== id); - const params = updatedList.map((x: any) => x.id); - updateQuery({ [paramKey]: params }); - setDataList({ ...dataList, wardList: updatedList }); - }; - - const lsgWardData = (lsgs: any, wards: any) => - setDataList({ lsgList: lsgs, wardList: wards }); - - const lsgWardBadge = (key: string, value: any, paramKey: string) => { - return ( - value && ( - - {`${key}: ${value.name}`} - - paramKey === "local_bodies" - ? removeLSGFilter(paramKey, value.id) - : paramKey === "wards" - ? removeWardFilter(paramKey, value.id) - : null - } - /> - - ) - ); - }; - - let resultList: any[] = []; - if (data?.results.length) { - resultList = data.results.map((result: any) => { - const resultUrl = `/external_results/${result.id}`; - return ( - - navigate(resultUrl)} - className="text-md whitespace-nowrap px-6 py-4 leading-5 text-secondary-900" - > - - - - - {result.test_type} - - - - - {result.result} - - {result.patient_created ? ( - - Patient Created - - ) : null} - - - {result.result_date || "-"} - - - { - setShowDialog(true); - setResultId(result.id); - }} - > - CREATE - - - - ); - }); - } - - if (loading || !data) { - manageResults = ( - - - - - - ); - } else if (data?.results.length) { - manageResults = <>{resultList}; - } else if (data?.results.length === 0) { - manageResults = ( - - -
-
- No Results Found -
-
- - - ); - } - - return ( -
- setSelectedFacility(e)} - selectedFacility={selectedFacility} - handleOk={() => - navigate(`facility/${selectedFacility.id}/patient`, { - query: { extId: resultId }, - }) - } - handleCancel={() => setShowDialog(false)} - /> - - , - onClick: () => setImportModalOpen(true), - }, - }, - ] - : []), - { - label: "Export Results", - action: async () => { - const { data } = await request(routes.externalResultList, { - query: { ...qParams, csv: true }, - }); - return data ?? null; - }, - filePrefix: "external_results", - options: { - icon: , - }, - }, - ]} - /> - } - > - {importModalOpen && ( - setImportModalOpen(false)} - /> - )} -
- -
- updateQuery({ [e.name]: e.value })} - value={qParams.name} - placeholder="Search by name" - /> -
- setPhoneNum(e.value)} - error={phoneNumberError} - placeholder="Search by Phone Number" - types={["mobile", "landline"]} - /> -
-
-
- advancedFilter.setShow(true)} - /> -
-
- -
- {qParams.local_bodies && - dataList.lsgList.map((x) => lsgWardBadge("LSG", x, "local_bodies"))} - {qParams.wards && - dataList.wardList.map((x) => lsgWardBadge("Ward", x, "wards"))} -
- - [ - badge("Name", "name"), - phoneNumber("Phone no.", "mobile_number"), - ...dateRange("Created", "created_date"), - ...dateRange("Result", "result_date"), - ...dateRange("Sample created", "sample_collection_date"), - badge("SRF ID", "srf_id"), - ]} - /> - -
- - - - - - - - - - - - {manageResults} - -
- Name - - Test Type - - Status - - Result Date - - Create Patient -
-
- - -
-
- ); -} diff --git a/src/Components/ExternalResult/ResultUpdate.tsx b/src/Components/ExternalResult/ResultUpdate.tsx deleted file mode 100644 index 3e892940ac8..00000000000 --- a/src/Components/ExternalResult/ResultUpdate.tsx +++ /dev/null @@ -1,307 +0,0 @@ -import { useCallback, useState, useReducer, lazy } from "react"; -import * as Notification from "../../Utils/Notifications.js"; -import TextAreaFormField from "../Form/FormFields/TextAreaFormField.js"; -import CircularProgress from "../Common/components/CircularProgress.js"; -import { SelectFormField } from "../Form/FormFields/SelectFormField.js"; -import RadioFormField from "../Form/FormFields/RadioFormField.js"; -import { navigate } from "raviger"; -import { Cancel, Submit } from "../Common/components/ButtonV2"; -import useAppHistory from "../../Common/hooks/useAppHistory"; -import Page from "../Common/components/Page.js"; -import useQuery from "../../Utils/request/useQuery.js"; -import routes from "../../Redux/api.js"; -import request from "../../Utils/request/request.js"; -import { compareBy } from "../../Utils/utils.js"; -import { useTranslation } from "react-i18next"; - -const Loading = lazy(() => import("../Common/Loading")); - -const initForm = { - address: "", - local_body: "", - ward: "", - patient_created: "false", -}; - -const initError = Object.assign( - {}, - ...Object.keys(initForm).map((k) => ({ [k]: "" })), -); - -const initialState = { - form: { ...initForm }, - errors: { ...initError }, -}; - -const FormReducer = (state = initialState, action: any) => { - switch (action.type) { - case "set_form": { - return { - ...state, - form: action.form, - }; - } - case "set_error": { - return { - ...state, - errors: action.errors, - }; - } - default: - return state; - } -}; - -const initialLocalbodies = [{ id: 0, name: "Choose Localbody", number: 0 }]; -const initialWard = [{ id: 0, name: "Choose Ward", number: 0 }]; - -export default function UpdateResult(props: any) { - const { id } = props; - const { goBack } = useAppHistory(); - const { t } = useTranslation(); - - const [state, dispatch] = useReducer(FormReducer, initialState); - const [isLoading, setIsLoading] = useState(true); - const [isLocalbodyLoading, setIsLocalbodyLoading] = useState(false); - const [isWardLoading, setIsWardLoading] = useState(false); - const [localBody, setLocalBody] = useState(initialLocalbodies); - const [ward, setWard] = useState(initialLocalbodies); - - const { loading } = useQuery(routes.externalResult, { - pathParams: { id }, - onResponse: async ({ res, data }) => { - if (res && data) { - const form = { ...state.form }; - form["name"] = data.name; - form["age"] = data.age; - form["age_in"] = data.age_in; - form["srf_id"] = data.srf_id; - form["address"] = data.address; - form["district"] = data.district_object.name; - form["local_body"] = String(data.local_body); - form["ward"] = String(data.ward); - form["patient_created"] = String(data.patient_created); - - dispatch({ type: "set_form", form }); - - Promise.all([ - fetchLocalBody(data.district), - fetchWards(data.local_body), - ]); - setIsLoading(false); - } - }, - }); - - const fetchLocalBody = async (id: number) => { - if (Number(id) > 0) { - setIsLocalbodyLoading(true); - const { res, data } = await request(routes.getLocalbodyByDistrict, { - pathParams: { id: String(id) }, - }); - if (res && data) { - setIsLocalbodyLoading(false); - setLocalBody([...initialLocalbodies, ...data]); - } - } else { - setLocalBody(initialLocalbodies); - } - }; - - const fetchWards = useCallback( - async (id: number) => { - if (Number(id) > 0) { - setIsWardLoading(true); - const { res, data } = await request(routes.getWardByLocalBody, { - pathParams: { id: String(id) }, - }); - if (res && data) { - setWard([...initialWard, ...data.results]); - } - setIsWardLoading(false); - } else { - setWard(initialLocalbodies); - } - }, - [props.id], - ); - - const validateForm = () => { - const errors = { ...initError }; - let invalidForm = false; - - Object.keys(state.form).forEach((field) => { - switch (field) { - case "address": - if (!state.form[field]) { - errors[field] = t("field_required"); - invalidForm = true; - } - return; - case "local_body": - if (!state.form[field] || state.form[field] === "0") { - errors[field] = "Please select local body"; - invalidForm = true; - } - return; - case "ward": - if (!state.form[field] || state.form[field] === "0") { - errors[field] = "Please select ward"; - invalidForm = true; - } - return; - case "patient_created": - if (state.form[field] !== "true" && state.form[field] !== "false") { - errors[field] = "Please select an option if the patient is created"; - invalidForm = true; - } - return; - default: - return; - } - }); - - if (invalidForm) { - dispatch({ type: "set_error", errors }); - return false; - } - dispatch({ type: "set_error", errors }); - return true; - }; - - const handleChange = (e: any) => { - const form = { ...state.form }; - form[e.name] = e.value; - if (e.name === "local_body") { - form["ward"] = "0"; - } - dispatch({ type: "set_form", form }); - }; - - const handleSubmit = async (e: any) => { - e.preventDefault(); - const validForm = validateForm(); - if (validForm) { - setIsLoading(true); - const rdata = { - address: state.form.address ? state.form.address : undefined, - local_body: state.form.local_body ? state.form.local_body : undefined, - ward: state.form.ward, - patient_created: state.form.patient_created === "true", - }; - - const { res, data } = await request(routes.partialUpdateExternalResult, { - pathParams: { id }, - body: rdata, - }); - - setIsLoading(false); - if (res && data) { - dispatch({ type: "set_form", form: initForm }); - Notification.Success({ - msg: "External Result updated successfully", - }); - navigate(`/external_results/${id}`); - } - } - }; - - if (isLoading || loading) { - return ; - } - - return ( -
- -
-
-

- {state.form.name} - {state.form.age} {state.form.age_in} -

-

- SRF ID: {state.form.srf_id} -

-

- Care external results ID: {id} -

-
-
handleSubmit(e)}> -
-
- -
-
- {isLocalbodyLoading ? ( - - ) : ( - localBody.name} - optionValue={(localBody) => localBody.id} - onChange={(e) => [handleChange(e), fetchWards(e.value)]} - error={state.errors.local_body} - /> - )} -
-
- {isWardLoading ? ( - - ) : ( - { - return { id: e.id, name: e.number + ": " + e.name }; - })} - value={state.form.ward} - optionLabel={(ward) => ward.name} - optionValue={(ward) => ward.id} - onChange={handleChange} - error={state.errors.ward} - /> - )} -
-
- option.label} - optionValue={(option) => option.value} - error={state.errors.patient_created} - /> -
-
-
- goBack()} /> - -
-
-
-
-
- ); -} diff --git a/src/Components/ExternalResult/models.ts b/src/Components/ExternalResult/models.ts index bc143593019..bc5f8d29e03 100644 --- a/src/Components/ExternalResult/models.ts +++ b/src/Components/ExternalResult/models.ts @@ -1,48 +1,3 @@ -export interface IExternalResultUploadCsv { - sample_tests: any[]; -} - -export interface IExternalResult { - id: number; - name: string; - age: number; - age_in: string; - test_type: string; - result: string; - result_date: string; - patient_created: boolean; - gender: string; - source: string; - is_repeat: boolean; - mobile_number: string; - patient_status: string; - sample_type: string; - sample_collection_date: string; - patient_category: string; - srf_id: string; - permanent_address: string; - test_id: string; - village: string; - district_object: { - id: number; - name: string; - state: number; - }; - district: number; - ward: number; - local_body: number; - address: string; - ward_object: { - id: number; - number: number; - name: string; - }; - local_body_object: { - id: number; - name: string; - }; -} - export interface ILocalBodies { id: number; name: string; @@ -52,27 +7,12 @@ export interface ILocalBodies { localbody_code: string; district: number; } - -export interface IDeleteExternalResult { - detail: string; -} export interface IDeleteBedCapacity { detail: string; } -export interface IPartialUpdateExternalResult { - address: string; - ward: number; - local_body: number; - patient_created: boolean; -} - export interface ILocalBodyByDistrict { id: number; name: string; state: number; } - -export interface IExternalResultCsv { - sample_tests: Partial[]; -} diff --git a/src/Locale/en.json b/src/Locale/en.json index cdb23765786..94b9168e564 100644 --- a/src/Locale/en.json +++ b/src/Locale/en.json @@ -399,7 +399,6 @@ "Sample Test": "Sample Test", "Shifting": "Shifting", "Resource": "Resource", - "External Results": "External Results", "Users": "Users", "Profile": "Profile", "Dashboard": "Dashboard", @@ -415,7 +414,6 @@ "session_expired_msg": "It appears that your session has expired. This could be due to inactivity. Please login again to continue.", "invalid_reset": "Invalid Reset", "please_upload_a_csv_file": "Please Upload A CSV file", - "upload_external_results": "Upload External Results", "csv_file_in_the_specified_format": "Select a CSV file in the specified format", "sample_format": "Sample Format", "search_for_facility": "Search for Facility", @@ -435,7 +433,6 @@ "patient_status": "Patient Status", "mobile_number": "Mobile Number", "patient_created": "Patient Created", - "care_external_results_id": "Care external results ID", "update_record": "Update Record", "facility_search_placeholder": "Search by Facility / District Name", "advanced_filters": "Advanced Filters", diff --git a/src/Locale/hi.json b/src/Locale/hi.json index 689b6e257c3..3e967c35cb4 100644 --- a/src/Locale/hi.json +++ b/src/Locale/hi.json @@ -364,7 +364,6 @@ "Sample Test": "नमूना परीक्षण", "Shifting": "स्थानांतरण", "Resource": "संसाधन", - "External Results": "बाह्य परिणाम", "Users": "उपयोगकर्ताओं", "Profile": "प्रोफ़ाइल", "Dashboard": "डैशबोर्ड", @@ -380,7 +379,6 @@ "session_expired_msg": "ऐसा लगता है कि आपका सत्र समाप्त हो गया है। यह निष्क्रियता के कारण हो सकता है। कृपया जारी रखने के लिए फिर से लॉगिन करें।", "invalid_reset": "अमान्य रीसेट", "please_upload_a_csv_file": "कृपया एक CSV फ़ाइल अपलोड करें", - "upload_external_results": "बाहरी परिणाम अपलोड करें", "csv_file_in_the_specified_format": "निर्दिष्ट प्रारूप में CSV फ़ाइल चुनें", "sample_format": "नमूना प्रारूप", "search_for_facility": "सुविधा खोजें", @@ -400,7 +398,6 @@ "patient_status": "रोगी की स्थिति", "mobile_number": "मोबाइल नंबर", "patient_created": "रोगी बनाया गया", - "care_external_results_id": "देखभाल बाह्य परिणाम आईडी", "update_record": "रिकॉर्ड अपडेट करें", "facility_search_placeholder": "सुविधा / जिला नाम से खोजें", "advanced_filters": "उन्नत फ़िल्टर", @@ -812,4 +809,4 @@ "search_by_username": "उपयोगकर्ता नाम से खोजें", "last_online": "अंतिम ऑनलाइन", "total_users": "कुल उपयोगकर्ता" -} \ No newline at end of file +} diff --git a/src/Locale/kn.json b/src/Locale/kn.json index 4f23611bd9f..6d440ae951b 100644 --- a/src/Locale/kn.json +++ b/src/Locale/kn.json @@ -380,7 +380,6 @@ "session_expired_msg": "ನಿಮ್ಮ ಅವಧಿ ಮುಗಿದಿದೆ ಎಂದು ತೋರುತ್ತಿದೆ. ಇದು ನಿಷ್ಕ್ರಿಯತೆಯ ಕಾರಣದಿಂದಾಗಿರಬಹುದು. ಮುಂದುವರಿಸಲು ದಯವಿಟ್ಟು ಮತ್ತೆ ಲಾಗಿನ್ ಮಾಡಿ.", "invalid_reset": "ಅಮಾನ್ಯ ಮರುಹೊಂದಿಸಿ", "please_upload_a_csv_file": "ದಯವಿಟ್ಟು CSV ಫೈಲ್ ಅನ್ನು ಅಪ್‌ಲೋಡ್ ಮಾಡಿ", - "upload_external_results": "ಬಾಹ್ಯ ಫಲಿತಾಂಶಗಳನ್ನು ಅಪ್ಲೋಡ್ ಮಾಡಿ", "csv_file_in_the_specified_format": "ನಿರ್ದಿಷ್ಟಪಡಿಸಿದ ಸ್ವರೂಪದಲ್ಲಿ CSV ಫೈಲ್ ಅನ್ನು ಆಯ್ಕೆಮಾಡಿ", "sample_format": "ಮಾದರಿ ಸ್ವರೂಪ", "search_for_facility": "ಸೌಲಭ್ಯಕ್ಕಾಗಿ ಹುಡುಕಿ", @@ -400,7 +399,6 @@ "patient_status": "ರೋಗಿಯ ಸ್ಥಿತಿ", "mobile_number": "ಮೊಬೈಲ್ ಸಂಖ್ಯೆ", "patient_created": "ರೋಗಿಯನ್ನು ರಚಿಸಲಾಗಿದೆ", - "care_external_results_id": "ಬಾಹ್ಯ ಫಲಿತಾಂಶಗಳ ಐಡಿಯನ್ನು ನೋಡಿಕೊಳ್ಳಿ", "update_record": "ದಾಖಲೆಯನ್ನು ನವೀಕರಿಸಿ", "facility_search_placeholder": "ಸೌಲಭ್ಯ / ಜಿಲ್ಲೆಯ ಹೆಸರಿನ ಮೂಲಕ ಹುಡುಕಿ", "advanced_filters": "ಸುಧಾರಿತ ಫಿಲ್ಟರ್‌ಗಳು", @@ -812,4 +810,4 @@ "search_by_username": "ಬಳಕೆದಾರ ಹೆಸರಿನ ಮೂಲಕ ಹುಡುಕಿ", "last_online": "ಕೊನೆಯ ಆನ್‌ಲೈನ್", "total_users": "ಒಟ್ಟು ಬಳಕೆದಾರರು" -} \ No newline at end of file +} diff --git a/src/Locale/ml.json b/src/Locale/ml.json index af9e7160d47..1de33212062 100644 --- a/src/Locale/ml.json +++ b/src/Locale/ml.json @@ -380,7 +380,6 @@ "session_expired_msg": "നിങ്ങളുടെ സെഷൻ കാലഹരണപ്പെട്ടതായി തോന്നുന്നു. ഇത് നിഷ്ക്രിയത്വം മൂലമാകാം. തുടരാൻ വീണ്ടും ലോഗിൻ ചെയ്യുക.", "invalid_reset": "അസാധുവായ റീസെറ്റ്", "please_upload_a_csv_file": "ദയവായി ഒരു CSV ഫയൽ അപ്‌ലോഡ് ചെയ്യുക", - "upload_external_results": "ബാഹ്യ ഫലങ്ങൾ അപ്‌ലോഡ് ചെയ്യുക", "csv_file_in_the_specified_format": "നിർദ്ദിഷ്ട ഫോർമാറ്റിൽ ഒരു CSV ഫയൽ തിരഞ്ഞെടുക്കുക", "sample_format": "സാമ്പിൾ ഫോർമാറ്റ്", "search_for_facility": "സൗകര്യത്തിനായി തിരയുക", @@ -400,7 +399,6 @@ "patient_status": "രോഗിയുടെ അവസ്ഥ", "mobile_number": "മൊബൈൽ നമ്പർ", "patient_created": "രോഗിയെ സൃഷ്ടിച്ചു", - "care_external_results_id": "ബാഹ്യ ഫലങ്ങളുടെ ഐഡി പരിപാലിക്കുക", "update_record": "റെക്കോർഡ് അപ്ഡേറ്റ് ചെയ്യുക", "facility_search_placeholder": "ഫെസിലിറ്റി / ജില്ല പ്രകാരം തിരയുക", "advanced_filters": "വിപുലമായ ഫിൽട്ടറുകൾ", @@ -812,4 +810,4 @@ "search_by_username": "ഉപയോക്തൃനാമം ഉപയോഗിച്ച് തിരയുക", "last_online": "അവസാനമായി ഓൺലൈൻ", "total_users": "മൊത്തം ഉപയോക്താക്കൾ" -} \ No newline at end of file +} diff --git a/src/Locale/ta.json b/src/Locale/ta.json index 6ba7b30cf61..03decb02818 100644 --- a/src/Locale/ta.json +++ b/src/Locale/ta.json @@ -380,7 +380,6 @@ "session_expired_msg": "உங்கள் அமர்வு காலாவதியானது போல் தெரிகிறது. இது செயலற்ற தன்மை காரணமாக இருக்கலாம். தொடர மீண்டும் உள்நுழையவும்.", "invalid_reset": "தவறான மீட்டமைப்பு", "please_upload_a_csv_file": "CSV கோப்பைப் பதிவேற்றவும்", - "upload_external_results": "வெளிப்புற முடிவுகளைப் பதிவேற்றவும்", "csv_file_in_the_specified_format": "குறிப்பிட்ட வடிவத்தில் CSV கோப்பைத் தேர்ந்தெடுக்கவும்", "sample_format": "மாதிரி வடிவம்", "search_for_facility": "வசதியைத் தேடுங்கள்", @@ -400,7 +399,6 @@ "patient_status": "நோயாளியின் நிலை", "mobile_number": "மொபைல் எண்", "patient_created": "நோயாளி உருவாக்கப்பட்டது", - "care_external_results_id": "கேர் வெளிப்புற முடிவுகள் ஐடி", "update_record": "பதிவைப் புதுப்பிக்கவும்", "facility_search_placeholder": "வசதி / மாவட்ட பெயர் மூலம் தேடுங்கள்", "advanced_filters": "மேம்பட்ட வடிப்பான்கள்", @@ -812,4 +810,4 @@ "search_by_username": "பயனர்பெயர் மூலம் தேடவும்", "last_online": "கடைசியாக ஆன்லைன்", "total_users": "மொத்த பயனர்கள்" -} \ No newline at end of file +} diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index a0c3271386d..4775674084e 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -72,12 +72,8 @@ import { import { IComment, IResource } from "../Components/Resource/models"; import { IDeleteBedCapacity, - IDeleteExternalResult, - IExternalResult, - IExternalResultCsv, ILocalBodies, ILocalBodyByDistrict, - IPartialUpdateExternalResult, } from "../Components/ExternalResult/models"; import { InvestigationGroup, @@ -846,42 +842,6 @@ const routes = { TRes: Type(), }, - // External Results - externalResultList: { - path: "/api/v1/external_result/", - method: "GET", - TRes: Type>(), - }, - externalResult: { - path: "/api/v1/external_result/{id}/", - method: "GET", - TRes: Type(), - }, - externalResultUploadCsv: { - path: "/api/v1/external_result/bulk_upsert/", - method: "POST", - TBody: Type(), - TRes: Type(), - }, - - deleteExternalResult: { - path: "/api/v1/external_result/{id}/", - method: "DELETE", - TRes: Type(), - }, - - updateExternalResult: { - path: "/api/v1/external_result/{id}/", - method: "PUT", - }, - - partialUpdateExternalResult: { - path: "/api/v1/external_result/{id}/", - method: "PATCH", - TRes: Type(), - TBody: Type(), - }, - // States statesList: { path: "/api/v1/state/", diff --git a/src/Routers/AppRouter.tsx b/src/Routers/AppRouter.tsx index 4240eff221e..87bd3b71d8a 100644 --- a/src/Routers/AppRouter.tsx +++ b/src/Routers/AppRouter.tsx @@ -24,9 +24,7 @@ import HCXRoutes from "./routes/HCXRoutes"; import ShiftingRoutes from "./routes/ShiftingRoutes"; import AssetRoutes from "./routes/AssetRoutes"; import ResourceRoutes from "./routes/ResourceRoutes"; -import ExternalResultRoutes from "./routes/ExternalResultRoutes"; import { DetailRoute } from "./types"; -import useAuthUser from "../Common/hooks/useAuthUser"; import careConfig from "@careConfig"; import IconIndex from "../CAREUI/icons/Index"; @@ -63,22 +61,12 @@ const Routes = { }; export default function AppRouter() { - const authUser = useAuthUser(); - let routes = Routes; if (careConfig.hcx.enabled) { routes = { ...HCXRoutes, ...routes }; } - if ( - !["Nurse", "NurseReadOnly", "Staff", "StaffReadOnly"].includes( - authUser.user_type, - ) - ) { - routes = { ...routes, ...ExternalResultRoutes }; - } - useRedirect("/user", "/users"); const pages = useRoutes(routes) || ; const path = usePath(); diff --git a/src/Routers/routes/ExternalResultRoutes.tsx b/src/Routers/routes/ExternalResultRoutes.tsx deleted file mode 100644 index b6bc71a2808..00000000000 --- a/src/Routers/routes/ExternalResultRoutes.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import ResultItem from "../../Components/ExternalResult/ResultItem"; -import ResultList from "../../Components/ExternalResult/ResultList"; -import ResultUpdate from "../../Components/ExternalResult/ResultUpdate"; -import { DetailRoute } from "../types"; - -export default { - "/external_results": () => , - "/external_results/:id": ({ id }: DetailRoute) => , - "/external_results/:id/update": ({ id }: DetailRoute) => ( - - ), -};