From c7d0e4ca88d610cf0dea2594700bc2b5cec9726b Mon Sep 17 00:00:00 2001 From: Michael Fliegner Date: Thu, 21 Jul 2022 20:01:32 +0200 Subject: [PATCH] JUPYTER snippet for product item creation --- db/connection.yml | 4 +- db/connectionWSL.yml | 2 +- populateAndTest.ipynb | 972 +++++++++++++++++++++++++----------------- 3 files changed, 572 insertions(+), 406 deletions(-) diff --git a/db/connection.yml b/db/connection.yml index 82285c1..408b159 100644 --- a/db/connection.yml +++ b/db/connection.yml @@ -4,8 +4,8 @@ dev: adapter: PostgreSQL database: postgres host: 127.0.0.1 - username: gitpod - password: + username: postgres + password: postgres port: 5432 config: log_queries=false, log_level=Error diff --git a/db/connectionWSL.yml b/db/connectionWSL.yml index e0d47a3..408b159 100644 --- a/db/connectionWSL.yml +++ b/db/connectionWSL.yml @@ -5,7 +5,7 @@ dev: database: postgres host: 127.0.0.1 username: postgres - password: pg + password: postgres port: 5432 config: log_queries=false, log_level=Error diff --git a/populateAndTest.ipynb b/populateAndTest.ipynb index 1d59cab..da46fb4 100644 --- a/populateAndTest.ipynb +++ b/populateAndTest.ipynb @@ -1,405 +1,571 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Load packages" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#loading packages\n", - "push!(LOAD_PATH, \"src\");\n", - "import Base: @kwdef\n", - "using Test\n", - "using LifeInsuranceDataModel\n", - "\n", - "using BitemporalPostgres\n", - "using SearchLight\n", - "using SearchLightPostgreSQL\n", - "using TimeZones\n", - "using ToStruct\n", - "using JSON" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "purging the data model entirely - empty the schema" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if (haskey(ENV, \"GITPOD_REPO_ROOT\"))\n", - " run(```psql -f sqlsnippets/droptables.sql```)\n", - "else\n", - " println(\"execute this in Your REPL\")\n", - " println(\"\"\"\n", - " run(```sudo -u postgres psql -f sqlsnippets/droptables.sql```)\n", - " \"\"\")\n", - "end\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Loading the data model- Create tables, constraints etc. and load Roles\n", - "\n", - "loading inverses of the role tables to provide role descriptions in object creation, for instance like in: \"ref_role=cpRole[\"Policy Holder\"]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "LifeInsuranceDataModel.load_model()\n", - "\n", - "cpRole = Dict{String,Int64}()\n", - "map(find(LifeInsuranceDataModel.ContractPartnerRole)) do entry\n", - " cpRole[entry.value] = entry.id.value\n", - "end\n", - "tiprRole = Dict{String,Int64}()\n", - "map(find(LifeInsuranceDataModel.TariffItemPartnerRole)) do entry\n", - " tiprRole[entry.value] = entry.id.value\n", - "end\n", - "titrRole = Dict{String,Int64}()\n", - "map(find(LifeInsuranceDataModel.TariffItemRole)) do entry\n", - " titrRole[entry.value] = entry.id.value\n", - "end\n", - "\n", - "ppRole = Dict{String,Int64}()\n", - "map(find(LifeInsuranceDataModel.ProductPartRole)) do entry\n", - " ppRole[entry.value] = entry.id.value\n", - "end\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Or just connect to an existing model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "LifeInsuranceDataModel.connect()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a Partner" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = LifeInsuranceDataModel.Partner()\n", - "pr = LifeInsuranceDataModel.PartnerRevision(description=\"Partner 1\")\n", - "w = Workflow(\n", - " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", - ")\n", - "create_entity!(w)\n", - "create_component!(p, pr, w)\n", - "commit_workflow!(w)\n", - "\n", - "Partner1 = p.id.value" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create tariffs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# create Tariffs\n", - "function create_tariff(dsc)\n", - " t = LifeInsuranceDataModel.Tariff()\n", - " tr = LifeInsuranceDataModel.TariffRevision(description=dsc)\n", - " w = Workflow(\n", - " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", - " )\n", - " create_entity!(w)\n", - " create_component!(t, tr, w)\n", - " commit_workflow!(w)\n", - " t.id.value\n", - "end\n", - "\n", - "\n", - "LifeRiskTariff=create_tariff(\"Life Risk Insurance\")\n", - "TerminalIllnessTariff=create_tariff(\"Terminal Illness\")\n", - "OccupationalDisabilityTariff=create_tariff(\"Occupational Disability\")\n", - "ProfitParticipationTariff=create_tariff(\"Profit participation\")\n", - "\n", - "find(TariffRevision)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "find(Tariff,SQLWhereExpression(\"id=?\",ProfitParticipationTariff))\n", - "find(Tariff, SQLWhereExpression(\"id=?\", TerminalIllnessTariff))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create Product" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = Product()\n", - "pr = ProductRevision(description=\"Life Risk\")\n", - "\n", - "pp = ProductPart()\n", - "ppr = ProductPartRevision(ref_tariff=LifeRiskTariff, ref_role=ppRole[\"Main Coverage - Life\"], description=\"Main Coverage - Life\")\n", - "\n", - "pp2 = ProductPart()\n", - "ppr2 = ProductPartRevision(ref_tariff=ProfitParticipationTariff, ref_role=ppRole[\"Profit participation\"], description=\"Profit participation Lif Risk\")\n", - "\n", - "w0 = Workflow(\n", - " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", - ")\n", - "create_entity!(w0)\n", - "create_component!(p, pr, w0)\n", - "create_subcomponent!(p, pp, ppr, w0)\n", - "create_subcomponent!(p, pp2, ppr2, w0)\n", - "commit_workflow!(w0)\n", - "\n", - "LifeRiskProduct = p.id.value\n", - "println(LifeRiskProduct)\n", - "\n", - "p = Product()\n", - "pr = ProductRevision(description=\"Life Risk - Terminal Illness\")\n", - "\n", - "pp = ProductPart()\n", - "ppr = ProductPartRevision(ref_tariff=LifeRiskTariff, ref_role=ppRole[\"Main Coverage - Life\"], description=\"Main Coverage - Life\")\n", - "\n", - "pp2 = ProductPart()\n", - "ppr2 = ProductPartRevision(ref_tariff=ProfitParticipationTariff, ref_role=ppRole[\"Profit participation\"], description=\"Profit participation Life Risk\")\n", - "\n", - "pp3 = ProductPart()\n", - "ppr3 = ProductPartRevision(ref_tariff=TerminalIllnessTariff, ref_role=ppRole[\"Supplementary Coverage - Terminal Illness\"], description=\"additional cover Terminal Illness\")\n", - "\n", - "pp4 = ProductPart()\n", - "ppr4 = ProductPartRevision(ref_tariff=ProfitParticipationTariff, ref_role=ppRole[\"Profit participation\"], description=\"Profit participation Terminal Illness\")\n", - "\n", - "pp5 = ProductPart()\n", - "ppr5 = ProductPartRevision(ref_tariff=OccupationalDisabilityTariff, ref_role=ppRole[\"Supplementary Coverage - Occupational Disablity\"], description=\"additional cover Occupational Disablity\")\n", - "\n", - "pp6 = ProductPart()\n", - "ppr6 = ProductPartRevision(ref_tariff=ProfitParticipationTariff, ref_role=ppRole[\"Profit participation\"], description=\"Profit participation Occ.Disablity\")\n", - "\n", - "\n", - "\n", - "w0 = Workflow(\n", - " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", - ")\n", - "create_entity!(w0)\n", - "create_component!(p, pr, w0)\n", - "create_subcomponent!(p, pp, ppr, w0)\n", - "create_subcomponent!(p, pp2, ppr2, w0)\n", - "create_subcomponent!(p, pp3, ppr3, w0)\n", - "create_subcomponent!(p, pp4, ppr4, w0)\n", - "create_subcomponent!(p, pp5, ppr5, w0)\n", - "create_subcomponent!(p, pp6, ppr6, w0)\n", - "commit_workflow!(w0)\n", - "\n", - "LifeRiskTIODProduct = p.id.value\n", - "println(LifeRiskTIODProduct)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create contract" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - " w1 = Workflow(\n", - " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", - " )\n", - " \n", - " create_entity!(w1)\n", - " c = Contract()\n", - " cr = ContractRevision(description=\"contract creation properties\")\n", - " create_component!(c, cr, w1)\n", - " \n", - " cpr = ContractPartnerRef(ref_super=c.id)\n", - " cprr = ContractPartnerRefRevision(ref_partner=Partner1, ref_role=cpRole[\"Policy Holder\"], description=\"policiyholder ref properties\")\n", - " create_subcomponent!(c, cpr, cprr, w1)\n", - " # pi 1\n", - " cpi = ProductItem(ref_super=c.id)\n", - " cpir = ProductItemRevision(position=1, ref_product=LifeRiskTIODProduct, description=\"from contract creation\")\n", - " create_subcomponent!(c, cpi, cpir, w1)\n", - " # pi 1 ti 1 \n", - " pit = TariffItem(ref_super=cpi.id)\n", - " pitr = TariffItemRevision(ref_tariff=LifeRiskTariff, ref_role=titrRole[\"Main Coverage - Life\"], description=\"Life Risk tariff parameters\")\n", - " create_subcomponent!(cpi, pit, pitr, w1)\n", - " # pi 1 ti 1 p 1\n", - " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", - " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", - " create_subcomponent!(pit, pitp, pitpr, w1)\n", - " \n", - " # pi 1 ti 2 \n", - " pit = TariffItem(ref_super=cpi.id)\n", - " pitr = TariffItemRevision(ref_tariff=ProfitParticipationTariff, ref_role=titrRole[\"Profit participation\"], description=\"Profit participation tariff parameters\")\n", - " create_subcomponent!(cpi, pit, pitr, w1)\n", - " # pi 1 ti 2 p 1\n", - " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", - " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", - " create_subcomponent!(pit, pitp, pitpr, w1)\n", - " \n", - " # pi 1 ti 3 \n", - " pit = TariffItem(ref_super=cpi.id)\n", - " pitr = TariffItemRevision(ref_tariff=TerminalIllnessTariff, ref_role=titrRole[\"Supplementary Coverage - Terminal Illness\"], description=\"Terminal Illness tariff parameters\")\n", - " create_subcomponent!(cpi, pit, pitr, w1)\n", - " # pi 1 ti 3 p 1\n", - " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", - " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", - " create_subcomponent!(pit, pitp, pitpr, w1)\n", - " \n", - " # pi 1 ti 4 \n", - " pit = TariffItem(ref_super=cpi.id)\n", - " pitr = TariffItemRevision(ref_tariff=ProfitParticipationTariff, ref_role=titrRole[\"Profit participation\"], description=\"Profitparticipation tariff parameters\")\n", - " create_subcomponent!(cpi, pit, pitr, w1)\n", - " # pi 1 ti 4 p 1\n", - " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", - " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", - " create_subcomponent!(pit, pitp, pitpr, w1)\n", - " \n", - " \n", - " # pi 1 ti 5 \n", - " pit = TariffItem(ref_super=cpi.id)\n", - " pitr = TariffItemRevision(ref_tariff=ProfitParticipationTariff, ref_role=titrRole[\"Supplementary Coverage - Occupational Disablity\"], description=\"Occupational Disablity tariff parameters\")\n", - " create_subcomponent!(cpi, pit, pitr, w1)\n", - " # pi 1 ti 5 p 1\n", - " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", - " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", - " create_subcomponent!(pit, pitp, pitpr, w1)\n", - " \n", - " # pi 1 ti 6 \n", - " pit = TariffItem(ref_super=cpi.id)\n", - " pitr = TariffItemRevision(ref_tariff=ProfitParticipationTariff, ref_role=titrRole[\"Profit participation\"], description=\"Profit Participation tariff parameters\")\n", - " create_subcomponent!(cpi, pit, pitr, w1)\n", - " # pi 1 ti 6 p 1\n", - " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", - " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", - " create_subcomponent!(pit, pitp, pitpr, w1)\n", - " \n", - " \n", - " \n", - " \n", - " commit_workflow!(w1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "update Contract yellow" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cr1 = ContractRevision(ref_component=c.id, description=\"contract 1, 2nd mutation\")\n", - "w2 = Workflow(\n", - " ref_history=w1.ref_history,\n", - " tsw_validfrom=ZonedDateTime(2016, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", - ")\n", - "update_entity!(w2)\n", - "update_component!(cr, cr1, w2)\n", - "commit_workflow!(w2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - " update Contract red" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "cr2 = ContractRevision(ref_component=c.id, description=\"contract 1, 3rd mutation retrospective\")\n", - "w3 = Workflow(\n", - " ref_history=w2.ref_history,\n", - " tsw_validfrom=ZonedDateTime(2015, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", - ")\n", - "update_entity!(w3)\n", - "update_component!(cr1, cr2, w3)\n", - "commit_workflow!(w3)\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Julia 1.6.6", - "language": "julia", - "name": "julia-1.6" - }, - "language_info": { - "file_extension": ".jl", - "mimetype": "application/julia", - "name": "julia", - "version": "1.6.6" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Load packages" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [], + "source": [ + "#loading packages\n", + "push!(LOAD_PATH, \"src\");\n", + "import Base: @kwdef\n", + "using Pkg\n", + "Pkg.instantiate()\n", + "using Test\n", + "using LifeInsuranceDataModel\n", + "\n", + "using BitemporalPostgres\n", + "using SearchLight\n", + "using SearchLightPostgreSQL\n", + "using TimeZones\n", + "using ToStruct\n", + "using JSON" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "purging the data model entirely - empty the schema" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [], + "source": [ + "if (haskey(ENV, \"GITPOD_REPO_ROOT\"))\n", + " run(```psql -f sqlsnippets/droptables.sql```)\n", + "else\n", + " println(\"execute this in Your REPL\")\n", + " println(\"\"\"\n", + " run(```sudo -u postgres psql -f sqlsnippets/droptables.sql```)\n", + " \"\"\")\n", + "end\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Loading the data model- Create tables, constraints etc. and load Roles\n", + "\n", + "loading inverses of the role tables to provide role descriptions in object creation, for instance like in: \"ref_role=cpRole[\"Policy Holder\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4-element Vector{Int64}:\n", + " 1\n", + " 2\n", + " 3\n", + " 4" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "LifeInsuranceDataModel.load_model()\n", + "\n", + "cpRole = Dict{String,Int64}()\n", + "map(find(LifeInsuranceDataModel.ContractPartnerRole)) do entry\n", + " cpRole[entry.value] = entry.id.value\n", + "end\n", + "tiprRole = Dict{String,Int64}()\n", + "map(find(LifeInsuranceDataModel.TariffItemPartnerRole)) do entry\n", + " tiprRole[entry.value] = entry.id.value\n", + "end\n", + "titrRole = Dict{String,Int64}()\n", + "map(find(LifeInsuranceDataModel.TariffItemRole)) do entry\n", + " titrRole[entry.value] = entry.id.value\n", + "end\n", + "\n", + "ppRole = Dict{String,Int64}()\n", + "map(find(LifeInsuranceDataModel.ProductPartRole)) do entry\n", + " ppRole[entry.value] = entry.id.value\n", + "end\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Or just connect to an existing model" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "PostgreSQL connection (CONNECTION_OK) with parameters:\n", + " user = postgres\n", + " password = ********************\n", + " channel_binding = prefer\n", + " dbname = postgres\n", + " host = 127.0.0.1\n", + " port = 5432\n", + " client_encoding = UTF8\n", + " options = -c DateStyle=ISO,YMD -c IntervalStyle=iso_8601 -c TimeZone=UTC\n", + " application_name = LibPQ.jl\n", + " sslmode = prefer\n", + " sslcompression = 0\n", + " sslsni = 1\n", + " ssl_min_protocol_version = TLSv1.2\n", + " gssencmode = prefer\n", + " krbsrvname = postgres\n", + " target_session_attrs = any" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "LifeInsuranceDataModel.connect()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create a Partner" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "p = LifeInsuranceDataModel.Partner()\n", + "pr = LifeInsuranceDataModel.PartnerRevision(description=\"Partner 1\")\n", + "w = Workflow(\n", + " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", + ")\n", + "create_entity!(w)\n", + "create_component!(p, pr, w)\n", + "commit_workflow!(w)\n", + "\n", + "Partner1 = p.id.value" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create tariffs" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4-element Vector{TariffRevision}:\n", + " TariffRevision\n", + "| KEY | VALUE |\n", + "|-----------------------|---------------------|\n", + "| description::String | Life Risk Insurance |\n", + "| id::DbId | 1 |\n", + "| ref_component::DbId | 1 |\n", + "| ref_invalidfrom::DbId | 9223372036854775807 |\n", + "| ref_validfrom::DbId | 2 |\n", + "\n", + " TariffRevision\n", + "| KEY | VALUE |\n", + "|-----------------------|---------------------|\n", + "| description::String | Terminal Illness |\n", + "| id::DbId | 2 |\n", + "| ref_component::DbId | 2 |\n", + "| ref_invalidfrom::DbId | 9223372036854775807 |\n", + "| ref_validfrom::DbId | 3 |\n", + "\n", + " TariffRevision\n", + "| KEY | VALUE |\n", + "|-----------------------|-------------------------|\n", + "| description::String | Occupational Disability |\n", + "| id::DbId | 3 |\n", + "| ref_component::DbId | 3 |\n", + "| ref_invalidfrom::DbId | 9223372036854775807 |\n", + "| ref_validfrom::DbId | 4 |\n", + "\n", + " TariffRevision\n", + "| KEY | VALUE |\n", + "|-----------------------|----------------------|\n", + "| description::String | Profit participation |\n", + "| id::DbId | 4 |\n", + "| ref_component::DbId | 4 |\n", + "| ref_invalidfrom::DbId | 9223372036854775807 |\n", + "| ref_validfrom::DbId | 5 |\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# create Tariffs\n", + "function create_tariff(dsc)\n", + " t = LifeInsuranceDataModel.Tariff()\n", + " tr = LifeInsuranceDataModel.TariffRevision(description=dsc)\n", + " w = Workflow(\n", + " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", + " )\n", + " create_entity!(w)\n", + " create_component!(t, tr, w)\n", + " commit_workflow!(w)\n", + " t.id.value\n", + "end\n", + "\n", + "\n", + "LifeRiskTariff=create_tariff(\"Life Risk Insurance\")\n", + "TerminalIllnessTariff=create_tariff(\"Terminal Illness\")\n", + "OccupationalDisabilityTariff=create_tariff(\"Occupational Disability\")\n", + "ProfitParticipationTariff=create_tariff(\"Profit participation\")\n", + "\n", + "find(TariffRevision)" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1-element Vector{Tariff}:\n", + " Tariff\n", + "| KEY | VALUE |\n", + "|-------------------|-------|\n", + "| id::DbId | 2 |\n", + "| ref_history::DbId | 3 |\n", + "| ref_version::DbId | 3 |\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "find(Tariff,SQLWhereExpression(\"id=?\",ProfitParticipationTariff))\n", + "find(Tariff, SQLWhereExpression(\"id=?\", TerminalIllnessTariff))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create Product" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": {}, + "outputs": [], + "source": [ + "p = Product()\n", + "pr = ProductRevision(description=\"Life Risk\")\n", + "\n", + "pp = ProductPart()\n", + "ppr = ProductPartRevision(ref_tariff=LifeRiskTariff, ref_role=ppRole[\"Main Coverage - Life\"], description=\"Main Coverage - Life\")\n", + "\n", + "pp2 = ProductPart()\n", + "ppr2 = ProductPartRevision(ref_tariff=ProfitParticipationTariff, ref_role=ppRole[\"Profit participation\"], description=\"Profit participation Lif Risk\")\n", + "\n", + "w0 = Workflow(\n", + " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", + ")\n", + "create_entity!(w0)\n", + "create_component!(p, pr, w0)\n", + "create_subcomponent!(p, pp, ppr, w0)\n", + "create_subcomponent!(p, pp2, ppr2, w0)\n", + "commit_workflow!(w0)\n", + "\n", + "LifeRiskProduct = p.id.value\n", + "println(LifeRiskProduct)\n", + "\n", + "p = Product()\n", + "pr = ProductRevision(description=\"Life Risk - Terminal Illness\")\n", + "\n", + "pp = ProductPart()\n", + "ppr = ProductPartRevision(ref_tariff=LifeRiskTariff, ref_role=ppRole[\"Main Coverage - Life\"], description=\"Main Coverage - Life\")\n", + "\n", + "pp2 = ProductPart()\n", + "ppr2 = ProductPartRevision(ref_tariff=ProfitParticipationTariff, ref_role=ppRole[\"Profit participation\"], description=\"Profit participation Life Risk\")\n", + "\n", + "pp3 = ProductPart()\n", + "ppr3 = ProductPartRevision(ref_tariff=TerminalIllnessTariff, ref_role=ppRole[\"Supplementary Coverage - Terminal Illness\"], description=\"additional cover Terminal Illness\")\n", + "\n", + "pp4 = ProductPart()\n", + "ppr4 = ProductPartRevision(ref_tariff=ProfitParticipationTariff, ref_role=ppRole[\"Profit participation\"], description=\"Profit participation Terminal Illness\")\n", + "\n", + "pp5 = ProductPart()\n", + "ppr5 = ProductPartRevision(ref_tariff=OccupationalDisabilityTariff, ref_role=ppRole[\"Supplementary Coverage - Occupational Disablity\"], description=\"additional cover Occupational Disablity\")\n", + "\n", + "pp6 = ProductPart()\n", + "ppr6 = ProductPartRevision(ref_tariff=ProfitParticipationTariff, ref_role=ppRole[\"Profit participation\"], description=\"Profit participation Occ.Disablity\")\n", + "\n", + "\n", + "\n", + "w0 = Workflow(\n", + " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", + ")\n", + "create_entity!(w0)\n", + "create_component!(p, pr, w0)\n", + "create_subcomponent!(p, pp, ppr, w0)\n", + "create_subcomponent!(p, pp2, ppr2, w0)\n", + "create_subcomponent!(p, pp3, ppr3, w0)\n", + "create_subcomponent!(p, pp4, ppr4, w0)\n", + "create_subcomponent!(p, pp5, ppr5, w0)\n", + "create_subcomponent!(p, pp6, ppr6, w0)\n", + "commit_workflow!(w0)\n", + "\n", + "LifeRiskTIODProduct = p.id.value\n", + "println(LifeRiskTIODProduct)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create contract" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [], + "source": [ + " w1 = Workflow(\n", + " tsw_validfrom=ZonedDateTime(2014, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", + " )\n", + " \n", + " create_entity!(w1)\n", + " c = Contract()\n", + " cr = ContractRevision(description=\"contract creation properties\")\n", + " create_component!(c, cr, w1)\n", + " \n", + " cpr = ContractPartnerRef(ref_super=c.id)\n", + " cprr = ContractPartnerRefRevision(ref_partner=Partner1, ref_role=cpRole[\"Policy Holder\"], description=\"policiyholder ref properties\")\n", + " create_subcomponent!(c, cpr, cprr, w1)\n", + " # pi 1\n", + " cpi = ProductItem(ref_super=c.id)\n", + " cpir = ProductItemRevision(position=1, ref_product=LifeRiskTIODProduct, description=\"from contract creation\")\n", + " create_subcomponent!(c, cpi, cpir, w1)\n", + " # pi 1 ti 1 \n", + " pit = TariffItem(ref_super=cpi.id)\n", + " pitr = TariffItemRevision(ref_tariff=LifeRiskTariff, ref_role=titrRole[\"Main Coverage - Life\"], description=\"Life Risk tariff parameters\")\n", + " create_subcomponent!(cpi, pit, pitr, w1)\n", + " # pi 1 ti 1 p 1\n", + " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", + " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", + " create_subcomponent!(pit, pitp, pitpr, w1)\n", + " \n", + " # pi 1 ti 2 \n", + " pit = TariffItem(ref_super=cpi.id)\n", + " pitr = TariffItemRevision(ref_tariff=ProfitParticipationTariff, ref_role=titrRole[\"Profit participation\"], description=\"Profit participation tariff parameters\")\n", + " create_subcomponent!(cpi, pit, pitr, w1)\n", + " # pi 1 ti 2 p 1\n", + " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", + " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", + " create_subcomponent!(pit, pitp, pitpr, w1)\n", + " \n", + " # pi 1 ti 3 \n", + " pit = TariffItem(ref_super=cpi.id)\n", + " pitr = TariffItemRevision(ref_tariff=TerminalIllnessTariff, ref_role=titrRole[\"Supplementary Coverage - Terminal Illness\"], description=\"Terminal Illness tariff parameters\")\n", + " create_subcomponent!(cpi, pit, pitr, w1)\n", + " # pi 1 ti 3 p 1\n", + " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", + " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", + " create_subcomponent!(pit, pitp, pitpr, w1)\n", + " \n", + " # pi 1 ti 4 \n", + " pit = TariffItem(ref_super=cpi.id)\n", + " pitr = TariffItemRevision(ref_tariff=ProfitParticipationTariff, ref_role=titrRole[\"Profit participation\"], description=\"Profitparticipation tariff parameters\")\n", + " create_subcomponent!(cpi, pit, pitr, w1)\n", + " # pi 1 ti 4 p 1\n", + " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", + " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", + " create_subcomponent!(pit, pitp, pitpr, w1)\n", + " \n", + " \n", + " # pi 1 ti 5 \n", + " pit = TariffItem(ref_super=cpi.id)\n", + " pitr = TariffItemRevision(ref_tariff=ProfitParticipationTariff, ref_role=titrRole[\"Supplementary Coverage - Occupational Disablity\"], description=\"Occupational Disablity tariff parameters\")\n", + " create_subcomponent!(cpi, pit, pitr, w1)\n", + " # pi 1 ti 5 p 1\n", + " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", + " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", + " create_subcomponent!(pit, pitp, pitpr, w1)\n", + " \n", + " # pi 1 ti 6 \n", + " pit = TariffItem(ref_super=cpi.id)\n", + " pitr = TariffItemRevision(ref_tariff=ProfitParticipationTariff, ref_role=titrRole[\"Profit participation\"], description=\"Profit Participation tariff parameters\")\n", + " create_subcomponent!(cpi, pit, pitr, w1)\n", + " # pi 1 ti 6 p 1\n", + " pitp = TariffItemPartnerRef(ref_super=pit.id)\n", + " pitpr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=tiprRole[\"Insured Person\"], description=\"partner 1 ref properties\")\n", + " create_subcomponent!(pit, pitp, pitpr, w1)\n", + " \n", + " \n", + " \n", + " \n", + " commit_workflow!(w1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "update Contract yellow" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [], + "source": [ + "cr1 = ContractRevision(ref_component=c.id, description=\"contract 1, 2nd mutation\")\n", + "w2 = Workflow(\n", + " ref_history=w1.ref_history,\n", + " tsw_validfrom=ZonedDateTime(2016, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", + ")\n", + "update_entity!(w2)\n", + "update_component!(cr, cr1, w2)\n", + "commit_workflow!(w2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " update Contract red" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "cr2 = ContractRevision(ref_component=c.id, description=\"contract 1, 3rd mutation retrospective\")\n", + "w3 = Workflow(\n", + " ref_history=w2.ref_history,\n", + " tsw_validfrom=ZonedDateTime(2015, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", + ")\n", + "update_entity!(w3)\n", + "update_component!(cr1, cr2, w3)\n", + "\n", + "\n", + "commit_workflow!(w3)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [], + "source": [ + "w4 = Workflow(\n", + " ref_history=w2.ref_history,\n", + " tsw_validfrom=ZonedDateTime(2018, 5, 30, 21, 0, 1, 1, tz\"Africa/Porto-Novo\"),\n", + ")\n", + "update_entity!(w4)\n", + "cr3 = ContractRevision(ref_component=c.id, description=\"contract 1, 4th mutation\")\n", + "update_component!(cr2, cr3, w4)\n", + "\n", + "# pi 2\n", + "LifeRiskTIODProduct = find(Product, SQLWhereExpression(\"id=?\", 2))[1].id.value\n", + "Partner1\n", + "PartnerRole = tiprRole[\"Insured Person\"]\n", + "\n", + "cpi = ProductItem(ref_super=c.id)\n", + "cpir = ProductItemRevision(position=2, ref_product=LifeRiskTIODProduct, description=\"from contract 4th mutation\")\n", + "create_subcomponent!(c, cpi, cpir, w4)\n", + "\n", + "println(\"vor neuem Teil\")\n", + "\n", + "\n", + "\n", + "map(find(ProductPart, SQLWhereExpression(\"ref_super=?\", LifeRiskTIODProduct))) do pp\n", + " println(pp.id.value)\n", + " map(find(ProductPartRevision, SQLWhereExpression(\"ref_component=?\", pp.id.value))) do ppr\n", + " println(ppr.description)\n", + " ti=TariffItem(ref_super=cpi.id)\n", + " tir = TariffItemRevision(ref_role=ppr.ref_role, ref_tariff=ppr.ref_tariff, description=ppr.description)\n", + " create_subcomponent!(cpi, ti, tir, w4)\n", + " tip = TariffItemPartnerRef(ref_super=cpi.id)\n", + " tipr = TariffItemPartnerRefRevision(ref_partner=Partner1, ref_role=PartnerRole)\n", + " create_subcomponent!(cpi, tip, tipr, w4)\n", + " println(tir)\n", + " println(tipr)\n", + " end\n", + "end\n", + "println(\"vor rollback\")\n", + "# rollback_workflow!(w4)\n", + "commit_workflow!(w4)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.6.7", + "language": "julia", + "name": "julia-1.6" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.6.7" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 }