Date
itself is considered a uint
and not a string
as it is represented in unix timestamp https://www.unixtimestamp.com/. In order to achieve what you want, your mapping should look like this:
mapping(address=>mapping(uint=>string))
And your function parameter _date
should be a uint
:
function addPatientrecord(uint _date,string memory _disease) public{}
Also, the patient record as far as I see will only be accessed by a hospital employee, so the msg.sender
will be the employee, not the patient itself, hence imo the address should be replaced with an ID of the patient to keep track of the records of the patient with that specific ID. This can be achieved as follows:
mapping(uint=> mapping(uint=>string)
UPDATE
To access multiple details of a record based on a key, you can use a struct.
struct PatientRecord{
uint ID;
uint date;
string disease;
}
and then map that structure to a key which in your case would be an address, although I think the ID would make more sense. For that the mapping would be as follows:
For address
:
mapping(address => PatientRecord[]) pAddressToRecord;
and push a PatientRecord struct into it:
PatientRecord memory record;
pAddressToRecord[msg.sender].push(record);
after which you retrieve it with a view function:
function getPatientRecords(address patientAddress) public view returns(PatientRecord[] memory){
return pAddressToRecord[patientAddress];//here you will get all the records for that specific address
}
The same logic goes with the ID instead of address. It depends a lot of what you want to achieve. Let me know if it works.