Health care
Health insurance example
This contract is adapted from the DAML 's introductory insurance contract.
DAML is a distributed private ledger and does not manage payments; the contract allows the doctor to generate bills for insurer and patient.
The strength of a public blockchain with a cryptocurrency, is that it allows payments and accounting of payments in a single business process. The main differences between the contract below and the DAML version are:
    payments are executed through contract entries
    the contract enters the Running state with validation from both insurer and patient parties
The main benefit of this version is that it may serve as an opposable document in the case of a default in payment: indeed, since the contract is used to channel payments, the contract is accounting for any default of payment (in the debts variables).
For example, a doctor may go to court and exhibit the debt value of his corresponding doctor asset as a proof of the default in payment.
From a design point of vue, the contract manages several doctors. A doctor is registered with approvals from both patient and insurer parties.
We see in this basic example, that a smart contract on a public blockchain with a cryptocurrency, enables organisations to capture the critical aspects of a business process : payments, permissions and accounting.
1
archetype health_care
2
3
constant insurer : role = @tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg
4
constant patient : role = @tz1bfVgcJC4ukaQSHUe1EbrUd5SekXeP9CWk
5
6
constant fee : tez = 100tz
7
constant deductible : tez = 500tz
8
constant period : duration = 30d
9
10
variable last_fee : date = 2019-11-12
11
12
variable consultation_debt : tez = 0tz
13
14
asset doctor identified by id {
15
id : role;
16
debt : tez = 0tz;
17
}
18
19
states =
20
| Created initial
21
| Running
22
| Canceled
23
24
transition confirm () {
25
from Created
26
(*signed by [insrurer; patient]*)
27
to Running
28
with effect {
29
last_fee := now
30
}
31
}
32
33
transition cancel () {
34
called by insurer or patient
35
from Created
36
to Canceled
37
}
38
39
entry register_doctor (docid : address) {
40
(*signed by [insurer; patient]*)
41
require {
42
r1 : state = Running;
43
}
44
effect {
45
doctor.add ({ id = docid })
46
}
47
}
48
49
entry declare_consultation (v : tez) {
50
require {
51
r2 : state = Running;
52
r3 : doctor.contains(caller);
53
}
54
effect {
55
doctor.update(caller, { debt += v });
56
consultation_debt += min (v, deductible)
57
}
58
}
59
60
entry pay_doctor (docid : address) {
61
specification {
62
postcondition idem_balance_pay_doctor {
63
balance = before.balance
64
}
65
}
66
accept transfer
67
called by insurer
68
require {
69
r4 : state = Running;
70
}
71
effect {
72
var ldebt = doctor[docid].debt;
73
var decrease : tez = min (transferred, ldebt);
74
transfer decrease to docid;
75
transfer (transferred - decrease) to insurer;
76
doctor.update (docid, { debt -= decrease })
77
}
78
}
79
80
entry pay_fee () {
81
specification {
82
postcondition idem_balance_pay_fee {
83
balance = before.balance
84
}
85
}
86
accept transfer
87
called by patient
88
require {
89
r5 : state = Running;
90
}
91
effect {
92
var nb_periods : int = (now - last_fee) div period; (* div is euclidean *)
93
var due = nb_periods * fee;
94
var decrease : tez = min (transferred, due);
95
transfer decrease to insurer;
96
transfer (transferred - decrease) to patient;
97
last_fee += nb_periods * period (* last_fee <> now because div is euclidean *)
98
}
99
}
100
101
entry pay_consulation () {
102
specification {
103
idem_balance_pay_consultation : balance = before.balance;
104
}
105
accept transfer
106
called by patient
107
require {
108
r6 : state = Running;
109
}
110
effect {
111
var decrease : tez = min (transferred, consultation_debt);
112
transfer decrease to insurer;
113
transfer (transferred - decrease) to patient;
114
consultation_debt -= decrease
115
}
116
}
117
Copied!
Last modified 1yr ago
Export as PDF
Copy link