In this example, we will explore a prescription-filling system, with a Pharmacy, Prescriptions, and Patients. Patients have prescriptions, which they must first deposit at a Pharmacy before filling. Each Prescription can be filled a set number of times.
This system is intended to reflect the following rule on prescriptions:
The code in the file Prescription.obs
contains several tasks, each labeled // TODO TASK #: ...
.
You do not have to do the tasks in any particular order, but they are numbered by anticipated difficulty, with lower numbers being less time consuming.
Below are the declarations of contracts and transactions that are useful for managing collections of PharmacyPrescriptionRecords. The full code can be found in Collections.obs in the same directory as the main file (Prescription.obs).
contract MaybeRecord {
asset state Something {
PharmacyPrescriptionRecord@HasFills record;
}
state Nothing;
MaybeRecord@Nothing();
MaybeRecord@Something(PharmacyPrescriptionRecord@HasFills >> Unowned newRecord);
transaction getRecord(MaybeRecord@Just >> Nothing this) returns PharmacyPrescriptionRecord@HasFills;
}
contract PharmacyPrescriptionRecordList {
state Nil;
asset state Cons {
PharmacyPrescriptionRecord@HasFills record;
PharmacyPrescriptionRecordList@Shared next;
}
PharmacyPrescriptionRecordList@Nil();
PharmacyPrescriptionRecordList@Cons(PharmacyPrescriptionRecord@HasFills >> Unowned newRecord,
PharmacyPrescriptionRecordList@Shared tail);
transaction prependIfNotEmpty(PharmacyPrescriptionRecord@Owned >> Unowned newRecord) returns PharmacyPrescriptionRecordList@Shared;
transaction contains(Prescription@Unowned prescription) returns bool;
transaction removeIfExists(Prescription@Unowned prescription) returns MaybeRecord@Owned;
}