Created
October 31, 2023 14:20
-
-
Save Nasah-Kuma/35e6609ba8e37699132f1c963907ed35 to your computer and use it in GitHub Desktop.
In this contract, the HealthRecord struct represents a patient's health record, and it includes various data points such as recordID, patientName, age, diagnosis, treatment, medications, and isAdmitted. The addHealthRecord function allows adding a new health record to the repository, while the getPatientRecords and getRecordByID functions enable…
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 { | |
struct HealthRecord { | |
uint256 recordID; | |
string patientName; | |
uint256 age; | |
string diagnosis; | |
string treatment; | |
string[] medications; | |
bool isAdmitted; | |
} | |
mapping(address => HealthRecord[]) private patientRecords; | |
function addHealthRecord( | |
string memory _patientName, | |
uint256 _age, | |
string memory _diagnosis, | |
string memory _treatment, | |
string[] memory _medications, | |
bool _isAdmitted | |
) public { | |
HealthRecord memory newRecord = HealthRecord({ | |
recordID: patientRecords[msg.sender].length, | |
patientName: _patientName, | |
age: _age, | |
diagnosis: _diagnosis, | |
treatment: _treatment, | |
medications: _medications, | |
isAdmitted: _isAdmitted | |
}); | |
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
In this contract, the HealthRecord struct represents a patient's health record, and it includes various data points such as recordID, patientName, age, diagnosis, treatment, medications, and isAdmitted. The addHealthRecord function allows adding a new health record to the repository, while the getPatientRecords and getRecordByID functions enable retrieving records for a specific patient or by a specific record ID.
The patientRecords mapping stores an array of HealthRecord for each patient's address, allowing the contract to store health records for multiple patients.