The core data structure for storing encrypted patient health information:
/// MedicalRecord - Private record storing encrypted patient health data/// /// This record is owned by the patient and contains their encrypted medical/// information. Only the patient can decrypt and read the contents.record MedicalRecord { owner: address, // The patient's Aleo address record_id: field, // Unique identifier for this record data_hash: field, // Hash of encrypted data for integrity data_part1: field, // Encrypted data segment 1 data_part2: field, // Encrypted data segment 2 data_part3: field, // Encrypted data segment 3 data_part4: field, // Encrypted data segment 4 data_part5: field, // Encrypted data segment 5 data_part6: field, // Encrypted data segment 6 data_part7: field, // Encrypted data segment 7 data_part8: field, // Encrypted data segment 8 data_part9: field, // Encrypted data segment 9 data_part10: field, // Encrypted data segment 10 data_part11: field, // Encrypted data segment 11 data_part12: field, // Encrypted data segment 12 record_type: u8, // Category of medical record (1-10) created_at: u32, // Block height placeholder version: u8, // Record version for upgradability}
Stores information about temporary access permissions:
/// AccessGrant - Public struct representing temporary access permission////// Stored in public mapping so doctors can verify their access rights./// The actual medical data remains private - this only proves permission.struct AccessGrant { patient: address, // Who granted access doctor: address, // Who has access record_id: field, // Which record (not the data itself) access_token: field, // Cryptographic proof of permission granted_at: u32, // When access was granted (block height) expires_at: u32, // When access expires (block height) is_revoked: bool, // Manual revocation flag}
Privacy Note: While AccessGrant is public, it only reveals that access was granted, not what medical data is contained in the record.
/// RecordMetadata - Public struct for record discovery (optional indexing)////// Allows patients to have a public index of their records without/// revealing the actual content. Useful for frontend record listing.struct RecordMetadata { patient: address, record_id: field, record_type: u8, created_at: u32, is_active: bool,}
Patients can choose whether to make records discoverable via the make_discoverable parameter. Setting this to false provides maximum privacy.
/// Maps access_token -> AccessGrant for verification/// Doctors use this to prove they have valid accessmapping access_grants: field => AccessGrant;/// Maps record_id -> RecordMetadata for optional public indexing/// Patients can choose to make record existence public (not content)mapping record_metadata: field => RecordMetadata;/// Maps (patient_address as field) -> record_count for tracking/// Helps track how many records a patient has createdmapping patient_record_count: field => u64;/// Maps access_token -> bool for quick validity checks/// Cheaper than reading full AccessGrant structmapping access_token_valid: field => bool;
Verifies if a doctor has valid access to a record.
async transition verify_access( access_token: field, doctor: address, record_id: field) -> Future { return finalize_verify_access(access_token, doctor, record_id);}async function finalize_verify_access( access_token: field, doctor: address, record_id: field) { // Check if token exists and is valid let is_valid: bool = access_token_valid.get_or_use(access_token, false); assert(is_valid); // Fails if token doesn't exist or is invalid // Get the full access grant let grant: AccessGrant = access_grants.get(access_token); // Verify doctor address matches assert_eq(grant.doctor, doctor); // Verify record_id matches assert_eq(grant.record_id, record_id); // Verify not revoked assert(!grant.is_revoked); // Verify not expired assert(block.height <= grant.expires_at); // If all assertions pass, access is valid}
The verify_access transaction succeeds if access is valid, and fails if any check doesn’t pass. This makes verification atomic and deterministic.
{ "program": "salud_health_records_v6.aleo", "version": "0.1.0", "description": "Privacy-preserving health records management on Aleo. Enables patients to store encrypted medical records and share them temporarily with healthcare providers via secure access tokens.", "license": "MIT", "leo": "3.4.0"}