// SPDX 许可证标识符:[`
`MIT`
pragma solidity >=0.5.0 <0.9.0;
contract Record {
struct Patients {
string ic;
string name;
string phone;
string gender;
string dob;
string height;
string weight;
string houseaddr;
string bloodgroup;
string allergies;
string medication;
string emergencyName;
string emergencyContact;
address addr;
uint date;
}
struct Doctors {
string ic;
string name;
string phone;
string gender;
string dob;
string qualification;
string major;
address addr;
uint date;
}
struct Appointments {
address doctoraddr;
address patientaddr;
string date;
string time;
string prescription;
string description;
string diagnosis;
string status;
uint creationDate;
}
address public owner;
address[] public patientList;
address[] public doctorList;
address[] public appointmentList;
mapping(address => Patients) patients;
mapping(address => Doctors) doctors;
mapping(address => Appointments) appointments;
mapping(address => mapping(address => bool)) isApproved;
mapping(address => bool) isPatient;
mapping(address => bool) isDoctor;
mapping(address => uint) AppointmentPerPatient;
uint256 public patientCount = 0;
uint256 public doctorCount = 0;
uint256 public appointmentCount = 0;
uint256 public permissionGrantedCount = 0;
function record() public {
// Record -> record;
owner = msg.sender;
}
//Retrieve patient details from user sign up page and store the details into the blockchain
function setDetails(
string memory _ic,
string memory _name,
string memory _phone,
string memory _gender,
string memory _dob,
string memory _height,
string memory _weight,
string memory _houseaddr,
string memory _bloodgroup,
string memory _allergies,
string memory _medication,
string memory _emergencyName,
string memory _emergencyContact
) public {
require(!isPatient[msg.sender]);
Patients storage p = patients[msg.sender];
p.ic = _ic;
p.name = _name;
p.phone = _phone;
p.gender = _gender;
p.dob = _dob;
p.height = _height;
p.weight = _weight;
p.houseaddr = _houseaddr;
p.bloodgroup = _bloodgroup;
p.allergies = _allergies;
p.medication = _medication;
p.emergencyName = _emergencyName;
p.emergencyContact = _emergencyContact;
p.addr = msg.sender;
p.date = block.timestamp;
patientList.push(msg.sender);
isPatient[msg.sender] = true;
isApproved[msg.sender][msg.sender] = true;
patientCount++;
}
//Allows patient to edit their existing record
function editDetails(
string memory _ic,
string memory _name,
string memory _phone,
string memory _gender,
string memory _dob,
string memory _height,
string memory _weight,
string memory _houseaddr,
string memory _bloodgroup,
string memory _allergies,
string memory _medication,
string memory _emergencyName,
string memory _emergencyContact
) public {
require(isPatient[msg.sender]);
Patients storage p = patients[msg.sender];
p.ic = _ic;
p.name = _name;
p.phone = _phone;
p.gender = _gender;
p.dob = _dob;
p.height = _height;
p.weight = _weight;
p.houseaddr = _houseaddr;
p.bloodgroup = _bloodgroup;
p.allergies = _allergies;
p.medication = _medication;
p.emergencyName = _emergencyName;
p.emergencyContact = _emergencyContact;
p.addr = msg.sender;
}
//Retrieve patient details from doctor registration page and store the details into the blockchain
function setDoctor(
string memory _ic,
string memory _name,
string memory _phone,
string memory _gender,
string memory _dob,
string memory _qualification,
string memory _major
) public {
require(!isDoctor[msg.sender]);
Doctors storage d = doctors[msg.sender];
d.ic = _ic;
d.name = _name;
d.phone = _phone;
d.gender = _gender;
d.dob = _dob;
d.qualification = _qualification;
d.major = _major;
d.addr = msg.sender;
d.date = block.timestamp;
doctorList.push(msg.sender);
isDoctor[msg.sender] = true;
doctorCount++;
}
//Allows doctors to edit their existing profile
function editDoctor(
string memory _ic,
string memory _name,
string memory _phone,
string memory _gender,
string memory _dob,
string memory _qualification,
string memory _major
) public {
require(isDoctor[msg.sender]);
Doctors storage d = doctors[msg.sender];
d.ic = _ic;
d.name = _name;
d.phone = _phone;
d.gender = _gender;
d.dob = _dob;
d.qualification = _qualification;
d.major = _major;
d.addr = msg.sender;
}
//Retrieve appointment details from appointment page and store the details into the blockchain`
function setAppointment(
address _addr,
string memory _date,
string memory _time,
string memory _diagnosis,
string memory _prescription,
string memory _description,
string memory _status
) public {
require(isDoctor[msg.sender]);
Appointments storage a = appointments[_addr];
a.doctoraddr = msg.sender;
a.patientaddr = _addr;
a.date = _date;
a.time = _time;
a.diagnosis = _diagnosis;
a.prescription = _prescription;
a.description = _description;
a.status = _status;
a.creationDate = block.timestamp;
appointmentList.push(_addr);
appointmentCount++;
AppointmentPerPatient[_addr]++;
}
//Retrieve appointment details from appointment page and store the details into the blockchain
function updateAppointment(
address _addr,
string memory _date,
string memory _time,
string memory _diagnosis,
string memory _prescription,
string memory _description,
string memory _status
) public {
require(isDoctor[msg.sender]);
Appointments storage a = appointments[_addr];
a.doctoraddr = msg.sender;
a.patientaddr = _addr;
a.date = _date;`your text`
a.time = _time;
a.diagnosis = _diagnosis;
a.prescription = _prescription;
a.description = _descriptio`your text`n;
a.status = _status;
}
//Owner of the record must give permission to doctor only they are allowed to view records
function givePermission(address _address) public returns`
$ /mnt/c/Codeeater/node_modules/.bin/hardhat 运行脚本/major_project.js 编译器错误:堆栈太深。尝试使用
--via-ir
(cli) 或等效的 viaIR: true
(标准 JSON)进行编译,同时启用优化器。否则,尝试删除局部变量。编译内联汇编时:变量 dataEnd 是堆栈内太深的 1 个槽。堆叠太深。尝试使用 --via-ir
(cli) 或等效的 viaIR: true
(标准 JSON)进行编译,同时启用优化器。否则,尝试删除局部变量。
**我在编译上述代码时遇到这些错误**``](https://stackoverflow.com) `
发生此错误是因为 EVM 在函数中限制了 16 个变量。如果它尝试访问 slot16 或更高版本(0 索引)中的变量,您将收到此错误。
您因以下功能而遇到问题:
setDetails
和editDetails
。
要修复此错误,您可以发送
struct
而不是单个变量,例如:
function setDetails(Patients memory patient) {
require(!isPatient[msg.sender]);
patients[msg.sender] = patient;
patients[msg.sender].addr = msg.sender;
patients[msg.sender].date = block.timestamp;
patientList.push(msg.sender);
isPatient[msg.sender] = true;
isApproved[msg.sender][msg.sender] = true;
patientCount++;
}
您可以对
editDetails
进行类似的操作。