Skip to content

Commit

Permalink
Merge branch 'develop' into encounter_card_design_update
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaJ2305 authored Feb 20, 2025
2 parents 3d8ad23 + b6aa5d9 commit 573acf2
Show file tree
Hide file tree
Showing 10 changed files with 779 additions and 119 deletions.
3 changes: 3 additions & 0 deletions cypress/e2e/patient_spec/patient_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const patientEncounter = new PatientEncounter();
const ENCOUNTER_TYPE = "Observation";
const ENCOUNTER_STATUS = "In Progress";
const ENCOUNTER_PRIORITY = "ASAP";
const ORGANIZATION_NAME = "Administration";

describe("Patient Management", () => {
const TEST_PHONE = "9495031234";
Expand Down Expand Up @@ -122,6 +123,7 @@ describe("Patient Management", () => {
.selectEncounterType(ENCOUNTER_TYPE)
.selectEncounterStatus(ENCOUNTER_STATUS)
.selectEncounterPriority(ENCOUNTER_PRIORITY)
.selectOrganization(ORGANIZATION_NAME)
.clickSubmitEncounter()
.assertEncounterCreationSuccess();

Expand Down Expand Up @@ -150,6 +152,7 @@ describe("Patient Management", () => {
.selectEncounterType(ENCOUNTER_TYPE)
.selectEncounterStatus(ENCOUNTER_STATUS)
.selectEncounterPriority(ENCOUNTER_PRIORITY)
.selectOrganization(ORGANIZATION_NAME)
.clickSubmitEncounter()
.assertEncounterCreationSuccess();

Expand Down
5 changes: 5 additions & 0 deletions cypress/pageObject/Patients/PatientVerify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class PatientVerify {
return this;
}

selectOrganization(organization: string) {
cy.clickAndSelectOption('[data-cy="facility-organization"]', organization);
return this;
}

clickSubmitEncounter() {
cy.clickSubmitButton("Create Encounter");
return this;
Expand Down
811 changes: 709 additions & 102 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dev": "npm run supported-browsers && vite",
"local": "npm run supported-browsers && vite --mode docker",
"preview": "cross-env NODE_ENV=production vite preview",
"preview:scan": "npm run preview & npx react-scan localhost:4000",
"build:meta": "node ./scripts/generate-build-version.js",
"build:react": "cross-env NODE_ENV=production vite build",
"supported-browsers": "node ./scripts/generate-supported-browsers.mjs",
Expand Down Expand Up @@ -124,6 +125,7 @@
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@julr/vite-plugin-validate-env": "^1.1.1",
"@react-scan/vite-plugin-react-scan": "^0.1.3",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
Expand Down
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@
"assigned_facility": "Facility assigned",
"assigned_to": "Assigned to",
"assigned_volunteer": "Assigned Volunteer",
"at_least_one_department_is_required": "At least one department is required",
"at_time": "at <strong>{{time}}</strong>",
"atypical_presentation_details": "Atypical presentation details",
"audio__allow_permission": "Please allow microphone permission in site settings",
Expand Down
38 changes: 29 additions & 9 deletions src/components/Encounter/CreateEncounterForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import careConfig from "@careConfig";
import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { t } from "i18next";
import {
Ambulance,
BedDouble,
Expand Down Expand Up @@ -74,7 +75,9 @@ const encounterFormSchema = z.object({
"use_as_directed",
"urgent",
] as const),
organizations: z.array(z.string()),
organizations: z.array(z.string()).min(1, {
message: t("at_least_one_department_is_required"),
}),
});

const encounterClasses = [
Expand Down Expand Up @@ -180,7 +183,15 @@ export default function CreateEncounterForm({
}

return (
<Sheet open={isOpen} onOpenChange={setIsOpen}>
<Sheet
open={isOpen}
onOpenChange={(open) => {
setIsOpen(open);
if (!open) {
form.reset();
}
}}
>
<SheetTrigger asChild>
{trigger || (
<Button
Expand Down Expand Up @@ -314,16 +325,25 @@ export default function CreateEncounterForm({
)}
/>
</div>

<FacilityOrganizationSelector
facilityId={facilityId}
onChange={(value) => {
form.setValue("organizations", [value]);
}}
<FormField
control={form.control}
name="organizations"
render={({ field }) => (
<FormItem>
<FacilityOrganizationSelector
facilityId={facilityId}
value={field.value[0]}
onChange={(value) => {
form.setValue("organizations", [value]);
}}
/>
<FormMessage />
</FormItem>
)}
/>

<Button type="submit" className="w-full" disabled={isPending}>
{isPending ? "Creating..." : "Create Encounter"}
{isPending ? "Creating..." : t("create_encounter")}
</Button>
</form>
</Form>
Expand Down
20 changes: 19 additions & 1 deletion src/components/Questionnaire/QuestionTypes/LocationQuestion.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useQuery } from "@tanstack/react-query";
import { format } from "date-fns";
import React, { useState } from "react";
import React, { useEffect, useState } from "react";

import { Input } from "@/components/ui/input";

import { LocationSearch } from "@/components/Location/LocationSearch";

import api from "@/Utils/request/api";
import query from "@/Utils/request/query";
import { Encounter } from "@/types/emr/encounter";
import { LocationAssociationQuestion } from "@/types/location/association";
import { LocationList } from "@/types/location/location";
import {
Expand Down Expand Up @@ -34,10 +38,24 @@ export function LocationQuestion({
facilityId,
encounterId,
}: LocationQuestionProps) {
const { data: encounter } = useQuery<Encounter>({
queryKey: ["encounter", encounterId],
queryFn: query(api.encounter.get, {
pathParams: { id: encounterId },
queryParams: { facility: facilityId },
}),
});

const [selectedLocation, setSelectedLocation] = useState<LocationList | null>(
null,
);

useEffect(() => {
if (encounter?.current_location) {
setSelectedLocation(encounter.current_location);
}
}, [encounter]);

const values =
(questionnaireResponse.values?.[0]
?.value as unknown as LocationAssociationQuestion[]) || [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useQuery } from "@tanstack/react-query";
import { Link } from "raviger";
import { useState } from "react";
import { useTranslation } from "react-i18next";

import CareIcon from "@/CAREUI/icons/CareIcon";
Expand Down Expand Up @@ -62,11 +61,10 @@ function OrganizationCard({

export default function FacilityOrganizationView({ id, facilityId }: Props) {
const { t } = useTranslation();
const { qParams, Pagination, resultsPerPage } = useFilters({
const { qParams, Pagination, resultsPerPage, updateQuery } = useFilters({
limit: 12,
cacheBlacklist: ["username"],
});
const [searchQuery, setSearchQuery] = useState("");

const { data: children, isLoading } = useQuery({
queryKey: [
Expand All @@ -76,15 +74,15 @@ export default function FacilityOrganizationView({ id, facilityId }: Props) {
id,
qParams.page,
resultsPerPage,
searchQuery,
qParams.search,
],
queryFn: query.debounced(routes.facilityOrganization.list, {
pathParams: { facilityId },
queryParams: {
parent: id,
offset: ((qParams.page || 1) - 1) * resultsPerPage,
limit: resultsPerPage,
name: searchQuery || undefined,
name: qParams.search || undefined,
},
}),
});
Expand All @@ -102,9 +100,9 @@ export default function FacilityOrganizationView({ id, facilityId }: Props) {
/>
<Input
placeholder={t("search_by_department_team_name")}
value={searchQuery}
value={qParams.search || ""}
onChange={(e) => {
setSearchQuery(e.target.value);
updateQuery({ search: e.target.value || undefined });
}}
className="w-full pl-8"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default function FacilityOrganizationSelector(
<div className="flex-1 flex items-center gap-2">
<div className="flex-1">
<Autocomplete
data-cy="facility-organization"
value={selectedLevels[level]?.id}
options={getOrganizationOptions(orgList)}
onChange={(value) => handleLevelChange(value, level)}
Expand Down
5 changes: 5 additions & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ValidateEnv } from "@julr/vite-plugin-validate-env";
import federation from "@originjs/vite-plugin-federation";
import reactScan from "@react-scan/vite-plugin-react-scan";
import react from "@vitejs/plugin-react";
import DOMPurify from "dompurify";
import fs from "fs";
Expand Down Expand Up @@ -208,6 +209,10 @@ export default defineConfig(({ mode }) => {
],
}),
react(),
reactScan({
enable:
env.NODE_ENV === "development" && env.ENABLE_REACT_SCAN === "true",
}),
checker({
typescript: true,
eslint: {
Expand Down

0 comments on commit 573acf2

Please sign in to comment.