Skip to content

Commit

Permalink
Merge branch 'ohcnetwork:develop' into issues/8913/test-to-assign-a-v…
Browse files Browse the repository at this point in the history
…olunteer
  • Loading branch information
sidpg123 authored Dec 17, 2024
2 parents 60e3890 + 69527b8 commit 3d30a92
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 144 deletions.
2 changes: 1 addition & 1 deletion src/Utils/request/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function queryRequest<TData, TBody>(

const fetchOptions: RequestInit = {
method,
headers: makeHeaders(noAuth ?? false),
headers: makeHeaders(noAuth ?? false, options?.headers),
signal: options?.signal,
};

Expand Down
1 change: 1 addition & 0 deletions src/Utils/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface QueryOptions<TBody = unknown> {
body?: TBody;
silent?: boolean;
signal?: AbortSignal;
headers?: HeadersInit;
}

export interface PaginatedResponse<TItem> {
Expand Down
24 changes: 7 additions & 17 deletions src/Utils/request/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,23 @@ const ensurePathNotMissingReplacements = (path: string) => {
}
};

export function makeHeaders(noAuth: boolean) {
const headers = new Headers({
"Content-Type": "application/json",
Accept: "application/json",
});
export function makeHeaders(noAuth: boolean, additionalHeaders?: HeadersInit) {
const headers = new Headers(additionalHeaders);

headers.set("Content-Type", "application/json");
headers.append("Accept", "application/json");

if (!noAuth) {
const token = getAuthorizationHeader();
const token = localStorage.getItem(LocalStorageKeys.accessToken);

if (token) {
headers.append("Authorization", token);
headers.append("Authorization", `Bearer ${token}`);
}
}

return headers;
}

export function getAuthorizationHeader() {
const bearerToken = localStorage.getItem(LocalStorageKeys.accessToken);

if (bearerToken) {
return `Bearer ${bearerToken}`;
}

return null;
}

export function mergeRequestOptions<TData>(
options: RequestOptions<TData>,
overrides: RequestOptions<TData>,
Expand Down
12 changes: 2 additions & 10 deletions src/components/Facility/PatientNotesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,10 @@ const PatientNotesList = (props: PatientNotesProps) => {
};

useEffect(() => {
if (reload) {
if (reload || thread) {
fetchNotes();
}
}, [reload]);

useEffect(() => {
fetchNotes();
}, [thread]);

useEffect(() => {
setReload(true);
}, []);
}, [reload, thread]);

const handleNext = () => {
if (state.cPage < state.totalPages) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Patient/DailyRounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export const DailyRounds = (props: any) => {
);
} else {
navigate(
`/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/log_updates/${obj.id}/update`,
`/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/log_updates/${obj.id}/critical_care/update`,
);
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/components/Patient/PatientDetailsTab/Demography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import AuthorizedChild from "@/CAREUI/misc/AuthorizedChild";

import { Button } from "@/components/ui/button";

import { InsuranceDetailsCard } from "@/components/Patient/InsuranceDetailsCard";
import { PatientProps } from "@/components/Patient/PatientDetailsTab";
import { parseOccupation } from "@/components/Patient/PatientHome";
import { AssignedToObjectModel } from "@/components/Patient/models";

import useAuthUser from "@/hooks/useAuthUser";

import { GENDER_TYPES } from "@/common/constants";

import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
import * as Notification from "@/Utils/Notifications";
import routes from "@/Utils/request/api";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import { formatName, formatPatientAge } from "@/Utils/utils";

import { PatientProps } from ".";
import * as Notification from "../../../Utils/Notifications";
import { InsuranceDetailsCard } from "../InsuranceDetailsCard";
import { parseOccupation } from "../PatientHome";
import { AssignedToObjectModel } from "../models";

export const Demography = (props: PatientProps) => {
const { patientData, facilityId, id } = props;
const authUser = useAuthUser();
Expand Down Expand Up @@ -64,9 +64,7 @@ export const Demography = (props: PatientProps) => {
const { data: insuranceDetials } = useTanStackQueryInstead(
routes.hcx.policies.list,
{
query: {
patient: id,
},
query: { patient: id },
},
);

Expand Down
42 changes: 3 additions & 39 deletions src/components/Patient/PatientDetailsTab/EncounterHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,20 @@
import React, { useEffect, useState } from "react";
import React from "react";
import { useTranslation } from "react-i18next";

import PaginatedList from "@/CAREUI/misc/PaginatedList";

import CircularProgress from "@/components/Common/CircularProgress";
import Loading from "@/components/Common/Loading";
import { ConsultationCard } from "@/components/Facility/ConsultationCard";
import { ConsultationModel } from "@/components/Facility/models";
import { PatientProps } from "@/components/Patient/PatientDetailsTab";

import useAuthUser from "@/hooks/useAuthUser";

import { triggerGoal } from "@/Integrations/Plausible";
import routes from "@/Utils/request/api";
import useTanStackQueryInstead from "@/Utils/request/useQuery";

import { PatientProps } from ".";
import { PatientModel } from "../models";

const EncounterHistory = (props: PatientProps) => {
const { patientData: initialPatientData, facilityId, id } = props;
const [patientData, setPatientData] =
useState<PatientModel>(initialPatientData);
const authUser = useAuthUser();

useEffect(() => {
setPatientData(initialPatientData);
}, [initialPatientData]);
const { patientData, id, refetch } = props;

const { t } = useTranslation();

const { loading: isLoading, refetch } = useTanStackQueryInstead(
routes.getPatient,
{
pathParams: {
id,
},
onResponse: ({ res, data }) => {
if (res?.ok && data) {
setPatientData(data);
}
triggerGoal("Patient Profile Viewed", {
facilityId: facilityId,
userId: authUser.id,
});
},
},
);

if (isLoading) {
return <Loading />;
}

return (
<PaginatedList
route={routes.getConsultationList}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";

import { PatientProps } from "@/components/Patient/PatientDetailsTab";
import { PatientModel } from "@/components/Patient/models";
import { UserModel } from "@/components/Users/models";

import useAuthUser from "@/hooks/useAuthUser";

import { ADMIN_USER_TYPES } from "@/common/constants";

import { PatientProps } from ".";
import * as Notification from "../../../Utils/Notifications";
import { PatientModel } from "../models";
import * as Notification from "@/Utils/Notifications";

export const HealthProfileSummary = (props: PatientProps) => {
const { patientData, facilityId, id } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";

import { PatientProps } from "@/components/Patient/PatientDetailsTab";
import { PatientModel } from "@/components/Patient/models";
import { UserModel } from "@/components/Users/models";

import useAuthUser from "@/hooks/useAuthUser";

import { ADMIN_USER_TYPES } from "@/common/constants";

import * as Notification from "@/Utils/Notifications";
import { formatDateTime } from "@/Utils/utils";

import { PatientProps } from ".";
import * as Notification from "../../../Utils/Notifications";
import { PatientModel } from "../models";

export const ImmunisationRecords = (props: PatientProps) => {
const { patientData, facilityId, id } = props;

Expand Down
40 changes: 7 additions & 33 deletions src/components/Patient/PatientDetailsTab/Notes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t } from "i18next";
import { useEffect, useState } from "react";
import { useState } from "react";

import CareIcon from "@/CAREUI/icons/CareIcon";

Expand All @@ -11,26 +11,21 @@ import {
PatientNotesModel,
} from "@/components/Facility/models";
import AutoExpandingTextInputFormField from "@/components/Form/FormFields/AutoExpandingTextInputFormField";
import { PatientProps } from "@/components/Patient/PatientDetailsTab";

import useAuthUser from "@/hooks/useAuthUser";
import { useMessageListener } from "@/hooks/useMessageListener";

import { PATIENT_NOTES_THREADS } from "@/common/constants";

import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
import * as Notification from "@/Utils/Notifications";
import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import { classNames, keysOf } from "@/Utils/utils";

import * as Notification from "../../../Utils/Notifications";

interface PatientNotesProps {
id: string;
facilityId: string;
}

const PatientNotes = (props: PatientNotesProps) => {
const { id: patientId, facilityId } = props;
const PatientNotes = (props: PatientProps) => {
const { patientData, id: patientId, facilityId } = props;

const authUser = useAuthUser();
const [thread, setThread] = useState(
Expand All @@ -39,7 +34,6 @@ const PatientNotes = (props: PatientNotesProps) => {
: PATIENT_NOTES_THREADS.Doctors,
);

const [patientActive, setPatientActive] = useState(true);
const [noteField, setNoteField] = useState("");
const [reload, setReload] = useState(false);
const [reply_to, setReplyTo] = useState<PatientNotesModel | undefined>(
Expand Down Expand Up @@ -84,26 +78,6 @@ const PatientNotes = (props: PatientNotesProps) => {
}
};

useEffect(() => {
async function fetchPatientName() {
if (patientId) {
try {
const { data } = await request(routes.getPatient, {
pathParams: { id: patientId },
});
if (data) {
setPatientActive(data.is_active ?? true);
}
} catch (error) {
Notification.Error({
msg: "Failed to fetch patient status",
});
}
}
}
fetchPatientName();
}, [patientId]);

useMessageListener((data) => {
const message = data?.message;
if (
Expand Down Expand Up @@ -161,15 +135,15 @@ const PatientNotes = (props: PatientNotesProps) => {
errorClassName="hidden"
innerClassName="pr-10"
placeholder={t("notes_placeholder")}
disabled={!patientActive}
disabled={!patientData.is_active}
/>
<ButtonV2
onClick={onAddNote}
border={false}
className="absolute right-2"
ghost
size="small"
disabled={!patientActive}
disabled={!patientData.is_active}
authorizeFor={NonReadOnlyUsers}
>
<CareIcon icon="l-message" className="text-lg" />
Expand Down
5 changes: 2 additions & 3 deletions src/components/Patient/PatientDetailsTab/ShiftingHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useTranslation } from "react-i18next";
import CareIcon from "@/CAREUI/icons/CareIcon";

import ButtonV2 from "@/components/Common/ButtonV2";
import { PatientProps } from "@/components/Patient/PatientDetailsTab";
import { PatientModel } from "@/components/Patient/models";
import { formatFilter } from "@/components/Resource/ResourceCommons";
import ShiftingTable from "@/components/Shifting/ShiftingTable";

Expand All @@ -13,9 +15,6 @@ import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
import routes from "@/Utils/request/api";
import useTanStackQueryInstead from "@/Utils/request/useQuery";

import { PatientProps } from ".";
import { PatientModel } from "../models";

const ShiftingHistory = (props: PatientProps) => {
const { patientData, facilityId, id } = props;
const { t } = useTranslation();
Expand Down
15 changes: 8 additions & 7 deletions src/components/Patient/PatientDetailsTab/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { PatientModel } from "../models";
import { Demography } from "./Demography";
import EncounterHistory from "./EncounterHistory";
import { HealthProfileSummary } from "./HealthProfileSummary";
import { ImmunisationRecords } from "./ImmunisationRecords";
import PatientNotes from "./Notes";
import ShiftingHistory from "./ShiftingHistory";
import EncounterHistory from "@/components/Patient/PatientDetailsTab//EncounterHistory";
import { HealthProfileSummary } from "@/components/Patient/PatientDetailsTab//HealthProfileSummary";
import { ImmunisationRecords } from "@/components/Patient/PatientDetailsTab//ImmunisationRecords";
import PatientNotes from "@/components/Patient/PatientDetailsTab//Notes";
import ShiftingHistory from "@/components/Patient/PatientDetailsTab//ShiftingHistory";
import { Demography } from "@/components/Patient/PatientDetailsTab/Demography";
import { PatientModel } from "@/components/Patient/models";

export interface PatientProps {
facilityId: string;
id: string;
patientData: PatientModel;
refetch: () => void;
}

export const patientTabs = [
Expand Down
Loading

0 comments on commit 3d30a92

Please sign in to comment.