Skip to content

Commit

Permalink
Merge branch 'coronasafe:develop' into assets_update
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijv256 authored Sep 29, 2023
2 parents 4f06879 + bebb693 commit aae1541
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 45 deletions.
3 changes: 3 additions & 0 deletions cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe("Patient Creation with consultation", () => {
it("Create a new patient with no consultation", () => {
patientPage.createPatient();
patientPage.selectFacility("dummy facility");
patientPage.patientformvisibility();
patientPage.enterPatientDetails(
phone_number,
emergency_phone_number,
Expand Down Expand Up @@ -69,6 +70,7 @@ describe("Patient Creation with consultation", () => {
patientPage.interceptFacilities();
patientPage.visitUpdatePatientUrl();
patientPage.verifyStatusCode();
patientPage.patientformvisibility();
updatePatientPage.enterPatientDetails(
"Test E2E User Edited",
"O+",
Expand Down Expand Up @@ -113,6 +115,7 @@ describe("Patient Creation with consultation", () => {
patientConsultationPage.selectSymptoms("ASYMPTOMATIC");

patientConsultationPage.enterConsultationDetails(
"Stable",
"Examination details and Clinical conditions",
"70",
"170",
Expand Down
2 changes: 0 additions & 2 deletions cypress/pageobject/Facility/FacilityCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ class FacilityPage {
}

verifyfacilitycreateassetredirection() {
cy.intercept("GET", "**/api/v1/facility/**").as("getNewAssets");
cy.url().should("include", "/assets/new");
cy.wait("@getNewAssets").its("response.statusCode").should("eq", 200);
}

verifyassetfacilitybackredirection() {
Expand Down
9 changes: 9 additions & 0 deletions cypress/pageobject/Patient/PatientConsultation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export class PatientConsultationPage {
}

fillIllnessHistory(history: string) {
cy.wait(5000);
cy.get("#history_of_present_illness").scrollIntoView();
cy.get("#history_of_present_illness").should("be.visible");
cy.get("#history_of_present_illness").click().type(history);
}

enterConsultationDetails(
category: string,
examinationDetails: string,
weight: string,
height: string,
Expand All @@ -30,6 +32,11 @@ export class PatientConsultationPage {
verificationBy: string
) {
cy.get("#symptoms").click();
cy.get("#category")
.click()
.then(() => {
cy.get("[role='option']").contains(category).click();
});
cy.get("#examination_details").click().type(examinationDetails);
cy.get("#weight").click().type(height);
cy.get("#height").click().type(weight);
Expand All @@ -38,10 +45,12 @@ export class PatientConsultationPage {
cy.get(
"#icd11_diagnoses_object input[placeholder='Select'][role='combobox']"
)
.scrollIntoView()
.click()
.type("1A");
cy.get("#icd11_diagnoses_object [role='option']")
.contains("1A03 Intestinal infections due to Escherichia coli")
.scrollIntoView()
.click();
cy.get("label[for='icd11_diagnoses_object']").click();
cy.wait("@getIcdResults").its("response.statusCode").should("eq", 200);
Expand Down
4 changes: 4 additions & 0 deletions cypress/pageobject/Patient/PatientCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,8 @@ export class PatientPage {
verifyStatusCode() {
cy.wait("@getFacilities").its("response.statusCode").should("eq", 200);
}

patientformvisibility() {
cy.get("[data-testid='current-address']").scrollIntoView();
}
}
2 changes: 1 addition & 1 deletion src/Components/ExternalResult/FacilitiesSelectDialogue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const FacilitiesSelectDialog = (props: Props) => {
<Cancel onClick={handleCancel} />
<Submit
onClick={handleOk}
disabled={!selectedFacility.id}
disabled={!selectedFacility?.id}
label={t("select")}
data-testid="submit-button"
/>
Expand Down
67 changes: 55 additions & 12 deletions src/Components/Facility/ConsultationDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {
SYMPTOM_CHOICES,
} from "../../../Common/constants";
import { ConsultationModel, ICD11DiagnosisModel } from "../models";
import { getConsultation, getPatient } from "../../../Redux/actions";
import {
getConsultation,
getPatient,
listShiftRequests,
} from "../../../Redux/actions";
import { statusType, useAbortableEffect } from "../../../Common/utils";
import { lazy, useCallback, useState } from "react";
import ToolTip from "../../Common/utils/Tooltip";
Expand Down Expand Up @@ -79,6 +83,7 @@ export const ConsultationDetails = (props: any) => {
{} as ConsultationModel
);
const [patientData, setPatientData] = useState<PatientModel>({});
const [activeShiftingData, setActiveShiftingData] = useState<Array<any>>([]);
const [openDischargeSummaryDialog, setOpenDischargeSummaryDialog] =
useState(false);
const [openDischargeDialog, setOpenDischargeDialog] = useState(false);
Expand Down Expand Up @@ -140,6 +145,15 @@ export const ConsultationDetails = (props: any) => {
};
setPatientData(data);
}

// Get shifting data
const shiftingRes = await dispatch(
listShiftRequests({ patient: id }, "shift-list-call")
);
if (shiftingRes?.data?.results) {
const data = shiftingRes.data.results;
setActiveShiftingData(data);
}
} else {
navigate("/not-found");
}
Expand Down Expand Up @@ -168,6 +182,19 @@ export const ConsultationDetails = (props: any) => {

const SelectedTab = TABS[tab];

const hasActiveShiftingRequest = () => {
if (activeShiftingData.length > 0) {
return [
"PENDING",
"APPROVED",
"DESTINATION APPROVED",
"PATIENT TO BE PICKED UP",
].includes(activeShiftingData[activeShiftingData.length - 1].status);
}

return false;
};

if (isLoading) {
return <Loading />;
}
Expand Down Expand Up @@ -265,17 +292,33 @@ export const ConsultationDetails = (props: any) => {
<div className="-right-6 top-0 flex w-full flex-col space-y-1 sm:w-min sm:flex-row sm:items-center sm:space-y-0 sm:divide-x-2 lg:absolute xl:right-0">
{!consultationData.discharge_date && (
<div className="flex w-full flex-col px-2 sm:flex-row">
<ButtonV2
onClick={() =>
navigate(
`/facility/${patientData.facility}/patient/${patientData.id}/shift/new`
)
}
className="btn btn-primary m-1 w-full hover:text-white"
>
<CareIcon className="care-l-ambulance h-5 w-5" />
Shift Patient
</ButtonV2>
{hasActiveShiftingRequest() ? (
<ButtonV2
onClick={() =>
navigate(
`/shifting/${
activeShiftingData[activeShiftingData.length - 1].id
}`
)
}
className="btn btn-primary m-1 w-full hover:text-white"
>
<CareIcon className="care-l-ambulance h-5 w-5" />
Track Shifting
</ButtonV2>
) : (
<ButtonV2
onClick={() =>
navigate(
`/facility/${patientData.facility}/patient/${patientData.id}/shift/new`
)
}
className="btn btn-primary m-1 w-full hover:text-white"
>
<CareIcon className="care-l-ambulance h-5 w-5" />
Shift Patient
</ButtonV2>
)}
<button
onClick={() => {
triggerGoal("Doctor Connect Clicked", {
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const initForm: FormDetails = {
facility: "",
admitted: "false",
admitted_to: "",
category: "Comfort",
category: "",
admission_date: new Date(),
discharge_date: null,
referred_to: "",
Expand Down Expand Up @@ -373,8 +373,8 @@ export const ConsultationForm = (props: any) => {
admitted_to: res.data.admitted_to ? res.data.admitted_to : "",
category: res.data.category
? PATIENT_CATEGORIES.find((i) => i.text === res.data.category)
?.id ?? "Comfort"
: "Comfort",
?.id ?? ""
: "",
patient_no: res.data.patient_no ?? "",
OPconsultation: res.data.consultation_notes,
is_telemedicine: `${res.data.is_telemedicine}`,
Expand Down
18 changes: 12 additions & 6 deletions src/Components/Patient/DailyRounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const initForm: any = {
other_symptoms: "",
physical_examination_info: "",
other_details: "",
patient_category: "Comfort",
patient_category: "",
current_health: 0,
recommend_discharge: false,
action: null,
Expand Down Expand Up @@ -142,14 +142,14 @@ export const DailyRounds = (props: any) => {
);

if (!status.aborted) {
if (res && res.data) {
if (res?.data) {
const data = {
...res.data,
patient_category: res.data.patient_category
? PATIENT_CATEGORIES.find(
(i) => i.text === res.data.patient_category
)?.id || "Comfort"
: "Comfort",
)?.id ?? ""
: "",
rhythm:
(res.data.rhythm &&
RHYTHM_CHOICES.find((i) => i.text === res.data.rhythm)?.id) ||
Expand Down Expand Up @@ -186,8 +186,8 @@ export const DailyRounds = (props: any) => {
patient_category: res.data.patient_category
? PATIENT_CATEGORIES.find(
(i) => i.text === res.data.patient_category
)?.id || "Comfort"
: "Comfort",
)?.id ?? ""
: "",
rhythm:
(res.data.rhythm &&
RHYTHM_CHOICES.find((i) => i.text === res.data.rhythm)?.id) ||
Expand All @@ -205,6 +205,12 @@ export const DailyRounds = (props: any) => {
let invalidForm = false;
Object.keys(state.form).forEach((field) => {
switch (field) {
case "patient_category":
if (!state.form[field]) {
errors[field] = "Please select a category";
invalidForm = true;
}
return;
case "other_symptoms":
if (
state.form.additional_symptoms?.includes(9) &&
Expand Down
4 changes: 1 addition & 3 deletions src/Components/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ import { FormContextValue } from "../Form/FormContext.js";
const Loading = lazy(() => import("../Common/Loading"));
const PageTitle = lazy(() => import("../Common/PageTitle"));

// const debounce = require("lodash.debounce");

interface PatientRegisterProps extends PatientModel {
facilityId: string;
}
Expand Down Expand Up @@ -1260,7 +1258,7 @@ export const PatientRegister = (props: PatientRegisterProps) => {
required
label="Phone Number"
onChange={(event) => {
duplicateCheck(event.value);
if (!id) duplicateCheck(event.value);
field("phone_number").onChange(event);
}}
types={["mobile", "landline"]}
Expand Down
13 changes: 7 additions & 6 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { PaginatedResponse } from "../Utils/request/types";
* A fake function that returns an empty object casted to type T
* @returns Empty object as type T
*/
function Res<T>(): T {
function Type<T>(): T {
return {} as T;
}

Expand All @@ -28,7 +28,7 @@ const routes = {
path: import.meta.env.REACT_APP_CONFIG ?? "/config.json",
method: "GET",
noAuth: true,
TRes: Res<IConfig>(),
TRes: Type<IConfig>(),
},

// Auth Endpoints
Expand All @@ -41,7 +41,8 @@ const routes = {
token_refresh: {
path: "/api/v1/auth/token/refresh/",
method: "POST",
TRes: Res<JwtTokenObtainPair>(),
TRes: Type<JwtTokenObtainPair>(),
TBody: Type<{ refresh: string }>(),
},

token_verify: {
Expand Down Expand Up @@ -71,7 +72,7 @@ const routes = {
// User Endpoints
currentUser: {
path: "/api/v1/users/getcurrentuser/",
TRes: Res<UserModel>(),
TRes: Type<UserModel>(),
},

userList: {
Expand Down Expand Up @@ -209,7 +210,7 @@ const routes = {
listFacilityAssetLocation: {
path: "/api/v1/facility/{facility_external_id}/asset_location/",
method: "GET",
TRes: Res<PaginatedResponse<LocationModel>>(),
TRes: Type<PaginatedResponse<LocationModel>>(),
},
createFacilityAssetLocation: {
path: "/api/v1/facility/{facility_external_id}/asset_location/",
Expand Down Expand Up @@ -820,7 +821,7 @@ const routes = {
getAsset: {
path: "/api/v1/asset/{external_id}/",
method: "GET",
TRes: Res<AssetData>(),
TRes: Type<AssetData>(),
},
deleteAsset: {
path: "/api/v1/asset/{external_id}/",
Expand Down
9 changes: 5 additions & 4 deletions src/Utils/request/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const FooRoutes = {
path: "/api/v1/foo/{id}/", // 👈 The path to the endpoint. Slug parameters can be specified using curly braces.

method: "GET", // 👈 The HTTP method to use. Optional; defaults to "GET".
TRes: Res<Foo()>, // 👈 The type of the response body (for type inference).
TRes: Type<Foo>(), // 👈 The type of the response body (for type inference).
TBody: Type<Foo>(), // 👈 The type of the request body (for type inference).
noAuth: true, // 👈 Whether to skip adding the Authorization header to the request.
},
} as const; // 👈 This is important for type inference to work properly.
Expand All @@ -78,7 +79,7 @@ const options = {
// thrown before the request is made.

query: { limit: 10 }, // 👈 The query parameters to be added to the request URL.
body: { name: "foo" }, // 👈 The body to be sent with the request.
body: { name: "foo" }, // 👈 The body to be sent with the request. Should be compatible with the TBody type of the route.
headers: { "X-Foo": "bar" }, // 👈 Additional headers to be sent with the request. (Coming soon...)

silent: true, // 👈 Whether to suppress notifications for this request.
Expand All @@ -103,7 +104,7 @@ The `useQuery` hook returns an object with the following properties:

```ts
{
res: Res<TRes> | undefined; // 👈 The response object. `undefined` if the request has not been made yet.
res: Type<TRes> | undefined; // 👈 The response object. `undefined` if the request has not been made yet.

data: TRes | null; // 👈 The response body. `null` if the request has not been made yet.

Expand All @@ -129,7 +130,7 @@ import FooRoutes from "@foo/routes";
export default async function updateFoo(id: string, object: Foo) {
const { res, data } = await request(FooRoutes.updateFoo, {
pathParams: { id },
body: object, // 👈 The body is automatically serialized to JSON.
body: object, // 👈 The body is automatically serialized to JSON. Should be compatible with the TBody type of the route.
});

if (res.status === 403) {
Expand Down
8 changes: 4 additions & 4 deletions src/Utils/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import handleResponse from "./handleResponse";
import { RequestOptions, RequestResult, Route } from "./types";
import { makeHeaders, makeUrl } from "./utils";

interface Options<TData> extends RequestOptions<TData> {
interface Options<TData, TBody> extends RequestOptions<TData, TBody> {
controller?: AbortController;
}

export default async function request<TData>(
{ path, method, noAuth }: Route<TData>,
export default async function request<TData, TBody>(
{ path, method, noAuth }: Route<TData, TBody>,
{
query,
body,
Expand All @@ -16,7 +16,7 @@ export default async function request<TData>(
onResponse,
silent,
reattempts = 3,
}: Options<TData> = {}
}: Options<TData, TBody> = {}
): Promise<RequestResult<TData>> {
const signal = controller?.signal;
const url = makeUrl(path, query, pathParams);
Expand Down
Loading

0 comments on commit aae1541

Please sign in to comment.