Skip to content

Commit

Permalink
BAH-3459 | Refactor. Abha Creation (#83)
Browse files Browse the repository at this point in the history
* BAH-3459 | Refactor. shouldn't proceed to update if ABHA Number linked to the matching patient

* BAH-3459 | Add. create default abha address

* BAH-3459 | Refactor. to display create default option for ABHA Number which doesn't linked to any ABHA Address
  • Loading branch information
SanoferSameera authored Jan 17, 2024
1 parent 04bfc9e commit 581adae
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 30 deletions.
9 changes: 9 additions & 0 deletions src/api/hipServiceApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,12 @@ export const fetchGlobalProperty = async (property) => {
return Constants.openMrsDown;
}
}

export const checkIfHealthNumberExists = async (patientUuid) => {
try {
const response = await axios.get(Constants.bahmniUrl + Constants.existingPatientUrl + "/checkHealthNumber/" + patientUuid, Constants.headers);
return response.data;
} catch (error) {
return Constants.openMrsDown;
}
}
21 changes: 19 additions & 2 deletions src/components/Common/CheckIdentifierExists.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, {useEffect, useState} from "react";
import {fetchPatientFromBahmniWithHealthId, getHealthIdStatus} from '../../api/hipServiceApi';
import {
checkIfHealthNumberExists,
fetchPatientFromBahmniWithHealthId,
getHealthIdStatus
} from '../../api/hipServiceApi';
import '../verifyHealthId/verifyHealthId.scss';

const CheckIdentifierExists = (props) => {
Expand All @@ -8,6 +12,7 @@ const CheckIdentifierExists = (props) => {
const [healthIdIsVoided, setHealthIdIsVoided] = useState(false);
const [errorHealthId, setErrorHealthId] = useState('');
const [showError, setShowError] = useState(false);
const [matchingPatientHasHealthIdNumberLinked, setMatchingPatientHasHealthIdNumberLinked] = useState(false);

async function checkIfAlreadyExistingIdentifier(id) {
if(props.setHealthIdIsVoided !== undefined)
Expand All @@ -30,6 +35,11 @@ const CheckIdentifierExists = (props) => {
else {
setMatchingPatientFound(true);
setMatchingPatientUuid(matchingPatientId.patientUuid);
const response = await checkIfHealthNumberExists(matchingPatientId.patientUuid);
if (response.Error === undefined && response !== "") {
props?.setHealthNumberAlreadyLinked(response);
setMatchingPatientHasHealthIdNumberLinked(response);
}
}
if(props.setMatchingPatientUuid !== undefined)
props?.setMatchingPatientUuid(matchingPatientId.patientUuid);
Expand All @@ -47,9 +57,16 @@ const CheckIdentifierExists = (props) => {
await checkIfAlreadyExistingIdentifier(props.id);
},[props.id])

function redirectToPatientDashboard() {
window.parent.postMessage({"patientUuid" : matchingpatientUuid}, "*");
}

return (
<div>
{matchingPatientFound && <div className="matched-patient-info">Matching record with {props.id} found. Please proceed to update the record</div>}
{matchingPatientFound && !matchingPatientHasHealthIdNumberLinked && <div className="matched-patient-info">Matching record with {props.id} found. Please proceed to update the record with ABHA Number</div>}
{matchingPatientFound && matchingPatientHasHealthIdNumberLinked && <div className="patient-existed" onClick={redirectToPatientDashboard}>
Matching record with {props.id} found
</div>}
{healthIdIsVoided && <div className="id-deactivated">
{props.id} is deactivated
</div>}
Expand Down
62 changes: 42 additions & 20 deletions src/components/creation/CreateABHAAddress.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useState} from "react";
import './creation.scss';
import Spinner from "../spinner/spinner";
import {checkIfABHAAddressExists, createABHAAddress} from "../../api/hipServiceApi";
import {checkIfABHAAddressExists, createABHAAddress, createDefaultHealthId} from "../../api/hipServiceApi";
import Footer from "./Footer";
import {cmSuffixProperty} from "../../api/constants";

Expand Down Expand Up @@ -35,6 +35,7 @@ const CreateABHAAddress = (props) => {
if (response.data === undefined) {
processingError(response);
} else {
setNewAbhaAddress(newAbhaAddress.concat(cmSuffix));
props.setABHAAddressCreated(true);
}
}
Expand All @@ -51,6 +52,20 @@ const CreateABHAAddress = (props) => {
}
}

async function createDefault() {
setLoader(true);
setError('');
const response = await createDefaultHealthId();
if (response.data !== undefined) {
setNewAbhaAddress(response.data.healthId);
props.setABHAAddressCreated(true);
}
else {
setError(response.details[0].message || response.message)
}
setLoader(false);
}

function processingError(response){
if (response.details !== undefined && response.details.length > 0)
setError(response.details[0].message)
Expand All @@ -64,28 +79,35 @@ const CreateABHAAddress = (props) => {

return (
<div>
<div>
<div className="abha-address" >
<label htmlFor="abhaAdddress">Enter new ABHA ADDRESS </label>
<div className="abha-adddress-input" >
<div className="new-abha-address-input">
<input type="text" id="abhaAdddress" name="abhaAdddress" value={newAbhaAddress} onChange={OnChangeHandler} />
<span className="abha-address-suffix">{cmSuffix}</span>
</div>
<div className="abha-address" >
<label htmlFor="abhaAdddress">Enter new ABHA ADDRESS </label>
<div className="abha-adddress-input" >
<div className="new-abha-address-input">
<input type="text" id="abhaAdddress" name="abhaAdddress" value={newAbhaAddress} onChange={OnChangeHandler} />
<span className="abha-address-suffix">{cmSuffix}</span>
</div>
</div>
<div className="center" >
<input type="checkbox" id="preferred" checked={isPreferred} className="checkbox" onChange={OnClick}/>
<span className="preferred"> Preferred </span>
</div>
<p className="message">Click on the check box to make the above abha-address as a default</p>
{error !== '' && <h6 className="error">{error}</h6>}
{loader && <Spinner />}
<div className="center">
<button type="button" className="proceed" onClick={onCreate}>Create</button>
</div>
<Footer setBack={props.setBack} />
</div>
<div className="center" >
<input type="checkbox" id="preferred" checked={isPreferred} className="checkbox" onChange={OnClick}/>
<span className="preferred"> Preferred </span>
</div>
<p className="message">Click on the check box to make the above abha-address as a default</p>
<div className="center">
<button type="button" className="proceed" onClick={onCreate}>Create</button>
</div>
{props?.showCreateDefaultOption !== undefined && props?.showCreateDefaultOption &&
<div>
<div className="alternative-text">
OR
</div>
<div className="create-default-healthId">
<button name="default-healthId-btn" type="button" onClick={createDefault}>Create Default ABHA Address</button>
</div>
</div>}
{loader && <Spinner />}
{error !== '' && <h6 className="error">{error}</h6>}
<Footer setBack={props.setBack} />
</div>
);
}
Expand Down
19 changes: 11 additions & 8 deletions src/components/creation/LinkABHAAddress.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './creation.scss';
import PatientDetails from "../patient-details/patientDetails";
import VerifyMobileEmail from "./VerifyMobileEmail";
import CreateABHAAddress from "./CreateABHAAddress";
import {cmSuffixProperty, enableLinkABHAAddress} from "../../api/constants";
import {enableLinkABHAAddress} from "../../api/constants";
import CheckIdentifierExists from "../Common/CheckIdentifierExists";
import {fetchGlobalProperty} from "../../api/hipServiceApi";

Expand All @@ -19,10 +19,9 @@ const LinkABHAAddress = (props) => {
const [healthIdIsVoided, setHealthIdIsVoided] = useState(false);
const [matchingPatientUuid, setMatchingPatientUuid] = useState(undefined);
const [isAbhaSelected, setIsAbhaSelected] = useState(false);
const [healthNumberAlreadyLinked, setHealthNumberAlreadyLinked] = useState(false);
let isLinkingEnabled;
const refEls = useRef({});

const cmSuffix = localStorage.getItem(cmSuffixProperty)

function onProceed() {
mapPatient();
Expand Down Expand Up @@ -64,7 +63,7 @@ const LinkABHAAddress = (props) => {


function mapPatient(){
props.mappedPatient.id = abhaAddressCreated ? newAbhaAddress.concat(cmSuffix) : abhaAddress;
props.mappedPatient.id = abhaAddressCreated ? newAbhaAddress : abhaAddress;
}

function gotoLink(){
Expand Down Expand Up @@ -100,10 +99,13 @@ const LinkABHAAddress = (props) => {
<div>
{patient.phrAddress === undefined &&
<div className="no-abha-address">
<p className="note">No ABHA address found linked to the ABHA number</p>
<p className="note">You don't have ABHA Address/ Health Id linked to your ABHA Number</p>
<p className="note">
{isLinkingEnabled && <> Please proceed with linking the ABHA address that is already mapped to the mobile number or email, or </>}
create a new ABHA address</p>
{!isLinkingEnabled &&
<CreateABHAAddress setBack={setBack} newAbhaAddress={newAbhaAddress} setNewAbhaAddress={setNewAbhaAddress} setABHAAddressCreated={setABHAAddressCreated} showCreateDefaultOption={true}/>
}
</div>}
{patient.phrAddress !== undefined &&
<div>
Expand All @@ -113,18 +115,19 @@ const LinkABHAAddress = (props) => {
</div>
{phrAddressList}
</div>
{isAbhaSelected && <CheckIdentifierExists id={abhaAddress} setHealthIdIsVoided={setHealthIdIsVoided} setMatchingPatientUuid={setMatchingPatientUuid}/>}
{isAbhaSelected && <CheckIdentifierExists id={abhaAddress} setHealthIdIsVoided={setHealthIdIsVoided} setMatchingPatientUuid={setMatchingPatientUuid} setHealthNumberAlreadyLinked={setHealthNumberAlreadyLinked}/>}
{abhaAddress !== '' && <div className="center">
<button type="button" disabled={healthIdIsVoided || !isAbhaSelected? true : false} className="proceed" onClick={onProceed}>Proceed</button>
<button type="button" disabled={healthNumberAlreadyLinked || healthIdIsVoided || !isAbhaSelected? true : false} className="proceed" onClick={onProceed}>Proceed</button>
</div>}
</div>}

{isLinkingEnabled && <div className="left-button">
<button type="button" disabled={isAbhaSelected ? true : false} className="proceed" title="Link exisiting ABHA Address linked to Mobile/Email" onClick={gotoLink}>Link ABHA Address</button>
</div>}

<div className={isLinkingEnabled ? "right-button" :"create-new-abhaAddress"}>
<button type="button" disabled={isAbhaSelected ? true : false} className="proceed" title="Create new ABHA Address" onClick={gotoCreate}>Create ABHA Address</button>
</div>
</div>}
</div>}
{!proceed && createNewABHA &&
<CreateABHAAddress setBack={setBack} newAbhaAddress={newAbhaAddress} setNewAbhaAddress={setNewAbhaAddress} setABHAAddressCreated={setABHAAddressCreated} />
Expand Down
5 changes: 5 additions & 0 deletions src/components/creation/creation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
color: red;
margin-top: 0px;
}

.create-default-healthId {
margin-left: 40%;
margin-top: 5%
}
}

button {
Expand Down

0 comments on commit 581adae

Please sign in to comment.