I have the following Solidity code that compiles and tests okay, but the insurancePlan property of the Patient struct is not being saved. I've tried many variations and it is just blank (empty) when I go to access the property. Any help would be appreciated.
contract Prescription {
// Define patient struct
struct Patient {
address patient;
bool insured;
string insurancePlan;
Rx[] prescriptions;
}
// Define prescription struct
struct Rx {
uint cost;
string code;
string description;
uint quantity;
bool active;
bool refill;
}
Patient[] public patients;
/******************************
* Create a new patient *
*******************************/
function newPatient(address _patient, bool _insured, string memory _insurancePlan) external {
Patient storage patient = patients.push();
patient.patient = _patient;
patient.insured = _insured;
patient.insurancePlan = _insurancePlan;
Rx storage prescription = patient.prescriptions.push();
prescription.cost = 0;
prescription.code = "none";
prescription.description = "none";
prescription.quantity = 0;
prescription.active = false;
prescription.refill = false;
}
I am then accessing the information using the following method:
/******************************
* Return a patient *
*******************************/
function getPatient(address _patient)
public
view
returns(address patient, bool insured, string memory insurancePlan, Rx[] memory prescriptions)
{
for(uint i = 0; i < patients.length; i++) {
if(patients[i].patient == _patient) {
return (patients[i].patient, patients[i].insured, patients[i].insurancePlan, patients[i].prescriptions);
}
}
}