Created
November 2, 2023 10:22
-
-
Save Nasah-Kuma/45df56de79a493572eceecb53f5cbaeb to your computer and use it in GitHub Desktop.
A refactor of https://gist.github.com/Nasah-Kuma/35e6609ba8e37699132f1c963907ed35 using enums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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