Skip to content

Commit

Permalink
Migrate useDispatch with useQuery/request in `src/Components/Comm…
Browse files Browse the repository at this point in the history
…on/**` (#6889)

* Migrate to `useQuery` in `AssetSelect`

* Migrate `useQuery` in `BedSelect`

* Migrate `useQuery` in `DistrictAutocompleteFormField`

* Migrate `useQuery` in `StateAutocompleteFormField`

* Migrate `useQuery` in `LocalBodyAutocompleteFormField`

* Migrate `useQuery` in `FacilitySelect`

* Migrate `useQuery` in `LocationSelect`

* Migrate `useQuery` in `SkillSelect`

* Migrate `useQuery` in `InvestigationBuilder`

* Migrate `useQuery` in `Uptime` (Asset)

* fix location select not working for single select

* uptime: fix issue with reverse
rithviknishad authored Jan 10, 2024
1 parent cc38860 commit 197cb39
Showing 18 changed files with 156 additions and 309 deletions.
28 changes: 7 additions & 21 deletions src/Components/Common/AssetSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from "react";
import { useDispatch } from "react-redux";
import { listAssets } from "../../Redux/actions";
import AutoCompleteAsync from "../Form/AutoCompleteAsync";
import routes from "../../Redux/api";
import request from "../../Utils/request/request";

interface AssetSelectProps {
name: string;
@@ -16,7 +16,6 @@ interface AssetSelectProps {
asset_class?: string;
showAll?: boolean;
showNOptions?: number;
freeText?: boolean;
selected: any;
setSelected: (selected: any) => void;
}
@@ -33,21 +32,13 @@ export const AssetSelect = (props: AssetSelectProps) => {
is_permanent = null,
showNOptions = 10,
className = "",
freeText = false,
errors = "",
asset_class = "",
} = props;

const dispatchAction: any = useDispatch();

const AssetSearch = useCallback(
async (text: string) => {
const params: Partial<AssetSelectProps> & {
limit: number;
offset: number;
search_text: string;
asset_class: string;
} = {
const query = {
limit: 50,
offset: 0,
search_text: text,
@@ -56,17 +47,12 @@ export const AssetSelect = (props: AssetSelectProps) => {
in_use_by_consultation,
is_permanent,
asset_class,
};
} as const;

const res = await dispatchAction(listAssets(params));
if (freeText)
res?.data?.results?.push({
id: -1,
name: text,
});
return res?.data?.results;
const { data } = await request(routes.listAssets, { query });
return data?.results;
},
[dispatchAction]
[asset_class, facility, in_use_by_consultation, is_permanent, is_working]
);

return (
24 changes: 11 additions & 13 deletions src/Components/Common/BedSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useCallback } from "react";
import { useDispatch } from "react-redux";
import { listFacilityBeds } from "../../Redux/actions";
import { BedModel } from "../Facility/models";
import AutoCompleteAsync from "../Form/AutoCompleteAsync";
import { useTranslation } from "react-i18next";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";

interface BedSelectProps {
name: string;
@@ -34,13 +34,11 @@ export const BedSelect = (props: BedSelectProps) => {
location,
showNOptions = 20,
} = props;

const dispatchAction: any = useDispatch();
const { t } = useTranslation();

const onBedSearch = useCallback(
async (text: string) => {
const params = {
const query = {
limit: 50,
offset: 0,
search_text: text,
@@ -49,17 +47,17 @@ export const BedSelect = (props: BedSelectProps) => {
location,
};

const res = await dispatchAction(listFacilityBeds(params));
if (res && res.data) {
let beds = res.data.results;
if (unoccupiedOnly) {
beds = beds.filter((bed: BedModel) => bed?.is_occupied === false);
}
const { data } = await request(routes.listFacilityBeds, { query });

return beds;
if (unoccupiedOnly) {
return data?.results?.filter(
(bed: BedModel) => bed?.is_occupied === false
);
}

return data?.results;
},
[dispatchAction, facility, location, searchAll, unoccupiedOnly]
[facility, location, searchAll, unoccupiedOnly]
);

return (
46 changes: 11 additions & 35 deletions src/Components/Common/DistrictAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,27 @@
import { useDispatch } from "react-redux";
import { FormFieldBaseProps } from "../Form/FormFields/Utils";
import { IState } from "./StateAutocompleteFormField";
import AutocompleteFormField from "../Form/FormFields/Autocomplete";
import { statusType, useAbortableEffect } from "../../Common/utils";
import { useCallback, useState } from "react";
import { getDistrictByState } from "../../Redux/actions";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
import { DistrictModel, StateModel } from "../Facility/models";

export type IDistrict = {
id: number;
name: string;
};

type Props = FormFieldBaseProps<IDistrict["id"]> & {
type Props = FormFieldBaseProps<DistrictModel["id"]> & {
placeholder?: string;
state?: IState["id"];
state?: StateModel["id"];
};

export default function DistrictAutocompleteFormField(props: Props) {
const dispatch = useDispatch<any>();
const [districts, setDistricts] = useState<IDistrict[]>();

const fetchDistricts = useCallback(
async (status: any) => {
setDistricts(undefined);
if (!props.state) {
return;
}
const res = await dispatch(getDistrictByState({ id: props.state }));
if (!status.aborted && res.data) {
setDistricts(res.data);
}
},
[dispatch, props.state]
);

useAbortableEffect(
(status: statusType) => fetchDistricts(status),
[props.state]
);
const { data, loading } = useQuery(routes.getDistrictByState, {
pathParams: { id: props.state?.toString() ?? "" },
prefetch: props.state !== undefined,
});

return (
<AutocompleteFormField
{...props}
options={districts ?? []}
options={data ?? []}
optionLabel={(option) => option.name}
optionValue={(option) => option.id}
isLoading={!!(props.state && districts === undefined)}
isLoading={loading}
disabled={!props.state}
/>
);
20 changes: 10 additions & 10 deletions src/Components/Common/FacilitySelect.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback } from "react";
import { useDispatch } from "react-redux";
import { getAllFacilities, getPermittedFacilities } from "../../Redux/actions";
import AutoCompleteAsync from "../Form/AutoCompleteAsync";
import { FacilityModel } from "../Facility/models";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";

interface FacilitySelectProps {
name: string;
@@ -37,11 +37,9 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
errors = "",
} = props;

const dispatchAction: any = useDispatch();

const facilitySearch = useCallback(
async (text: string) => {
const params = {
const query = {
limit: 50,
offset: 0,
search_text: text,
@@ -51,17 +49,19 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
district,
};

const res = await dispatchAction(
showAll ? getAllFacilities(params) : getPermittedFacilities(params)
const { data } = await request(
showAll ? routes.getAllFacilities : routes.getPermittedFacilities,
{ query }
);

if (freeText)
res?.data?.results?.push({
data?.results?.push({
id: -1,
name: text,
});
return res?.data?.results;
return data?.results;
},
[dispatchAction, searchAll, showAll, facilityType, district]
[searchAll, showAll, facilityType, district, exclude_user, freeText]
);

return (
48 changes: 11 additions & 37 deletions src/Components/Common/LocalBodyAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,27 @@
import { useDispatch } from "react-redux";
import { FormFieldBaseProps } from "../Form/FormFields/Utils";
import AutocompleteFormField from "../Form/FormFields/Autocomplete";
import { statusType, useAbortableEffect } from "../../Common/utils";
import { useCallback, useState } from "react";
import { getLocalbodyByDistrict } from "../../Redux/actions";
import { IDistrict } from "./DistrictAutocompleteFormField";
import { DistrictModel, LocalBodyModel } from "../Facility/models";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";

export type ILocalBody = {
id: number;
name: string;
};

type Props = FormFieldBaseProps<ILocalBody["id"]> & {
type Props = FormFieldBaseProps<LocalBodyModel["id"]> & {
placeholder?: string;
district?: IDistrict["id"];
district?: DistrictModel["id"];
};

export default function LocalBodyAutocompleteFormField(props: Props) {
const dispatch = useDispatch<any>();
const [localBodies, setLocalBodies] = useState<ILocalBody[]>();

const fetchLocalBodies = useCallback(
async (status: any) => {
setLocalBodies(undefined);
if (!props.district) {
return;
}
const res = await dispatch(
getLocalbodyByDistrict({ id: props.district })
);
if (!status.aborted && res && res.data) {
setLocalBodies(res.data);
}
},
[dispatch, props.district]
);

useAbortableEffect(
(status: statusType) => fetchLocalBodies(status),
[props.district]
);
const { data, loading } = useQuery(routes.getLocalbodyByDistrict, {
pathParams: { id: props.district?.toString() ?? "" },
prefetch: props.district !== undefined,
});

return (
<AutocompleteFormField
{...props}
options={localBodies ?? []}
options={data ?? []}
optionLabel={(option) => option.name}
optionValue={(option) => option.id}
isLoading={!!(props.district && localBodies === undefined)}
isLoading={loading}
disabled={!props.district}
/>
);
89 changes: 30 additions & 59 deletions src/Components/Common/LocationSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import { listFacilityAssetLocation } from "../../Redux/actions";
import AutocompleteFormField from "../Form/FormFields/Autocomplete";
import AutocompleteMultiSelectFormField from "../Form/FormFields/AutocompleteMultiselect";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
interface LocationSelectProps {
name: string;
disabled?: boolean;
@@ -11,84 +10,56 @@ interface LocationSelectProps {
className?: string;
searchAll?: boolean;
multiple?: boolean;
facilityId: number | string;
facilityId: string;
showAll?: boolean;
selected: string | string[] | null;
setSelected: (selected: string | string[] | null) => void;
errorClassName?: string;
}

export const LocationSelect = (props: LocationSelectProps) => {
const {
name,
multiple,
selected,
setSelected,
errors,
className = "",
facilityId,
disabled = false,
} = props;
const [locations, setLocations] = useState<{ name: string; id: string }[]>(
[]
const { data, loading, refetch } = useQuery(
routes.listFacilityAssetLocation,
{
query: {
limit: 14,
},
pathParams: {
facility_external_id: props.facilityId,
},
prefetch: props.facilityId !== undefined,
}
);
const [query, setQuery] = useState<string>("");
const [loading, setLoading] = useState<boolean>(false);
const dispatchAction: any = useDispatch();

const handleValueChange = (current: string[]) => {
if (multiple) setSelected(current);
else setSelected(current ? current[0] : "");
};

useEffect(() => {
if (!facilityId) return;
const params = {
limit: 14,
search_text: query,
};
setLoading(true);
dispatchAction(
listFacilityAssetLocation(params, { facility_external_id: facilityId })
).then(({ data }: any) => {
setLocations(data.results);
setLoading(false);
});
}, [query, facilityId]);

return props.multiple ? (
<AutocompleteMultiSelectFormField
name={name}
disabled={disabled}
value={selected as unknown as string[]}
options={locations}
onChange={({ value }) => handleValueChange(value as unknown as string[])}
onQuery={(query) => {
setQuery(query);
}}
name={props.name}
disabled={props.disabled}
value={props.selected as unknown as string[]}
options={data?.results ?? []}
onChange={({ value }) => props.setSelected(value)}
onQuery={(search_text) => refetch({ query: { search_text } })}
placeholder="Search by location name"
optionLabel={(option) => option.name}
optionValue={(option) => option.id}
error={errors}
className={className}
error={props.errors}
className={props.className}
errorClassName={props.errorClassName}
/>
) : (
<AutocompleteFormField
name={name}
disabled={disabled}
value={selected as string}
options={locations}
onChange={({ value }) => handleValueChange([value])}
onQuery={(query) => {
setQuery(query);
}}
name={props.name}
disabled={props.disabled}
value={props.selected as string}
options={data?.results ?? []}
onChange={({ value }) => props.setSelected(value)}
onQuery={(search_text) => refetch({ query: { search_text } })}
isLoading={loading}
placeholder="Search by location name"
optionLabel={(option) => option.name}
optionValue={(option) => option.id}
error={errors}
className={className}
error={props.errors}
className={props.className}
errorClassName={props.errorClassName}
/>
);
25 changes: 7 additions & 18 deletions src/Components/Common/SkillSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback } from "react";
import { useDispatch } from "react-redux";
import { getAllSkills } from "../../Redux/actions";
import AutoCompleteAsync from "../Form/AutoCompleteAsync";
import { SkillModel, SkillObjectModel } from "../Users/models";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";

interface SkillSelectProps {
id?: string;
@@ -11,12 +11,10 @@ interface SkillSelectProps {
className?: string;
searchAll?: boolean;
multiple?: boolean;
showAll?: boolean;
showNOptions?: number;
disabled?: boolean;
selected: SkillObjectModel | SkillObjectModel[] | null;
setSelected: (selected: SkillObjectModel) => void;
username?: string;
userSkills?: SkillModel[];
}

@@ -28,37 +26,28 @@ export const SkillSelect = (props: SkillSelectProps) => {
selected,
setSelected,
searchAll,
showAll = true,
showNOptions = 10,
disabled = false,
className = "",
errors = "",
//username,
userSkills,
} = props;

const dispatchAction: any = useDispatch();

const skillSearch = useCallback(
async (text: string) => {
const params = {
const query = {
limit: 50,
offset: 0,
search_text: text,
all: searchAll,
};

const res = await dispatchAction(getAllSkills(params));
const skillsID: string[] = [];
userSkills?.map((skill: SkillModel) =>
skillsID.push(skill.skill_object.id)
);
const skills = res?.data?.results.filter(
(skill: any) => !skillsID.includes(skill.id)
const { data } = await request(routes.getAllSkills, { query });
return data?.results.filter(
(skill) => !userSkills?.some((userSkill) => userSkill.id === skill.id)
);
return skills;
},
[dispatchAction, searchAll, userSkills, showAll]
[searchAll, userSkills]
);

return (
36 changes: 7 additions & 29 deletions src/Components/Common/StateAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,23 @@
import { useCallback, useState } from "react";
import AutocompleteFormField from "../Form/FormFields/Autocomplete";
import { FormFieldBaseProps } from "../Form/FormFields/Utils";
import { statusType, useAbortableEffect } from "../../Common/utils";
import { useDispatch } from "react-redux";
import { getStates } from "../../Redux/actions";
import { StateModel } from "../Facility/models";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";

export type IState = {
id: number;
name: string;
};

type Props = FormFieldBaseProps<IState["id"]> & {
type Props = FormFieldBaseProps<StateModel["id"]> & {
placeholder?: string;
};

export default function StateAutocompleteFormField(props: Props) {
const dispatch = useDispatch<any>();
const [states, setStates] = useState<IState[]>();

const fetchStates = useCallback(
async (status: any) => {
setStates(undefined);
const res = await dispatch(getStates());
if (!status.aborted && res && res.data) {
setStates(res.data.results);
}
},
[dispatch]
);

useAbortableEffect((status: statusType) => {
fetchStates(status);
}, []);
const { data, loading } = useQuery(routes.statesList);

return (
<AutocompleteFormField
{...props}
options={states ?? []}
options={data?.results ?? []}
optionLabel={(option) => option.name}
optionValue={(option) => option.id}
isLoading={states === undefined}
isLoading={loading}
/>
);
}
42 changes: 10 additions & 32 deletions src/Components/Common/Uptime.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Popover } from "@headlessui/react";
import { useCallback, useEffect, useRef, useState } from "react";
import { listAssetAvailability } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import * as Notification from "../../Utils/Notifications.js";
import { useEffect, useRef, useState } from "react";
import { AssetStatus, AssetUptimeRecord } from "../Assets/AssetTypes";
import { reverse } from "lodash-es";
import { classNames } from "../../Utils/utils";
import dayjs from "../../Utils/dayjs";
import useQuery from "../../Utils/request/useQuery.js";
import routes from "../../Redux/api.js";

const STATUS_COLORS = {
Operational: "bg-green-500",
@@ -63,7 +61,7 @@ function UptimeInfo({
<>
<span className="my-2 block font-bold">Status Updates</span>
<div className="grid grid-cols-1 gap-1 md:grid-cols-4">
{reverse(incidents)?.map((incident, index) => {
{incidents.reverse().map((incident, index) => {
const prevIncident = incidents[index - 1];
let endTimestamp;
let ongoing = false;
@@ -171,16 +169,16 @@ export default function Uptime(props: { assetId: string }) {
const [summary, setSummary] = useState<{
[key: number]: AssetUptimeRecord[];
}>([]);
const [availabilityData, setAvailabilityData] = useState<AssetUptimeRecord[]>(
[]
);
const [loading, setLoading] = useState(true);
const { data, loading } = useQuery(routes.listAssetAvailability, {
query: { external_id: props.assetId },
onResponse: ({ data }) => setUptimeRecord(data?.results.reverse() ?? []),
});
const availabilityData = data?.results ?? [];
const graphElem = useRef<HTMLDivElement>(null);
const [numDays, setNumDays] = useState(
Math.floor((window.innerWidth - 1024) / 20)
);
const [hoveredDay, setHoveredDay] = useState(-1);
const dispatch = useDispatch<any>();

const handleResize = () => {
const containerWidth = graphElem.current?.clientWidth ?? window.innerWidth;
@@ -268,25 +266,6 @@ export default function Uptime(props: { assetId: string }) {
return Math.round((upStatus / (days * 3)) * 100);
}

const fetchData = useCallback(async () => {
setLoading(true);
setLoading(false);

const availabilityData = await dispatch(
listAssetAvailability({
external_id: props.assetId,
})
);
if (availabilityData?.data) {
setAvailabilityData(availabilityData.data.results);
setUptimeRecord(reverse(availabilityData.data.results));
} else {
Notification.Error({
msg: "Error fetching availability history",
});
}
}, [dispatch, props.assetId]);

useEffect(() => {
setTimeout(() => {
handleResize();
@@ -297,8 +276,7 @@ export default function Uptime(props: { assetId: string }) {

useEffect(() => {
handleResize();
fetchData();
}, [props.assetId, fetchData]);
}, []);

const getStatusColor = (day: number) => {
if (summary[day]) {
37 changes: 14 additions & 23 deletions src/Components/Common/prescription-builder/InvestigationBuilder.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import {
listInvestigationGroups,
listInvestigations,
} from "../../../Redux/actions";
import { PrescriptionDropdown } from "./PrescriptionDropdown";
import { PrescriptionMultiDropdown } from "./PrescriptionMultiselect";
import CareIcon from "../../../CAREUI/icons/CareIcon";
import request from "../../../Utils/request/request";
import routes from "../../../Redux/api";

export type InvestigationType = {
type?: string[];
repetitive?: boolean;
@@ -35,7 +33,6 @@ export default function InvestigationBuilder(
) {
const { investigations, setInvestigations } = props;
const [investigationsList, setInvestigationsList] = useState<string[]>([]);
const dispatch: any = useDispatch();
const [activeIdx, setActiveIdx] = useState<number | null>(null);
const additionalInvestigations = [
["Vitals", ["Temp", "Blood Pressure", "Respiratory Rate", "Pulse Rate"]],
@@ -85,26 +82,20 @@ export default function InvestigationBuilder(
};

const fetchInvestigations = async () => {
const res = await dispatch(listInvestigations({}));
if (res && res.data) {
return res.data.results.map(
(investigation: any) =>
investigation.name +
" -- " +
investigation.groups
.map((group: any) => " ( " + group.name + " ) ")
.join(", ")
);
}
return [];
const { data } = await request(routes.listInvestigations);
return (
data?.results.map(
(investigation) =>
`${investigation.name} -- ${investigation.groups
.map((group) => ` ( ${group.name} ) `)
.join(", ")}`
) ?? []
);
};

const fetchInvestigationGroups = async () => {
const res = await dispatch(listInvestigationGroups({}));
if (res && res.data) {
return res.data.results.map((group: any) => group.name + " (GROUP)");
}
return [];
const { data } = await request(routes.listInvestigationGroups);
return data?.results.map((group) => `${group.name} (GROUP)`) ?? [];
};

return (
2 changes: 1 addition & 1 deletion src/Components/Facility/AssetCreate.tsx
Original file line number Diff line number Diff line change
@@ -563,7 +563,7 @@ const AssetCreate = (props: AssetProps) => {
selected={location}
showAll={false}
multiple={false}
facilityId={facilityId as unknown as number}
facilityId={facilityId}
errors={state.errors.location}
/>
</div>
13 changes: 9 additions & 4 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
@@ -229,11 +229,16 @@ type ConsultationFormSection =
| "Treatment Plan"
| "Bed Status";

export const ConsultationForm = (props: any) => {
type Props = {
facilityId: string;
patientId: string;
id?: string;
};

export const ConsultationForm = ({ facilityId, patientId, id }: Props) => {
const { goBack } = useAppHistory();
const { kasp_enabled, kasp_string } = useConfig();
const dispatchAction: any = useDispatch();
const { facilityId, patientId, id } = props;
const [state, dispatch] = useAutoSaveReducer<FormDetails>(
consultationFormReducer,
initialState
@@ -344,7 +349,7 @@ export const ConsultationForm = (props: any) => {
const fetchData = useCallback(
async (status: statusType) => {
if (!patientId) setIsLoading(true);
const res = await dispatchAction(getConsultation(id));
const res = await dispatchAction(getConsultation(id!));
handleFormFieldChange({
name: "InvestigationAdvice",
value: !Array.isArray(res.data.investigation)
@@ -743,7 +748,7 @@ export const ConsultationForm = (props: any) => {
};

const res = await dispatchAction(
id ? updateConsultation(id, data) : createConsultation(data)
id ? updateConsultation(id!, data) : createConsultation(data)
);
setIsLoading(false);
if (res?.data && res.status !== 400) {
4 changes: 2 additions & 2 deletions src/Components/Facility/Investigations/Reports/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Notification from "../../../../Utils/Notifications";
import _ from "lodash-es";
import { Group, InvestigationType } from "..";
import { InvestigationGroup, InvestigationType } from "..";
import {
getPatient,
getPatientInvestigation,
@@ -22,7 +22,7 @@ import { useRef } from "react";

const RESULT_PER_PAGE = 14;
interface InitialState {
investigationGroups: Group[];
investigationGroups: InvestigationGroup[];
selectedGroup: string[];
investigations: InvestigationType[];
selectedInvestigations: any[];
12 changes: 7 additions & 5 deletions src/Components/Facility/Investigations/index.tsx
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ const initialState = {
form: {},
};

export interface Group {
export interface InvestigationGroup {
external_id: string;
name: string;
}
@@ -38,9 +38,9 @@ export interface InvestigationType {
unit?: string;
choices?: string;
ideal_value?: string;
groups: Group[];
groups: InvestigationGroup[];
}
type SearchItem = Group | InvestigationType;
type SearchItem = InvestigationGroup | InvestigationType;
function isInvestigation(e: SearchItem): e is InvestigationType {
return (e as InvestigationType).groups !== undefined;
}
@@ -67,7 +67,7 @@ const listOfInvestigations = (
);
};

const findGroup = (group_id: string, groups: Group[]) => {
const findGroup = (group_id: string, groups: InvestigationGroup[]) => {
return groups.find((g) => g.external_id === group_id);
};

@@ -106,7 +106,9 @@ const Investigation = (props: {
const [selectedGroup, setSelectedGroup] = useState<string[]>([]);
const [state, setState] = useReducer(testFormReducer, initialState);
const [investigations, setInvestigations] = useState<InvestigationType[]>([]);
const [investigationGroups, setInvestigationGroups] = useState<Group[]>([]);
const [investigationGroups, setInvestigationGroups] = useState<
InvestigationGroup[]
>([]);
const [selectedInvestigations, setSelectedInvestigations] = useState<
InvestigationType[]
>([]);
10 changes: 6 additions & 4 deletions src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
@@ -203,11 +203,11 @@ export interface InventoryItemsModel {
}

export interface LocationModel {
id?: string;
name?: string;
id: string;
name: string;
description?: string;
middleware_address?: string;
location_type?: AssetLocationType;
location_type: AssetLocationType;
facility?: {
name: string;
};
@@ -218,15 +218,17 @@ export interface LocationModel {
export interface BedModel {
id?: string;
bed_type?: string;
description?: string;
name?: string;
description?: string;
facility?: string;
location_object?: {
name: string;
id?: string;
};
location?: string;
is_occupied?: boolean;
created_date?: string;
modified_date?: string;
}

export interface CurrentBed {
2 changes: 0 additions & 2 deletions src/Components/Users/SkillsSlideOver.tsx
Original file line number Diff line number Diff line change
@@ -115,12 +115,10 @@ export default ({ show, setShow, username }: IProps) => {
multiple={false}
name="skill"
disabled={!authorizeForAddSkill}
showAll={true}
showNOptions={Infinity}
selected={selectedSkill}
setSelected={setSelectedSkill}
errors=""
username={username}
userSkills={skills?.results || []}
/>
<ButtonV2
15 changes: 2 additions & 13 deletions src/Redux/actions.tsx
Original file line number Diff line number Diff line change
@@ -20,14 +20,6 @@ export const getPermittedFacilities = (params: object) => {
return fireRequest("getPermittedFacilities", [], params);
};

export const getAllFacilities = (params: object) => {
return fireRequest("getAllFacilities", [], params);
};

export const getAllSkills = (params: object) => {
return fireRequest("getAllSkills", [], params);
};

export const getAnyFacility = (id: number | string, key?: string) => {
return fireRequest("getAnyFacility", [], {}, { id: id }, key);
};
@@ -296,10 +288,10 @@ export const createConsultation = (params: object) => {
export const getConsultationList = (params: object) => {
return fireRequest("getConsultationList", [], params);
};
export const getConsultation = (id: number) => {
export const getConsultation = (id: string) => {
return fireRequest("getConsultation", [], {}, { id: id });
};
export const updateConsultation = (id: number, params: object) => {
export const updateConsultation = (id: string, params: object) => {
return fireRequest("updateConsultation", [], params, { id: id });
};
//Inventory
@@ -506,9 +498,6 @@ export const updateAsset = (id: string, params: object) =>
export const operateAsset = (id: string, params: object) =>
fireRequest("operateAsset", [], params, { external_id: id });

export const listAssetAvailability = (params: object) =>
fireRequest("listAssetAvailability", [], params);

export const listPMJYPackages = (query?: string) =>
fireRequest("listPMJYPackages", [], { query });

12 changes: 11 additions & 1 deletion src/Redux/api.tsx
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ import {
AssetServiceUpdate,
AssetTransaction,
AssetUpdate,
AssetUptimeRecord,
PatientAssetBed,
} from "../Components/Assets/AssetTypes";
import {
@@ -77,6 +78,10 @@ import {
import { IComment, IResource } from "../Components/Resource/models";
import { IShift } from "../Components/Shifting/models";
import { HCXPolicyModel } from "../Components/HCX/models";
import {
InvestigationGroup,
InvestigationType,
} from "../Components/Facility/Investigations";

/**
* A fake function that returns an empty object casted to type T
@@ -286,6 +291,7 @@ const routes = {

getAllFacilities: {
path: "/api/v1/getallfacilities",
TRes: Type<PaginatedResponse<FacilityModel>>(),
},

createFacility: {
@@ -933,10 +939,12 @@ const routes = {
listInvestigations: {
path: "/api/v1/investigation/",
method: "GET",
TRes: Type<PaginatedResponse<InvestigationType>>(),
},
listInvestigationGroups: {
path: "/api/v1/investigation/group",
path: "/api/v1/investigation/group/",
method: "GET",
TRes: Type<PaginatedResponse<InvestigationGroup>>(),
},
createInvestigation: {
path: "/api/v1/consultation/{consultation_external_id}/investigation/",
@@ -1232,10 +1240,12 @@ const routes = {
listAssetAvailability: {
path: "/api/v1/asset_availability/",
method: "GET",
TRes: Type<PaginatedResponse<AssetUptimeRecord>>(),
},
getAssetAvailability: {
path: "/api/v1/asset_availability/{id}",
method: "GET",
TRes: Type<AssetUptimeRecord>(),
},

// Prescription endpoints

0 comments on commit 197cb39

Please sign in to comment.