Skip to content

Commit

Permalink
Merge branch 'develop' into fix#6877
Browse files Browse the repository at this point in the history
  • Loading branch information
sriharsh05 authored Jan 16, 2024
2 parents 836a281 + 51b02c2 commit 6175b42
Show file tree
Hide file tree
Showing 29 changed files with 257 additions and 171 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Authenticate to staging API with any of the following credentials

- username: staffdev
password: Coronasafe@123
role: Staff
role: Nurse

- username: doctordev
password: Coronasafe@123
Expand Down
34 changes: 11 additions & 23 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type UserRole =
| "Volunteer"
| "StaffReadOnly"
| "Staff"
| "NurseReadOnly"
| "Nurse"
| "Doctor"
| "WardAdmin"
| "LocalBodyAdmin"
Expand All @@ -47,6 +49,8 @@ export const USER_TYPE_OPTIONS: {
{ id: "Volunteer", role: "Volunteer", readOnly: false },
{ id: "StaffReadOnly", role: "Staff", readOnly: true },
{ id: "Staff", role: "Staff", readOnly: false },
{ id: "NurseReadOnly", role: "Nurse", readOnly: true },
{ id: "Nurse", role: "Nurse", readOnly: false },
{ id: "Doctor", role: "Doctor", readOnly: false },
{ id: "WardAdmin", role: "Ward Admin", readOnly: false },
{ id: "LocalBodyAdmin", role: "Local Body Admin", readOnly: false },
Expand Down Expand Up @@ -294,10 +298,10 @@ export const SYMPTOM_CHOICES = [
];

export const DISCHARGE_REASONS = [
{ id: "REC", text: "Recovered" },
{ id: "EXP", text: "Expired" },
{ id: "REF", text: "Referred" },
{ id: "LAMA", text: "LAMA" },
{ id: 1, text: "Recovered" },
{ id: 2, text: "Referred" },
{ id: 3, text: "Expired" },
{ id: 4, text: "LAMA" },
];

export const CONSCIOUSNESS_LEVEL = [
Expand Down Expand Up @@ -418,24 +422,6 @@ export const SAMPLE_FLOW_RULES = {
RECEIVED_AT_LAB: ["COMPLETED"],
};

export const ROLE_STATUS_MAP = {
Staff: ["SENT_TO_COLLECTON_CENTRE"],
DistrictAdmin: [
"APPROVED",
"DENIED",
"SENT_TO_COLLECTON_CENTRE",
"RECEIVED_AND_FORWARED",
],
StateLabAdmin: [
"APPROVED",
"DENIED",
"SENT_TO_COLLECTON_CENTRE",
"RECEIVED_AND_FORWARED",
"RECEIVED_AT_LAB",
"COMPLETED",
],
};

export const DISEASE_STATUS = [
"POSITIVE",
"SUSPECTED",
Expand Down Expand Up @@ -1042,6 +1028,8 @@ export const USER_TYPES_MAP = {
StaffReadOnly: "Staff",
Staff: "Staff",
Doctor: "Doctor",
Nurse: "Nurse",
NurseReadOnly: "Nurse",
WardAdmin: "Ward Admin",
LocalBodyAdmin: "Local Body Admin",
DistrictLabAdmin: "District Lab Admin",
Expand All @@ -1051,7 +1039,7 @@ export const USER_TYPES_MAP = {
StateReadOnlyAdmin: "State Admin",
StateAdmin: "State Admin",
RemoteSpecialist: "Remote Specialist",
};
} as const;

export const AREACODES: Record<string, string[]> = {
CA: [
Expand Down
14 changes: 10 additions & 4 deletions src/Common/hooks/useFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useQueryParams } from "raviger";
import { QueryParam, setQueryParamsOptions, useQueryParams } from "raviger";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import GenericFilterBadge from "../../CAREUI/display/FilterBadge";
Expand All @@ -23,7 +23,15 @@ export default function useFilters({ limit = 14 }: { limit?: number }) {
const { kasp_string } = useConfig();
const hasPagination = limit > 0;
const [showFilters, setShowFilters] = useState(false);
const [qParams, setQueryParams] = useQueryParams();
const [qParams, _setQueryParams] = useQueryParams();

const setQueryParams = (
query: QueryParam,
options?: setQueryParamsOptions
) => {
_setQueryParams(query, options);
updateFiltersCache(query);
};

const updateQuery = (filter: FilterState) => {
filter = hasPagination ? { page: 1, limit, ...filter } : filter;
Expand All @@ -38,8 +46,6 @@ export default function useFilters({ limit = 14 }: { limit?: number }) {
};
const removeFilter = (param: string) => removeFilters([param]);

useEffect(() => updateFiltersCache(qParams), [qParams]);

useEffect(() => {
const cache = getFiltersCache();
const qParamKeys = Object.keys(qParams);
Expand Down
10 changes: 5 additions & 5 deletions src/Components/Assets/AssetFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getDate = (value: any) =>

function AssetFilter(props: any) {
const { filter, onChange, closeFilter, removeFilters } = props;
const [facility, setFacility] = useState<FacilityModel>({ name: "" });
const [facility, setFacility] = useState<FacilityModel | null>(null);
const [asset_type, setAssetType] = useState<string>(
filter.asset_type ? filter.asset_type : ""
);
Expand Down Expand Up @@ -51,7 +51,7 @@ function AssetFilter(props: any) {
setLocationId(
facility?.id === qParams.facility ? qParams.location ?? "" : ""
);
}, [facility.id, qParams.facility, qParams.location]);
}, [facility?.id, qParams.facility, qParams.location]);

const clearFilter = useCallback(() => {
removeFilters([
Expand Down Expand Up @@ -81,8 +81,8 @@ function AssetFilter(props: any) {
onChange(data);
};

const handleFacilitySelect = (selected: FacilityModel) => {
setFacility(selected ? selected : facility);
const handleFacilitySelect = (selected: FacilityModel | null) => {
setFacility(selected);
handleLocationSelect("");
};
const handleLocationSelect = (selectedId: string) => {
Expand All @@ -107,7 +107,7 @@ function AssetFilter(props: any) {
<FacilitySelect
name="Facilities"
setSelected={(selected) =>
handleFacilitySelect(selected as FacilityModel)
handleFacilitySelect(selected as FacilityModel | null)
}
selected={facility}
errors=""
Expand Down
9 changes: 4 additions & 5 deletions src/Components/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,14 @@ export const Login = (props: { forgot?: boolean }) => {

const handleSubmit = async (e: any) => {
e.preventDefault();

setLoading(true);
invalidateFiltersCache();

const validated = validateData();
if (!validated) return;

if (!validated) {
setLoading(false);
return;
}
const { res } = await signIn(validated);

setCaptcha(res?.status === 429);
setLoading(false);
};
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Common/DistrictAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type Props = FormFieldBaseProps<DistrictModel["id"]> & {

export default function DistrictAutocompleteFormField(props: Props) {
const { data, loading } = useQuery(routes.getDistrictByState, {
pathParams: { id: props.state?.toString() ?? "" },
prefetch: props.state !== undefined,
pathParams: { id: props.state! },
prefetch: !!props.state,
});

return (
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Common/LocalBodyAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type Props = FormFieldBaseProps<LocalBodyModel["id"]> & {

export default function LocalBodyAutocompleteFormField(props: Props) {
const { data, loading } = useQuery(routes.getLocalbodyByDistrict, {
pathParams: { id: props.district?.toString() ?? "" },
prefetch: props.district !== undefined,
pathParams: { id: props.district! },
prefetch: !!props.district,
});

return (
Expand Down
41 changes: 25 additions & 16 deletions src/Components/Common/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useConfig from "../../../Common/hooks/useConfig";
import SlideOver from "../../../CAREUI/interactive/SlideOver";
import { classNames } from "../../../Utils/utils";
import { Link } from "raviger";
import useAuthUser from "../../../Common/hooks/useAuthUser";

export const SIDEBAR_SHRINK_PREFERENCE_KEY = "sidebarShrinkPreference";

Expand All @@ -27,28 +28,36 @@ type StatelessSidebarProps =
onItemClick: (open: boolean) => void;
};

const NavItems = [
{ text: "Facilities", to: "/facility", icon: "care-l-hospital" },
{ text: "Patients", to: "/patients", icon: "care-l-user-injured" },
{ text: "Assets", to: "/assets", icon: "care-l-shopping-cart-alt" },
{ text: "Sample Test", to: "/sample", icon: "care-l-medkit" },
{ text: "Shifting", to: "/shifting", icon: "care-l-ambulance" },
{ text: "Resource", to: "/resource", icon: "care-l-heart-medical" },
{
text: "External Results",
to: "/external_results",
icon: "care-l-clipboard-notes",
},
{ text: "Users", to: "/users", icon: "care-l-users-alt" },
{ text: "Notice Board", to: "/notice_board", icon: "care-l-meeting-board" },
];

const StatelessSidebar = ({
shrinkable = false,
shrinked = false,
setShrinked,
onItemClick,
}: StatelessSidebarProps) => {
const authUser = useAuthUser();

const NavItems = [
{ text: "Facilities", to: "/facility", icon: "care-l-hospital" },
{ text: "Patients", to: "/patients", icon: "care-l-user-injured" },
{ text: "Assets", to: "/assets", icon: "care-l-shopping-cart-alt" },
{ text: "Sample Test", to: "/sample", icon: "care-l-medkit" },
{ text: "Shifting", to: "/shifting", icon: "care-l-ambulance" },
{ text: "Resource", to: "/resource", icon: "care-l-heart-medical" },
...(!["Nurse", "NurseReadOnly", "Staff", "StaffReadOnly"].includes(
authUser.user_type
)
? [
{
text: "External Results",
to: "/external_results",
icon: "care-l-clipboard-notes",
},
]
: []),
{ text: "Users", to: "/users", icon: "care-l-users-alt" },
{ text: "Notice Board", to: "/notice_board", icon: "care-l-meeting-board" },
];

const { main_logo } = useConfig();
const activeLink = useActiveLink();
const Item = shrinked ? ShrinkedSidebarItem : SidebarItem;
Expand Down
26 changes: 19 additions & 7 deletions src/Components/ExternalResult/ResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ 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";
const Loading = lazy(() => import("../Common/Loading"));

export default function ResultList() {
const authUser = useAuthUser();
const {
qParams,
updateQuery,
Expand Down Expand Up @@ -165,6 +168,10 @@ export default function ResultList() {
<td className="whitespace-nowrap px-6 py-4 text-left text-sm leading-5 text-gray-500">
<ButtonV2
variant="primary"
disabled={
authUser.user_type === "Nurse" || authUser.user_type === "Staff"
}
authorizeFor={NonReadOnlyUsers}
border
ghost
onClick={() => {
Expand Down Expand Up @@ -226,13 +233,18 @@ export default function ResultList() {
<ExportMenu
label="Import/Export"
exportItems={[
{
label: "Import Results",
action: () => navigate("/external_results/upload"),
options: {
icon: <CareIcon className="care-l-import" />,
},
},
...(authUser.user_type !== "Nurse" &&
authUser.user_type !== "Staff"
? [
{
label: "Import Results",
action: () => navigate("/external_results/upload"),
options: {
icon: <CareIcon className="care-l-import" />,
},
},
]
: []),
{
label: "Export Results",
action: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
{props.consultationData.discharge_date && (
<div
className={`gap-4 overflow-hidden rounded-lg bg-white shadow ${
props.consultationData.discharge_reason === "REC" &&
props.consultationData.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Recovered")?.id &&
"lg:col-span-2"
}`}
>
Expand All @@ -190,11 +191,13 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
<span className="font-semibold">
{DISCHARGE_REASONS.find(
(d) =>
d.id === props.consultationData.discharge_reason
d.id === props.consultationData.new_discharge_reason
)?.text ?? "--"}
</span>
</div>
{props.consultationData.discharge_reason === "REF" && (
{props.consultationData.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Referred")
?.id && (
<div>
Referred Facility {" - "}
<span className="font-semibold">
Expand All @@ -204,7 +207,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
</span>
</div>
)}
{props.consultationData.discharge_reason === "REC" && (
{props.consultationData.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Recovered")
?.id && (
<div className="grid gap-4">
<div>
Discharge Date {" - "}
Expand Down Expand Up @@ -239,7 +244,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
</div>
</div>
)}
{props.consultationData.discharge_reason === "EXP" && (
{props.consultationData.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")
?.id && (
<div className="grid gap-4">
<div>
Date of Death {" - "}
Expand All @@ -266,8 +273,8 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
</div>
</div>
)}
{["REF", "LAMA"].includes(
props.consultationData.discharge_reason ?? ""
{[2, 4].includes(
props.consultationData.new_discharge_reason ?? 0
) && (
<div className="grid gap-4">
<div>
Expand Down
Loading

0 comments on commit 6175b42

Please sign in to comment.