Skip to content

Commit

Permalink
Abdm (#5798)
Browse files Browse the repository at this point in the history
  • Loading branch information
khavinshankar authored Jul 21, 2023
1 parent e3216ce commit bddeda6
Show file tree
Hide file tree
Showing 32 changed files with 2,981 additions and 16,287 deletions.
17,280 changes: 1,174 additions & 16,106 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"echarts": "^5.4.2",
"echarts-for-react": "^3.0.1",
"events": "^3.3.0",
"html2canvas": "^1.4.1",
"i18next": "^22.5.0",
"i18next-browser-languagedetector": "^7.0.0",
"libphonenumber-js": "^1.10.30",
Expand Down Expand Up @@ -161,7 +162,7 @@
"tailwindcss": "^3.2.4",
"typescript": "^4.8.4",
"vite": "^4.2.1",
"vite-plugin-pwa": "^0.14.6"
"vite-plugin-pwa": "^0.14.7"
},
"browserslist": {
"production": [
Expand Down
3 changes: 2 additions & 1 deletion public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"kasp_string": "KASP",
"kasp_full_string": "Karunya Arogya Suraksha Padhathi",
"sample_format_asset_import": "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=11JaEhNHdyCHth4YQs_44YaRlP77Rrqe81VSEfg1glko&exportFormat=xlsx",
"sample_format_external_result_import": "https://docs.google.com/spreadsheets/d/17VfgryA6OYSYgtQZeXU9mp7kNvLySeEawvnLBO_1nuE/export?format=csv&id=17VfgryA6OYSYgtQZeXU9mp7kNvLySeEawvnLBO_1nuE"
"sample_format_external_result_import": "https://docs.google.com/spreadsheets/d/17VfgryA6OYSYgtQZeXU9mp7kNvLySeEawvnLBO_1nuE/export?format=csv&id=17VfgryA6OYSYgtQZeXU9mp7kNvLySeEawvnLBO_1nuE",
"enable_abdm": true
}
7 changes: 4 additions & 3 deletions src/CAREUI/icons/CareIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useEffect } from "react";
import { transformIcons } from "./icon";
import { useEffect } from "react";

export interface CareIconProps {
className?: string | undefined;
onClick?: () => void;
}

/**
Expand All @@ -13,10 +14,10 @@ export interface CareIconProps {
*
* @see [icon library](https://iconscout.com/unicons/)
*/
export default function CareIcon({ className }: CareIconProps) {
export default function CareIcon({ className, onClick }: CareIconProps) {
useEffect(() => transformIcons(), [className]);
return (
<span key={className}>
<span onClick={onClick} key={className}>
<i className={`care ${className}`} />
</span>
);
Expand Down
4 changes: 4 additions & 0 deletions src/Common/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export interface IConfig {
* Env to enable HCX features
*/
enable_hcx: boolean;
/**
* Env to enable ABDM features
*/
enable_abdm: boolean;
/**
* Env to toggle peacetime and wartime shifting
*/
Expand Down
155 changes: 155 additions & 0 deletions src/Components/ABDM/ABHAProfileModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import * as Notify from "../../Utils/Notifications";

import { AbhaObject } from "../Patient/models";
import CareIcon from "../../CAREUI/icons/CareIcon";
import DialogModal from "../Common/Dialog";
import QRCode from "qrcode.react";
import { formatDate } from "../../Utils/utils";
import { getAbhaCard } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import { useRef } from "react";

interface IProps {
patientId?: string;
abha?: AbhaObject;
show: boolean;
onClose: () => void;
}

const ABHAProfileModal = ({ patientId, show, onClose, abha }: IProps) => {
const printRef = useRef(null);
const dispatch = useDispatch<any>();

const downloadAbhaCard = async (type: "pdf" | "png") => {
if (!patientId) return;
const response = await dispatch(getAbhaCard(patientId, type));

if (response.status === 200 && response.data) {
if (type === "png") {
const downloadLink = document.createElement("a");
downloadLink.href =
"data:application/octet-stream;base64," + response.data;
downloadLink.download = "abha.png";
downloadLink.click();
} else {
const htmlPopup = `<embed width=100% height=100%" type='application/pdf' src='data:application/pdf;base64,${response.data}'></embed>`;

const printWindow = window.open("", "PDF");
printWindow?.document.write(htmlPopup);
printWindow?.print();
}
} else {
Notify.Error({ msg: "Download Failed..." });
}
};

return (
<DialogModal
title={
<div className="flex items-center justify-between">
<h4>ABHA Profile</h4>
<div className="flex items-center gap-2">
<CareIcon
onClick={() => downloadAbhaCard("pdf")}
className="care-l-print cursor-pointer"
/>
<CareIcon
onClick={() => downloadAbhaCard("png")}
className="care-l-import cursor-pointer"
/>
</div>
</div>
}
show={show}
onClose={onClose}
>
<div
ref={printRef}
id="section-to-print"
className="print flex items-center justify-around print:border border-black p-4 print:w-full"
>
<>
<div className="flex flex-col items-center justify-evenly">
<div className="flex items-center justify-evenly gap-2 text-lg font-semibold">
{abha?.name ? (
<span> {abha?.name}</span>
) : (
<>
<span> {abha?.first_name}</span>
<span> {abha?.middle_name} </span>
<span> {abha?.last_name} </span>
</>
)}
</div>
<span className="font-bold">{abha?.abha_number}</span>
{abha?.health_id && (
<div className="flex items-center gap-1 font-bold">
<span>{abha.health_id.split("@")[0]}</span>
{/* <span className="text-gray-700 text-sm">@</span>
<span>{abha.health_id.split("@")[1] || "care"}</span> */}
</div>
)}
<div className="flex flex-col mt-2">
{abha?.gender && (
<p className="text-sm text-gray-600">
Gender:
<span className="ml-2 text-base font-semibold text-gray-900">
{abha?.gender}
</span>
</p>
)}
{abha?.date_of_birth && (
<p className="text-sm text-gray-600">
DOB:
<span className="ml-2 text-base font-semibold text-gray-900">
{abha?.date_of_birth}
</span>
</p>
)}
{abha?.email && (
<p className="text-sm text-gray-600">
Email:
<span className="ml-2 text-base font-semibold text-gray-900">
{abha?.email}
</span>
</p>
)}
</div>
</div>
</>
<>
<QRCode
className="border border-black p-1"
value={JSON.stringify({
hidn: abha?.abha_number,
phr: abha?.health_id,
name: abha?.name,
gender: abha?.gender,
dob: abha?.date_of_birth,
address: abha?.address,
"state name": abha?.state,
"dist name": abha?.district,
})}
/>
</>
</div>

<div className="flex flex-col mt-4 text-sm text-gray-700">
{abha?.created_date && (
<div className="flex gap-1 items-center">
<span className="">Created On: </span>
<span>{formatDate(abha.created_date)}</span>
</div>
)}
{abha?.modified_date && (
<div className="flex gap-1 items-center">
<span className="">Last Modified On: </span>
<span>{formatDate(abha.modified_date)}</span>
</div>
)}
</div>
</DialogModal>
);
};

export default ABHAProfileModal;
Loading

0 comments on commit bddeda6

Please sign in to comment.