Overview
Thecreate_record transition allows patients to store their encrypted medical data on-chain as a private record. The encryption must happen client-side before calling this function. The record is stored as a private Aleo record, visible only to the patient who owns it.
Function Signature
Parameters
First segment of encrypted medical data. Part of the 12-field encrypted data storage (~360 bytes total capacity).
Second segment of encrypted medical data.
Third segment of encrypted medical data.
Fourth segment of encrypted medical data.
Fifth segment of encrypted medical data.
Sixth segment of encrypted medical data.
Seventh segment of encrypted medical data.
Eighth segment of encrypted medical data.
Ninth segment of encrypted medical data.
Tenth segment of encrypted medical data.
Eleventh segment of encrypted medical data.
Twelfth segment of encrypted medical data.
Category of medical record. Must be between 1-10:
- 1: General Health
- 2: Laboratory Results
- 3: Prescriptions
- 4: Imaging/Radiology
- 5: Vaccination Records
- 6: Surgical Records
- 7: Mental Health
- 8: Dental Records
- 9: Vision/Ophthalmology
- 10: Other/Miscellaneous
Hash of the original encrypted data for integrity verification. Used to ensure data hasn’t been tampered with and as part of the unique record ID generation.
Client-provided random nonce for unique ID generation. Ensures the record ID is unpredictable and unique even if the same data is uploaded multiple times.
If
true, adds the record to the public record_metadata mapping for indexing. This makes the record existence public (but not the content) so it can be listed in patient portals.Returns
Private record owned by the caller containing:
owner: The patient’s Aleo addressrecord_id: Unique identifier (BHP256 hash of patient, data_hash, nonce)data_hash: Integrity verification hashdata_part1-12: Encrypted medical data segmentsrecord_type: Category (1-10)created_at: Set to 0u32 (actual creation time stored in public metadata)version: Schema version (currently 1u8)
Async finalization that:
- Increments the patient’s record count in
patient_record_countmapping - Optionally adds record metadata to
record_metadatamapping ifmake_discoverableis true - Records the actual block height as creation time in public metadata
Validation Rules
Record Type Validation
record_type is not between 1 and 10.
Record ID Generation
- Patient address (ensures uniqueness per patient)
- Data hash (ensures uniqueness per content)
- Client nonce (prevents prediction, ensures uniqueness)
Code Example
Client-Side Pre-computation
You can compute the record ID before callingcreate_record using the compute_record_id helper:
On-Chain State Changes
Patient Record Count
The finalize function increments the patient’s total record count:Optional Public Metadata
Ifmake_discoverable is true, the record is indexed:
Error Cases
Privacy Considerations
- Medical Data: The 12 data parts contain encrypted medical information. Encryption MUST happen client-side before calling this function.
- Private Record: The
MedicalRecordis stored as an Aleo record, visible only to the owner (patient). - Public Metadata: If
make_discoverableis true, the record’s existence, type, and creation time are public, but the actual medical data remains private. - Data Capacity: 12 fields provide ~360 bytes of encrypted storage. For larger medical records, implement client-side chunking.
Best Practices
- Always encrypt data client-side before splitting into field elements
- Use cryptographically secure random nonces to prevent record ID prediction
- Compute and verify data_hash to ensure integrity
- Set make_discoverable based on patient preference - some patients may want complete privacy
- Store the private MedicalRecord locally after creation for future access grants
- Track nonces used to avoid accidental reuse
Related Functions
- grant_access - Share this record with a healthcare provider
- MedicalRecord Structure - Understanding the record structure