-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsurance.se
82 lines (70 loc) · 2.36 KB
/
insurance.se
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#A simple example of decentralize autonomous health insurance
#contract creation: parameters
#the I_ prefix represents an index in the contract.storage array
I_STATE = 0
I_CREATOR = 1
I_MAX_BENEFICIARIES = 2
I_MIN_BENEFICIARIES = 3
I_NUM_BENEFICIARIES = 4
I_NEW_PATIENT_VOTE = 5
I_ENROL_START = 6
I_ENROL_END = 7
I_COVERAGE_START = 8
I_COVERAGE_END = 9
I_CANCELATION_PENALTY = 10
I_BASE_PREMIUM = 11
I_ADJUSTMENT_FORMULA = 12
I_BENEFITS_PAID = 13
I_BALANCE = 14
I_MAX_PLAN_LIMIT = 15
I_TERMS_OF_CARE = 16
I_NUM_PCP = 17
I_NEW_PROVIDER_VOTE = 18
I_OUTCOME_REWARD = 19
I_PATIENT_REWARD_PERCENT = 20
I_PROVIDER_REWARD_PERCENT = 21
I_DISMISSAL_VOTE = 22
I_DISMISSAL_SEVERANCE = 23
I_PATIENT_LIST_START = 24
I_PROVIDER_LIST_START = 25
# state of contract creation
S_DRAFT = 0 // still drafting the contract
S_ENROLMENT = 1 // enrolment period
S_ACTIVE = 2 // contract is in effect
S_EXPIRED = 3 // contract has expired
state = contract.storage[I_STATE]
# create parameters in the S_DRAFT state
if state == S_DRAFT:
contract.storage[I_CREATOR] = tx.sender
contract.storage[I_...] = tx.data[
stop
# apply to join a group (no voting in this example; everyone who applies is automatically accepted)
if state == S_ENROLMENT:
x = 0
while x < msg.datasize:
index = x + I_PATIENT_LIST_START
contract.storage[index] = msg.data[x]
x = x+1
return(0)
# allow providers to bill
if state == S_ACTIVE:
if msg.data[0] > contract.storage[I_BALANCE]:
return(1)
contract.storage[I_BALANCE] = contract.storage[I_BALANCE] - msg.data[0]
to_address = msg.sender
send(to_address, msg.data[0], tx.gas - 100)
# when a contract expires, see if there is surplus and divide
# surplus among patients and providers
if state == S_EXPIRED:
pt_address = msg.sender
provider_address = msg.data[0]
# cumulative premiums by an individual patient over the coverage period
premium_pad = msg.data[1]
# benefits paid to an individual patient over the coverage period
total_used = msg.data[2]
num_minus = msg.data[3]
if premium_pad > total_used * contract.storage[I_OUTCOME_REWARD_PERCENT]:
surplus = premium_pad - total_used * contract.storage[I_PATIENT_REWARD_PERCENT]
send(pt_address, surplus*contract.storage[I_PATIENT_REWARD_PERCENTAGE], tx.gas - 100)
send(provider_address, contract.storage[I_BALANCE] - contract.storage[I_BALANCE] - surplus*contract.stroage[I_PROVIDER_REWARD_PERCENTAGE]
return(0)