Skip to content

Commit

Permalink
Merge pull request #8850 from ohcnetwork/disable-abha-no-hf
Browse files Browse the repository at this point in the history
Disable abha number linking when health facility id is not present
  • Loading branch information
khavinshankar authored Oct 21, 2024
2 parents 69364c1 + 63a28a5 commit 420318b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 31 deletions.
66 changes: 46 additions & 20 deletions src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as Notification from "../../Utils/Notifications.js";

import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/Components/ui/tooltip";
import {
CONSULTATION_SUGGESTION,
DISCHARGE_REASONS,
Expand Down Expand Up @@ -43,6 +48,7 @@ import { SkillModel } from "../Users/models.js";
import { AuthorizedForConsultationRelatedActions } from "../../CAREUI/misc/AuthorizedChild.js";
import LinkAbhaNumber from "../ABDM/LinkAbhaNumber";
import careConfig from "@careConfig";
import { cn } from "@/lib/utils.js";

const formatSkills = (arr: SkillModel[]) => {
const skills = arr.map((skill) => skill.skill_object.name);
Expand Down Expand Up @@ -133,6 +139,11 @@ export default function PatientInfoCard(props: {
prefetch: !!consultation?.treating_physician_object?.username,
});

const { data: healthFacility } = useQuery(routes.abdm.healthFacility.get, {
pathParams: { facility_id: patient.facility ?? "" },
silent: true,
});

return (
<>
<DialogModal
Expand Down Expand Up @@ -781,25 +792,40 @@ export default function PatientInfoCard(props: {
</MenuItem>
</>
) : (
<MenuItem>
{({ close }) => (
<div
className="dropdown-item-primary pointer-events-auto m-2 flex cursor-pointer items-center justify-start gap-2 rounded border-0 p-2 text-sm font-normal transition-all duration-200 ease-in-out"
onClick={() => {
close();
setShowLinkABHANumber(true);
}}
>
<span className="flex w-full items-center justify-start gap-2">
<CareIcon
icon="l-link"
className="text-lg text-primary-500"
/>
<p>{t("link_abha_profile")}</p>
</span>
</div>
)}
</MenuItem>
<TooltipProvider>
<Tooltip>
<TooltipTrigger>
<MenuItem disabled={!healthFacility}>
{({ close, disabled }) => (
<div
className={cn(
"dropdown-item-primary pointer-events-auto m-2 flex cursor-pointer items-center justify-start gap-2 rounded border-0 p-2 text-sm font-normal transition-all duration-200 ease-in-out",
disabled && "pointer-events-none opacity-30",
)}
onClick={() => {
close();
setShowLinkABHANumber(true);
}}
>
<span className="flex w-full items-center justify-start gap-2">
<CareIcon
icon="l-link"
className="text-lg text-primary-500"
/>
<p>{t("generate_link_abha")}</p>
</span>
</div>
)}
</MenuItem>
</TooltipTrigger>

{!healthFacility && (
<TooltipContent className="max-w-sm break-words text-sm">
{t("abha_disabled_due_to_no_health_facility")}
</TooltipContent>
)}
</Tooltip>
</TooltipProvider>
))}
</div>
<div>
Expand Down
44 changes: 33 additions & 11 deletions src/Components/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import {
import { useCallback, useReducer, useRef, useState } from "react";
import { navigate } from "raviger";
import { statusType, useAbortableEffect } from "../../Common/utils";

import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/Components/ui/tooltip";
import AccordionV2 from "../Common/components/AccordionV2";
import AutocompleteFormField from "../Form/FormFields/Autocomplete.js";
import ButtonV2 from "../Common/components/ButtonV2";
Expand Down Expand Up @@ -372,6 +377,11 @@ export const PatientRegister = (props: PatientRegisterProps) => {
[id],
);

const { data: healthFacility } = useQuery(routes.abdm.healthFacility.get, {
pathParams: { facility_id: facilityId },
silent: true,
});

useQuery(routes.hcx.policies.list, {
query: {
patient: id,
Expand Down Expand Up @@ -1013,16 +1023,28 @@ export const PatientRegister = (props: PatientRegisterProps) => {
</div>
{!state.form.abha_number && (
<div className="flex justify-center md:justify-end">
<Button
variant="outline_primary"
onClick={(e) => {
e.preventDefault();
setShowLinkAbhaNumberModal(true);
}}
>
<CareIcon icon="l-user-square" className="mr-2" />
<span>Generate/Link ABHA Number</span>
</Button>
<TooltipProvider>
<Tooltip>
<TooltipTrigger>
<Button
variant="outline_primary"
disabled={!healthFacility}
onClick={(e) => {
e.preventDefault();
setShowLinkAbhaNumberModal(true);
}}
>
<CareIcon icon="l-user-square" className="mr-2" />
<span>{t("generate_link_abha")}</span>
</Button>
</TooltipTrigger>
{!healthFacility && (
<TooltipContent className="max-w-sm break-words text-sm">
{t("abha_disabled_due_to_no_health_facility")}
</TooltipContent>
)}
</Tooltip>
</TooltipProvider>
</div>
)}
{showAlertMessage.show && (
Expand Down
2 changes: 2 additions & 0 deletions src/Locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"abha_address_validation_length_error": "Should be atleast 4 character long",
"abha_address_validation_start_error": "Shouldn't start with a number or dot (.)",
"abha_details": "ABHA Details",
"abha_disabled_due_to_no_health_facility": "ABHA Number generation and linking is disabled for this facility, Please link a health facility to enable this feature.",
"abha_link_options__create_with_aadhaar__description": "Create New ABHA Number Using Aadhaar Number",
"abha_link_options__create_with_aadhaar__title": "Create with Aadhaar",
"abha_link_options__create_with_driving_license__description": "Create New ABHA Number Using Driving License",
Expand Down Expand Up @@ -666,6 +667,7 @@
"full_name": "Full Name",
"full_screen": "Full Screen",
"gender": "Gender",
"generate_link_abha": "Generate/Link ABHA Number",
"generate_report": "Generate Report",
"generated_summary_caution": "This is a computer generated summary using the information captured in the CARE system.",
"generating": "Generating",
Expand Down

0 comments on commit 420318b

Please sign in to comment.