I'm getting error "Copying of type struct MedicalRecord memory[] memory to storage not supported yet" from the below code:
struct Patient {
bytes32 name;
uint256 age;
bytes32 gender;
uint256 doctorId;
address patientWallet;
MedicalRecord[] medicalRecords;
}

struct MedicalRecord {
bytes32 diagnosis;
bytes32 prescription;
bytes32 notes;
uint256 timestamp;
}

// A snippet from addPatient()
patients[patientId] = Patient({
name: _name,
age: _age,
gender: _gender,
doctorId: _doctorId,
patientWallet: _patientWallet,
medicalRecords: new MedicalRecord[](0)
});

I want to add Patient with an empty array but getting this error.
Any idea how can I make solve this?

Feb 6, 2023, 7:37 AM
Try this
struct Patient {
bytes32 name;
uint256 age;
bytes32 gender;
uint256 doctorId;
address patientWallet;
uint256[] medicalRecordIds;
}

mapping (uint256 => MedicalRecord) medicalRecords;

struct MedicalRecord {
bytes32 diagnosis;
bytes32 prescription;
bytes32 notes;
uint256 timestamp;
}

// A snippet from addPatient()
uint256 medicalRecordId = medicalRecords.length;
patients[patientId] = Patient({
name: _name,
age: _age,
gender: _gender,
doctorId: _doctorId,
patientWallet: _patientWallet,
medicalRecordIds: new uint256[](0)
});
medicalRecords[medicalRecordId] = MedicalRecord({
diagnosis: "",
prescription: "",
notes: "",
timestamp: 0
});
To solve it create a mapping to store the MedicalRecords and store the mapping's index in the Patient struct.
Feb 6, 2023, 7:51 AM
Let me, thanks in advance brother
Feb 6, 2023, 7:54 AM
Try it , will work well
be sure verify that it compiles without any errors.
In Remix, select the "Run" tab and change the environment to "Polygon (Polygon mainnet)".a
Connect to your Ethereum wallet by clicking on the "Connect to Wallet" button in the top right corner.
In the Run tab, select the "Deploy" button.
In the Run tab, select the "Deploy" button.
Feb 6, 2023, 7:59 AM
there is no compile error
deploy in other chain is possible
error occurs in deploying on polygon mainnet
Feb 6, 2023, 8:02 AM
Polygon mainnet requires a fee to be paid in POLY to deploy a smart contract. Make sure you have enough POLY in your wallet to cover the fee.
Feb 6, 2023, 8:07 AM
wtf?
deploy and see
Feb 6, 2023, 8:21 AM
I have enough fee in my wallet
Feb 6, 2023, 10:54 AM

© 2024 Draquery.com All rights reserved.