Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/src/components/HealthCareProvider/HCManageDoctors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const HCManageDoctors: FunctionComponent<{}> = () => {
<tbody className='bg-white divide-y divide-gray-200'>
{doctorToProviderReqList &&
doctorToProviderReqList.length > 0 &&
doctorToProviderReqList.map((req) => (
<tr>
doctorToProviderReqList.map((req, idx) => (

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index based map is not suggested

<tr key={idx}>
<td className='px-6 py-4 whitespace-nowrap'>
<div className='text-sm text-gray-900'>{req.name}</div>
</td>
Expand All @@ -85,7 +85,7 @@ const HCManageDoctors: FunctionComponent<{}> = () => {
className='bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded'
onClick={() => {
if (currentAccount) {
updateProfile?.(currentAccount, req.address, 'rejected');
updateProfile?.(currentAccount, req.address, 'rejected', idx);
}
}}
>
Expand All @@ -96,7 +96,7 @@ const HCManageDoctors: FunctionComponent<{}> = () => {
className='bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded'
onClick={() => {
if (currentAccount) {
updateProfile?.(currentAccount, req.address, 'confirmed');
updateProfile?.(currentAccount, req.address, 'confirmed', idx);
}
}}
//updateStatus('confirmed', appointment.appointment_id)
Expand Down
26 changes: 22 additions & 4 deletions client/src/contracts/HealthBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export interface HealthBlockInterface extends utils.Interface {
"getHCProviderInfoAll(address)": FunctionFragment;
"registerHCProvider(string,string,string,string)": FunctionFragment;
"getAllDoctorsForProvider(address)": FunctionFragment;
"mapDoctorToProvider(address,address)": FunctionFragment;
"declineDoctorToProviderRequest(address,address)": FunctionFragment;
"mapDoctorToProvider(address,address,uint256)": FunctionFragment;
"declineDoctorToProviderRequest(address,address,uint256)": FunctionFragment;
"raiseDoctorToProviderRequest(address,address,string)": FunctionFragment;
"getAllDoctorToProviderRequests(address)": FunctionFragment;
};
Expand Down Expand Up @@ -205,11 +205,19 @@ export interface HealthBlockInterface extends utils.Interface {
): string;
encodeFunctionData(
functionFragment: "mapDoctorToProvider",
values: [PromiseOrValue<string>, PromiseOrValue<string>]
values: [
PromiseOrValue<string>,
PromiseOrValue<string>,
PromiseOrValue<BigNumberish>
]
): string;
encodeFunctionData(
functionFragment: "declineDoctorToProviderRequest",
values: [PromiseOrValue<string>, PromiseOrValue<string>]
values: [
PromiseOrValue<string>,
PromiseOrValue<string>,
PromiseOrValue<BigNumberish>
]
): string;
encodeFunctionData(
functionFragment: "raiseDoctorToProviderRequest",
Expand Down Expand Up @@ -530,12 +538,14 @@ export interface HealthBlock extends BaseContract {
mapDoctorToProvider(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;

declineDoctorToProviderRequest(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;

Expand Down Expand Up @@ -666,12 +676,14 @@ export interface HealthBlock extends BaseContract {
mapDoctorToProvider(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;

declineDoctorToProviderRequest(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;

Expand Down Expand Up @@ -804,12 +816,14 @@ export interface HealthBlock extends BaseContract {
mapDoctorToProvider(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: CallOverrides
): Promise<void>;

declineDoctorToProviderRequest(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: CallOverrides
): Promise<void>;

Expand Down Expand Up @@ -976,12 +990,14 @@ export interface HealthBlock extends BaseContract {
mapDoctorToProvider(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<BigNumber>;

declineDoctorToProviderRequest(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<BigNumber>;

Expand Down Expand Up @@ -1086,12 +1102,14 @@ export interface HealthBlock extends BaseContract {
mapDoctorToProvider(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<PopulatedTransaction>;

declineDoctorToProviderRequest(
_providerAddress: PromiseOrValue<string>,
_doctorAddress: PromiseOrValue<string>,
idx: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<PopulatedTransaction>;

Expand Down
12 changes: 11 additions & 1 deletion client/src/contracts/factories/HealthBlock__factory.ts

Large diffs are not rendered by default.

31 changes: 23 additions & 8 deletions client/src/providers/HealthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ interface HealthAppContextInterface {
connectWallet?: () => Promise<void>;
healthBlockContract?: () => Promise<void>;
registerHealthBlockContract?: (name: string, age: number, email: string) => Promise<void>;
updateProfile?: (hcAddress: string, docAddress: string, status: string) => Promise<void>;
updateProfile?: (
hcAddress: string,
docAddress: string,
status: string,
idx: number,
) => Promise<void>;
registerDoctorHealthBlockContract?: (
name: string,
age: number,
Expand Down Expand Up @@ -290,10 +295,16 @@ export const HealthProvider: React.FC<Props> = ({ children, ...props }) => {

setDoctorList(docArr);
} catch (error) {
setError('Error Loading Health Contract');
throw error;
// setError('Error Loading Health Contract');
}
};
const updateProfile = async (hcAddress: string, docAddress: string, status: string) => {
const updateProfile = async (
hcAddress: string,
docAddress: string,
status: string,
idx: number,
) => {
try {
const web3modal = new Web3Modal();
const connection = await web3modal.connect();
Expand All @@ -302,14 +313,15 @@ export const HealthProvider: React.FC<Props> = ({ children, ...props }) => {
const contract: HealthBlock = fetchContract(signer);
let update;
if (status == 'confirmed') {
update = await contract.mapDoctorToProvider(hcAddress, docAddress);
update = await contract.mapDoctorToProvider(hcAddress, docAddress, idx);
} else {
update = await contract.declineDoctorToProviderRequest(hcAddress, docAddress);
update = await contract.declineDoctorToProviderRequest(hcAddress, docAddress, idx);
}

update.wait();
} catch (err: any) {
setError(`Error Loading Health Contract ${err}`);
throw err;
//setError(`Error Loading Health Contract ${err}`);
}
};

Expand All @@ -323,6 +335,7 @@ export const HealthProvider: React.FC<Props> = ({ children, ...props }) => {
const doctors = await contract.getAllDoctorToProviderRequests(
'0xb3cc507e752dcc3da1cef955b58e97ae77160103',
);

let docArr = [];
for (let i = 0; i < doctors.length; i++) {
let obj = {
Expand All @@ -335,7 +348,8 @@ export const HealthProvider: React.FC<Props> = ({ children, ...props }) => {

setDocToProviderList(docArr);
} catch (err: any) {
setError(`Error Loading Health Contract ${err}`);
throw err;
//setError(`Error Loading Health Contract ${err}`);
}
};

Expand All @@ -352,7 +366,8 @@ export const HealthProvider: React.FC<Props> = ({ children, ...props }) => {
const contract: HealthBlock = fetchContract(signer);
const update = await contract.raiseDoctorToProviderRequest(hcAddress, docAddress, doctorName);
} catch (err: any) {
setError(`Error Loading Health Contract ${err}`);
//setError(`Error Loading Health Contract ${err}`);
throw err;
}
};

Expand Down
35 changes: 8 additions & 27 deletions contracts/HealthBlock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,39 +176,20 @@ contract HealthBlock {
function getAllDoctorsForProvider(address providerAddress) public view returns (doctor[] memory) {
return providerToDoctors[providerAddress];
}
function mapDoctorToProvider(address _providerAddress, address _doctorAddress) public{
function mapDoctorToProvider(address _providerAddress, address _doctorAddress, uint256 idx) public{
doctor storage d = doctors[_doctorAddress];
uint8 idx =0;
bool found = false;
for(uint8 i =0;i< providerToDoctorRequests[_providerAddress].length;i++){
if(providerToDoctorRequests[_providerAddress][i].doctorAddr == _doctorAddress){
idx = i;
break;
found = true;
}
}

providerToDoctorRequests[_providerAddress][idx].status = 'confirmed';
providerToDoctors[_providerAddress].push(doctor({name:d.name,email:d.email,specialization:d.specialization,id:_doctorAddress,age:d.age}));
DoctorToProviderRequest storage request = providerToDoctorRequests[_providerAddress][idx];
request.status="confirmed";
providerToDoctors[_providerAddress].push(doctor({name:d.name,email:d.email,specialization:d.specialization,id:_doctorAddress,age:d.age}));

}

function declineDoctorToProviderRequest(address _providerAddress, address _doctorAddress) public{
function declineDoctorToProviderRequest(address _providerAddress, address _doctorAddress,uint256 idx) public{
doctor storage d = doctors[_doctorAddress];
uint8 idx =0;
bool found = false;
for(uint8 i =0;i< providerToDoctorRequests[_providerAddress].length;i++){
if(providerToDoctorRequests[_providerAddress][i].doctorAddr == _doctorAddress){
idx = i;
break;
found = true;
}
}
DoctorToProviderRequest storage request = providerToDoctorRequests[_providerAddress][idx];
request.status ="rejected";

providerToDoctorRequests[_providerAddress][idx].status = 'rejected';


}
}



Expand Down