Skip to content

Instantly share code, notes, and snippets.

@Nasah-Kuma
Created October 31, 2023 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nasah-Kuma/35e6609ba8e37699132f1c963907ed35 to your computer and use it in GitHub Desktop.
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…
// 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];
}
}
@Nasah-Kuma
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment