Skip to content

Instantly share code, notes, and snippets.

@Nasah-Kuma
Created November 2, 2023 10:22
Show Gist options
  • Save Nasah-Kuma/45df56de79a493572eceecb53f5cbaeb to your computer and use it in GitHub Desktop.
Save Nasah-Kuma/45df56de79a493572eceecb53f5cbaeb to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HealthRecordRepository {
enum AdmissionStatus { Admitted, NotAdmitted }
struct HealthRecord {
uint256 recordID;
string patientName;
uint256 age;
string diagnosis;
string treatment;
string[] medications;
AdmissionStatus admissionStatus;
}
mapping(address => HealthRecord[]) private patientRecords;
function addHealthRecord(
string memory _patientName,
uint256 _age,
string memory _diagnosis,
string memory _treatment,
string[] memory _medications,
AdmissionStatus _admissionStatus
) public {
HealthRecord memory newRecord = HealthRecord({
recordID: patientRecords[msg.sender].length,
patientName: _patientName,
age: _age,
diagnosis: _diagnosis,
treatment: _treatment,
medications: _medications,
admissionStatus: _admissionStatus
});
patientRecords[msg.sender].push(newRecord);
}
function getPatientRecords(address _patientAddress)
public
view
returns (HealthRecord[] memory)
{
return patientRecords[_patientAddress];
}
function getRecordByID(address _patientAddress, uint256 _recordID)
public
view
returns (HealthRecord memory)
{
require(
_recordID < patientRecords[_patientAddress].length,
"Invalid record ID"
);
return patientRecords[_patientAddress][_recordID];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment