Skip to content

Commit

Permalink
Merge branch 'develop' into doctor-notes-enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
UdaySagar-Git authored Dec 17, 2024
2 parents 32e7b39 + 69527b8 commit b58cfad
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 100 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
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
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
38 changes: 21 additions & 17 deletions src/components/Patient/PatientHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ import { Link, navigate } from "raviger";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";

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

import { Avatar } from "@/components/Common/Avatar";
import ButtonV2 from "@/components/Common/ButtonV2";
import ConfirmDialog from "@/components/Common/ConfirmDialog";
import Loading from "@/components/Common/Loading";
import Page from "@/components/Common/Page";
import UserAutocomplete from "@/components/Common/UserAutocompleteFormField";
import { patientTabs } from "@/components/Patient/PatientDetailsTab";
import { isPatientMandatoryDataFilled } from "@/components/Patient/Utils";
import {
AssignedToObjectModel,
PatientModel,
} from "@/components/Patient/models";
import { SkillModel, UserBareMinimum } from "@/components/Users/models";

import useAuthUser from "@/hooks/useAuthUser";

Expand All @@ -13,16 +27,13 @@ import {
OCCUPATION_TYPES,
} from "@/common/constants";

import { triggerGoal } from "@/Integrations/Plausible";
import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
import * as Notification from "@/Utils/Notifications";
import dayjs from "@/Utils/dayjs";
import routes from "@/Utils/request/api";

import Chip from "../../CAREUI/display/Chip";
import CareIcon from "../../CAREUI/icons/CareIcon";
import { triggerGoal } from "../../Integrations/Plausible";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import * as Notification from "../../Utils/Notifications";
import request from "../../Utils/request/request";
import useTanStackQueryInstead from "../../Utils/request/useQuery";
import request from "@/Utils/request/request";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import {
formatDateTime,
formatName,
Expand All @@ -31,15 +42,7 @@ import {
isAntenatal,
isPostPartum,
relativeDate,
} from "../../Utils/utils";
import { Avatar } from "../Common/Avatar";
import ButtonV2 from "../Common/ButtonV2";
import Loading from "../Common/Loading";
import Page from "../Common/Page";
import { SkillModel, UserBareMinimum } from "../Users/models";
import { patientTabs } from "./PatientDetailsTab";
import { isPatientMandatoryDataFilled } from "./Utils";
import { AssignedToObjectModel, PatientModel } from "./models";
} from "@/Utils/utils";

export const parseOccupation = (occupation: string | undefined) => {
return OCCUPATION_TYPES.find((i) => i.value === occupation)?.text;
Expand Down Expand Up @@ -447,6 +450,7 @@ export const PatientHome = (props: {
facilityId={facilityId || ""}
id={id}
patientData={patientData}
refetch={refetch}
/>
)}
</div>
Expand Down

0 comments on commit b58cfad

Please sign in to comment.