Skip to content

Commit 29900d2

Browse files
Fixes in BAH-4119 (#100)
* BAH-4119.Get ABHA Card button removed when the user follows QR Scanning feature. * BAH-4119. Fix format of Abha number for existing patient. * BAH-4119. Show matching patient when verifying using Abha Address. * BAH-4119. Refactored the code to avoid potential errors and increase the readability of the code. --------- Co-authored-by: arshiyaTW2021 <arshiya.flamingo@gmail.com>
1 parent e379517 commit 29900d2

File tree

2 files changed

+54
-23
lines changed

2 files changed

+54
-23
lines changed

src/api/constants.js

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ export const serviceUnavailableError = {
5252
"message": "Service Unavailable. Please try again later"
5353
}
5454
}
55+
export const abhaAddressUnavailableError = {
56+
"error": {
57+
"message": "Please enter ABHA Address."
58+
}
59+
}
60+
export const inactiveAbhaAddressError = {
61+
"error": {
62+
"message": "Abha address is not active."
63+
}
64+
}
5565
export const invalidHealthId = {
5666
"error": {
5767
"message": "Health Id/PHR Address is invalid. " +
@@ -76,3 +86,4 @@ export const openMrsDown = {
7686
"message": "OpenMRS-REST is Unhealthy,OpenMRS-FHIR is Unhealthy"
7787
}
7888
}
89+
export const activeStatus = "ACTIVE"

src/components/verifyHealthId/verifyHealthId.jsx

+43-23
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import { FcWebcam } from 'react-icons/fc';
1212
import './verifyHealthId.scss';
1313
import DemoAuth from "../demo-auth/demoAuth";
1414
import CreateHealthId from "../otp-verification/create-healthId";
15-
import {enableHealthIdVerificationThroughMobileNumber} from "../../api/constants";
15+
import {
16+
abhaAddressUnavailableError, activeStatus,
17+
enableHealthIdVerificationThroughMobileNumber,
18+
inactiveAbhaAddressError
19+
} from "../../api/constants";
1620
import VerifyHealthIdThroughMobileNumber from "./verifyHealthIdThroughMobileNumber";
1721
import { formatAbhaNumber, validateAbhaNumber } from "../Common/FormatAndValidationUtils";
1822
import VerifyThroughAadhaarNumber from "./verifyThroughAadhaarNumber";
@@ -41,6 +45,8 @@ const VerifyHealthId = () => {
4145
const [isMobileOtpVerified, setIsMobileOtpVerified] = useState(false);
4246
const [isVerifyByAbhaAddress, setIsVerifyByAbhaAddress] = useState(false);
4347
const [selectedIdentifierType, setSelectedIdentifierType] = useState('');
48+
const [enableABHACardView, setEnableABHACardView] = useState(true);
49+
4450

4551
function identifierTypeOnChangeHandler(e) {
4652
setShowError(false);
@@ -70,10 +76,10 @@ const VerifyHealthId = () => {
7076
setErrorMessage("Invalid ABHA Number. ABHA Number should be 14 digits");
7177
return;
7278
}
79+
const formattedAbhaNumber = formatAbhaNumber(abhaNumber);
7380
setLoader(true);
7481
setShowError(false);
75-
setIsVerifyByAbhaAddress(false);
76-
const matchingPatientId = await fetchPatientFromBahmniWithHealthId(abhaNumber);
82+
const matchingPatientId = await fetchPatientFromBahmniWithHealthId(formattedAbhaNumber);
7783
const healthIdStatus = matchingPatientId.Error !== undefined ? await getHealthIdStatus(matchingPatientId.patientUuid) : false;
7884
if (matchingPatientId.Error === undefined) {
7985
if(healthIdStatus === true)
@@ -95,34 +101,44 @@ const VerifyHealthId = () => {
95101
}
96102

97103
async function searchByAbhaAddress() {
98-
setShowError(false);
99-
setErrorMessage('');
100-
if(abhaAddress === ''){
104+
if(!abhaAddress?.trim()){
101105
setShowError(true);
102-
setErrorMessage("Please enter ABHA Address");
106+
setErrorMessage(abhaAddressUnavailableError.error.message);
103107
return;
104108
}
105109
setLoader(true);
106-
const response = await searchAbhaAddress(abhaAddress);
107-
setLoader(false);
108-
setIsVerifyByAbhaAddress(true);
109-
if(response.data !== undefined){
110-
setIsVerifyThroughABHAService(true);
111-
if(response.data.status === "ACTIVE") {
112-
setShowAuthModes(true);
113-
setAuthModes(response.data.authMethods !== undefined ?
114-
response.data.authMethods.filter(e => supportedHealthIdAuthModes.includes(e)) : []);
115-
}
116-
else
117-
{
118-
setShowError(true)
119-
setErrorMessage("Abha address is not active");
110+
setShowError(false);
111+
setErrorMessage('');
112+
const existingPatientId = await fetchPatientFromBahmniWithHealthId(abhaAddress);
113+
const healthIdStatus = existingPatientId?.Error ? await getHealthIdStatus(existingPatientId.patientUuid) : false;
114+
if (existingPatientId?.Error === undefined) {
115+
if (healthIdStatus === true)
116+
setHealthIdIsVoided(true);
117+
else if (existingPatientId?.validPatient === true) {
118+
setMatchingPatientFound(true);
119+
setMatchingPatientUuid(existingPatientId.patientUuid);
120+
} else {
121+
const response = await searchAbhaAddress(abhaAddress);
122+
setLoader(false);
123+
setIsVerifyByAbhaAddress(true);
124+
if (response.data !== undefined) {
125+
setIsVerifyThroughABHAService(true);
126+
if (response.data.status === activeStatus) {
127+
setShowAuthModes(true);
128+
setAuthModes(response.data.authMethods !== undefined ?
129+
response.data.authMethods.filter(e => supportedHealthIdAuthModes.includes(e)) : []);
130+
} else {
131+
setShowError(true)
132+
setErrorMessage(inactiveAbhaAddressError.error.message);
133+
}
134+
}
120135
}
121136
}
122137
else {
123138
setShowError(true)
124-
setErrorMessage(response.error.message);
139+
setErrorMessage(existingPatientId.error.message);
125140
}
141+
setLoader(false);
126142
}
127143

128144
function getIfVaild(str){
@@ -157,6 +173,7 @@ const VerifyHealthId = () => {
157173
}
158174

159175
async function handleScan(scannedData) {
176+
setEnableABHACardView(false);
160177
if (scannedData != null) {
161178
var ndhmDetails = mapToNdhmDetails(scannedData)
162179
setScanningStatus(false);
@@ -288,7 +305,10 @@ const VerifyHealthId = () => {
288305
{isDemoAuth && !checkIfNotNull(ndhmDetails) && <DemoAuth id={abhaNumber} ndhmDetails={ndhmDetails} setNdhmDetails={setNdhmDetails} setBack={setBack}/>}
289306
{(isVerifyThroughABHASerice || isVerifyThroughMobileNumberEnabled) && checkIfNotNull(ndhmDetails) && ndhmDetails.id === undefined && <CreateHealthId ndhmDetails={ndhmDetails} setNdhmDetails={setNdhmDetails} setIsHealthIdCreated={setIsHealthIdCreated} />}
290307
{!matchingPatientFound && !healthIdIsVoided && checkIfNotNull(ndhmDetails) && (ndhmDetails.id !== undefined || isHealthIdCreated || isVerifyABHAThroughFetchModes)
291-
&& <PatientDetails enableABHACardView={true} ndhmDetails={ndhmDetails} id={abhaNumber} setBack={setBack} isVerifyABHAThroughFetchModes={isVerifyABHAThroughFetchModes || !isHealthIdCreated} isVerifyByAbhaAddress={isVerifyByAbhaAddress}/>}
308+
&& <PatientDetails enableABHACardView={enableABHACardView} ndhmDetails={ndhmDetails} id={abhaNumber}
309+
setBack={setBack}
310+
isVerifyABHAThroughFetchModes={isVerifyABHAThroughFetchModes || !isHealthIdCreated}
311+
isVerifyByAbhaAddress={isVerifyByAbhaAddress}/>}
292312
</div>
293313
);
294314
}

0 commit comments

Comments
 (0)