This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
testsCreateContract.jl
349 lines (288 loc) · 10.4 KB
/
testsCreateContract.jl
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#loading packages
push!(LOAD_PATH, "src");
import Base: @kwdef
using Pkg
Pkg.activate(".")
Pkg.instantiate()
using Test
using LifeInsuranceDataModel
using BitemporalPostgres
using SearchLight
using SearchLightPostgreSQL
using TimeZones
using ToStruct
using JSON
# purging the data model entirely - empty the schema
if (haskey(ENV, "GITPOD_REPO_ROOT"))
run(```psql -f sqlsnippets/droptables.sql```)
elseif (haskey(ENV, "GENIE_ENV") & (ENV["GENIE_ENV"] == "dev"))
run(```psql -d postgres -f sqlsnippets/droptables.sql```)
end
# Loading the data model- Create tables, constraints etc. and load Roles
# loading inverses of the role tables to provide role descriptions in object creation, for instance like in: "ref_role=cpRole["Policy Holder"]
LifeInsuranceDataModel.load_model()
@testset "CreateContract" begin
cpRole = Dict{String,Int64}()
map(find(LifeInsuranceDataModel.ContractPartnerRole)) do entry
cpRole[entry.value] = entry.id.value
end
tiprRole = Dict{String,Int64}()
map(find(LifeInsuranceDataModel.TariffItemPartnerRole)) do entry
tiprRole[entry.value] = entry.id.value
end
titrRole = Dict{String,Int64}()
map(find(LifeInsuranceDataModel.TariffItemRole)) do entry
titrRole[entry.value] = entry.id.value
end
ppRole = Dict{String,Int64}()
map(find(LifeInsuranceDataModel.ProductPartRole)) do entry
ppRole[entry.value] = entry.id.value
end
# Or just connect to an existing model
LifeInsuranceDataModel.connect()
# Create a Partner
p = LifeInsuranceDataModel.Partner()
pr = LifeInsuranceDataModel.PartnerRevision(description="Partner 1")
w = Workflow(type_of_entity="Partner",
tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz"Africa/Porto-Novo"),
)
create_entity!(w)
create_component!(p, pr, w)
commit_workflow!(w)
Partner1 = p.id.value
# Create tariffs
# create Tariffs
function create_tariff(dsc, mt)
t = LifeInsuranceDataModel.Tariff()
tr = LifeInsuranceDataModel.TariffRevision(description=dsc, mortality_table=mt)
w = Workflow(
type_of_entity="Tariff",
tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz"Africa/Porto-Novo"),
)
create_entity!(w)
create_component!(t, tr, w)
commit_workflow!(w)
t.id.value
end
LifeRiskTariff = create_tariff("Life Risk Insurance", "1980 CET - Male Nonsmoker, ANB")
TerminalIllnessTariff = create_tariff(
"Terminal Illness",
"2001 VBT Residual Standard Select and Ultimate - Male Nonsmoker, ANB",
)
OccupationalDisabilityTariff = create_tariff(
"Occupational Disability",
"2001 VBT Residual Standard Select and Ultimate - Male Nonsmoker, ANB",
)
ProfitParticipationTariff = create_tariff(
"Profit participation",
"2001 VBT Residual Standard Select and Ultimate - Male Nonsmoker, ANB",
)
LifeRiskTariff2 = create_tariff(
"Life Risk Insurance",
"2001 VBT Residual Standard Select and Ultimate - Male Nonsmoker, ANB",
)
find(TariffRevision)
find(Tariff, SQLWhereExpression("id=?", ProfitParticipationTariff))
find(Tariff, SQLWhereExpression("id=?", TerminalIllnessTariff))
# Create Product
p = Product()
pr = ProductRevision(description="Life Risk")
pp = ProductPart()
ppr = ProductPartRevision(
ref_tariff=LifeRiskTariff,
ref_role=ppRole["Main Coverage - Life"],
description="Main Coverage - Life",
)
pp2 = ProductPart()
ppr2 = ProductPartRevision(
ref_tariff=ProfitParticipationTariff,
ref_role=ppRole["Profit participation"],
description="Profit participation Lif Risk",
)
w0 = Workflow(
type_of_entity="Product",
tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz"Africa/Porto-Novo"),
)
create_entity!(w0)
create_component!(p, pr, w0)
create_subcomponent!(p, pp, ppr, w0)
create_subcomponent!(p, pp2, ppr2, w0)
commit_workflow!(w0)
LifeRiskProduct = p.id.value
println(LifeRiskProduct)
p = Product()
pr = ProductRevision(description="Life Risk - Terminal Illness")
pp = ProductPart()
ppr = ProductPartRevision(
ref_tariff=LifeRiskTariff,
ref_role=ppRole["Main Coverage - Life"],
description="Main Coverage - Life",
)
pp2 = ProductPart()
ppr2 = ProductPartRevision(
ref_tariff=ProfitParticipationTariff,
ref_role=ppRole["Profit participation"],
description="Profit participation Life Risk",
)
pp3 = ProductPart()
ppr3 = ProductPartRevision(
ref_tariff=TerminalIllnessTariff,
ref_role=ppRole["Supplementary Coverage - Terminal Illness"],
description="additional cover Terminal Illness",
)
pp4 = ProductPart()
ppr4 = ProductPartRevision(
ref_tariff=ProfitParticipationTariff,
ref_role=ppRole["Profit participation"],
description="Profit participation Terminal Illness",
)
pp5 = ProductPart()
ppr5 = ProductPartRevision(
ref_tariff=OccupationalDisabilityTariff,
ref_role=ppRole["Supplementary Coverage - Occupational Disablity"],
description="additional cover Occupational Disablity",
)
pp6 = ProductPart()
ppr6 = ProductPartRevision(
ref_tariff=ProfitParticipationTariff,
ref_role=ppRole["Profit participation"],
description="Profit participation Occ.Disablity",
)
w0 = Workflow(
type_of_entity="Product",
tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz"Africa/Porto-Novo"),
)
create_entity!(w0)
create_component!(p, pr, w0)
create_subcomponent!(p, pp, ppr, w0)
create_subcomponent!(p, pp2, ppr2, w0)
create_subcomponent!(p, pp3, ppr3, w0)
create_subcomponent!(p, pp4, ppr4, w0)
create_subcomponent!(p, pp5, ppr5, w0)
create_subcomponent!(p, pp6, ppr6, w0)
commit_workflow!(w0)
LifeRiskTIODProduct = p.id.value
println(LifeRiskTIODProduct)
# Testing
# Create contract blue
w1 = Workflow(
type_of_entity="Contract",
tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz"Africa/Porto-Novo"),
)
create_entity!(w1)
c = Contract()
cr = ContractRevision(description="contract creation properties")
create_component!(c, cr, w1)
cpr = ContractPartnerRef(ref_super=c.id)
cprr = ContractPartnerRefRevision(
ref_partner=Partner1,
ref_role=cpRole["Policy Holder"],
description="policiyholder ref properties",
)
create_subcomponent!(c, cpr, cprr, w1)
# pi 1
LifeRiskTIODProduct = find(Product, SQLWhereExpression("id=?", 2))[1].id.value
PartnerRole = tiprRole["Insured Person"]
cpi = ProductItem(ref_super=c.id)
cpir = ProductItemRevision(
ref_product=LifeRiskTIODProduct,
description="from contract creation",
)
create_subcomponent!(c, cpi, cpir, w1)
LifeInsuranceDataModel.create_product_instance(
w1,
cpi,
LifeRiskTIODProduct,
Partner1,
PartnerRole,
)
commit_workflow!(w1)
# update Contract yellow
cr1 = ContractRevision(ref_component=c.id, description="contract 1, 2nd mutation")
w2 = Workflow(
type_of_entity="Contract",
ref_history=w1.ref_history,
tsw_validfrom=ZonedDateTime(2016, 5, 30, 21, 0, 1, 1, tz"Africa/Porto-Novo"),
)
update_entity!(w2)
update_component!(cr, cr1, w2)
@test w2.ref_history == w1.ref_history
commit_workflow!(w2)
@test w2.ref_history == w1.ref_history
# update Contract red
w3 = Workflow(
type_of_entity="Contract",
ref_history=w2.ref_history,
tsw_validfrom=ZonedDateTime(2015, 5, 30, 21, 0, 1, 1, tz"Africa/Porto-Novo"),
)
update_entity!(w3)
cr1 = findcomponentrevision(ContractRevision, c.id, w3.ref_version)[1]
cr2 = ContractRevision(ref_component=c.id, description="contract 1, 3rd mutation retrospective")
update_component!(cr1, cr2, w3)
commit_workflow!(w3)
@test w3.ref_history == w2.ref_history
w4 = Workflow(
type_of_entity="Contract",
ref_history=w2.ref_history,
tsw_validfrom=ZonedDateTime(2018, 5, 30, 21, 0, 1, 1, tz"Africa/Porto-Novo"),
)
update_entity!(w4)
cr3 = ContractRevision(ref_component=c.id, description="contract 1, 4th mutation")
update_component!(cr2, cr3, w4)
# pi 2
LifeRiskTIODProduct = find(Product, SQLWhereExpression("id=?", 2))[1].id.value
PartnerRole = tiprRole["Insured Person"]
cpi = ProductItem(ref_super=c.id)
cpir = ProductItemRevision(
ref_product=LifeRiskTIODProduct,
description="from contract 4th mutation",
)
create_subcomponent!(c, cpi, cpir, w4)
println("vor neuem Teil")
LifeInsuranceDataModel.create_product_instance(
w4,
cpi,
LifeRiskTIODProduct,
Partner1,
PartnerRole,
)
commit_workflow!(w4)
end # testset create contract
using BitemporalPostgres, SearchLight
history = 9
txntime = MaxDate
res = SearchLight.query(
"select s.tsdb_invalidfrom as sdbinv, m.tsdb_validfrom as mdbval,
m.tsworld_validfrom as mwval, s.tsworld_validfrom as swval,m.tsworld_invalidfrom as mwinv,s.tsworld_invalidfrom as swinv,
m.id as mid, s.id as sid , m.ref_history as mh , m.ref_version as mv , s.ref_version as sv
from validityintervals m join validityintervals s
on m.ref_history=s.ref_history
and m.ref_version != s.ref_version
and m.tsdb_validfrom = s.tsdb_invalidfrom
and m.tsworld_validfrom <= s.tsworld_validfrom
--and tstzrange(m.tsworld_validfrom, m.tsworld_invalidfrom) @> s.tsworld_validfrom -- tstzrange(s.tsworld_validfrom,s.tsworld_invalidfrom)
where m.ref_history=$history
and m.tsdb_invalidfrom = TIMESTAMPTZ '$txntime'",
)
println(res)
txns = SearchLight.query("select tsdb_validfrom as vf from validityintervals union
select tsdb_invalidfrom as vf from validityintervals
group by vf order by vf")
refs = SearchLight.query("select tsworld_validfrom as vf from validityintervals union
select tsworld_invalidfrom as vf from validityintervals
group by vf order by vf")
println(txns)
println(refs)
txnDict = Dict()
for i = 1:first(size(txns))
txnDict[txns[i, 1]] = i
end
refDict = Dict()
for i = 1:first(size(refs))
refDict[refs[i, 1]] = i
end
println(txnDict)
println(refDict)
using BitemporalPostgres
valints = find(ValidityInterval)
vi = valints[1]