# Micro-Insurance

## Business Scenario

* Large volume of business: > 100,000/day
* High concurrency: 20,000/hour 
* Low amount: Insured amount < 100 RMB/policy
* Streamlined process: No manual underwriting, no workflows, few types of endorsements, fixed premium/amount or premium calculated by a third party.


## Technical Consideration

### Technology Optimization

* Use a single table to store policies, endorsements, and claims, and do not write them to log tables during policy issuance, which improves overall performance by 5 times and reduces storage space to 1/5 of the original.
* Remove ES indexing/querying, change traditional database querying, and index dynamic fields in relevant tables. There is no need for distributed transactions, which improves performance by 1 time.
* (Optional) Summarize micro insurance policies into group policies according to certain rules, and write them to traditional core systems. Process endorsements and claims similarly. This allows downstream systems (payment/accounting/claims/reporting etc.) to maintain compatibility and reduce pressure from big data.
* Optimize third-party channel integration:
  * Support query and update operations based on channel order number, policy number and user information etc.
  * Some internal fields do not need to be passed in during integration, and the system will automatically complete and remove the need for complex data padding in the iComposer.
  * Provide bulk Create/Update/Issue APIs that can process multiple policies at one time.
  * Optimize distributed databases, adding partition information to all SQL statements.


### Provided APIs

* Policy: Create, Update, Issue, Payment, Load, Query (exact)
* Endorsement: Create, Update, Issue, Payment, Load, Query (exact)
* Claim: Create, Update, Settle, Payment, Load, Query (exact)

### Differences from Traditional Core APIs

* Create/Update/Issue APIs do not involve ES operations, call ES APIs from iComposer if needed.
* Create/Update/Issue APIs do not do premium calculation/manual underwriting, call Proposal/Endorsement Calculation/autoUnderWriting APIs if needed.
* Query APIs only support exact queries, and support database querying on most common fields including custom dynamic fields.
* Provide additional bulk operation APIs for better performance.
* Optimize distributed databases, adding partition information to all SQL statements. 

### Usage in iComposer Layer

* Similar to calling traditional Proposal/Endorsement APIs, there are no special requirements.
* There is no need to customize integration APIs for different channels/products, and call Mass APIs after internal model transformation.
* For third-party channel integration via files:
  * You can use platform's functions like Upload, Define Templates and Parse Uploaded Data.
  * Do necessary processing on parsed data, and call platform APIs to save it to the database. Mass provides some additional bulk update interfaces.
  * For summarized group policies, it is necessary to customize post core system logic for different products (they may have different core systems).

### Some Points to Note

* Because Mass APIs don't use ES, there is no need to enable distributed transactions.
* When updating policy data and allowing some fields to be absent, the system will skip updating automatically. This helps a lot for third-party integration mode, which is unnecessary to load policy to fill in data.

## API Usage

### Policy JSON Structure

Mostly, users can use the same JSON body to call both proposal and micro insurance API.

### API Parameters

It is same as Policy/Endo/Claim objects in Proposal/Endo/Claim services.
Calling Proposal and Endorsement APIs can basically and directly switch to calling Mass APIs.


### Other Related Configurations

Global + Product Level Parameter Configurations:

* Whether to summarize into group policies or not
* Group policy summarization rules
* Group policy data template (or hard coding in iComposer)
* Whether to auto-generate ARAP or not
* Whether to print policies or not
* Which products directly use Claim module rather than Mass Claim?

### Limitations

* Fuzzy query in ES is not supported, but precise query on necessary fields in database is supported.
* Traditional report statistics directly on policy model is not supported, but you can use DataMO for data analysis, or analyze summarized group policies.
* DataPatch will be more complex, and you need to update JSON data. 

### Sample JSON

Request

The environmental information in the first line below needs to be modified accordingly.

```json

curl --location 'https://tenantcode***.insuremo.com/tenantcode-mass-bff-app/massIntegration/common/proposal/createEx' \
--header 'Content-Type: application/json' \
--header 'Cookie: httponly' \
--data-raw '{
   "@type": "Policy-POLICY",
   "ChannelPolicyNo":"CP1691379025",
   "ChannelOrderNo":"CO1691379025",
    "ProductCode": "TBTI",
    "ProductVersion": "1.0",
    "ProposalDate": "2021-04-22T00:00:00",
    "EffectiveDate": "2021-04-22T00:00:00",
    "ExpiryDate": "2022-04-21T23:59:59",
    "AgentCode": "TB0001",
    "BookCurrencyCode": "USD",
    "PremiumCurrencyCode": "USD",
    "OrgCode": "10002",
    "LocalCurrencyCode": "USD",
    "PremiumBookExchangeRate": 1,
    "PremiumLocalExchangeRate": 1,
    "SumInsured": 300000,
    "DuePremium":10,
    "PolicyCustomerList": [
        {"@type": "PolicyCustomer-PolicyCustomer",
            "CustomerName": "Apitest202111",
            "DateOfBirth": "1988-06-08",
            "IdNo": "0629",
            "IdType": "1",
            "Gender": "F",
            "IsOrgParty": "N",
            "CustomerType": "IndiCustomer",
            "IsPolicyHolder": "Y"
        }
    ],
    "PolicyLobList": [
        {"@type": "PolicyLob-PolicyLob",
            "PolicyRiskList": [
                {"@type": "PolicyRisk-PolicyRisk",
                    "CustomerName": "Customer",
                    "IdNo": "IdNo",
                    "IdType": "1",
                    "DateOfBirth": "1988-10-01",
                    "PolicyCoverageList": [
                        {"@type": "PolicyCoverage-PolicyCoverage",
                            "ProductElementCode": "C100416",
                            "SumInsured": 300000,
                            "PolicyBenefitList": [
                                {"@type": "PolicyBenefit-PolicyBenefit",
                                    "ProductElementCode": "B00248"
                                }
                            ]
                        },
                        {"@type": "PolicyCoverage-PolicyCoverage",
                            "ProductElementCode": "C100692",
                            "SumInsured": 300000
                        },
                        {"@type": "PolicyCoverage-PolicyCoverage",
                            "ProductElementCode": "C100715",
                            "SumInsured": 300000
                        }
                    ],
                    "ProductElementCode": "R10007",
                    "RiskName": "Test"
                }
            ],
            "ProductCode": "TBTI",
            "TotalInsuredCount": 1
        }
    ]
}'
```


Response

```json
{
    "@pk": 24200202802,
    "@type": "Policy-POLICY",
    "AgentCode": "TB0001",
    "BookCurrencyCode": "USD",
    "BusinessCateCode": "1",
    "BusinessObjectId": 3517051304219,
    "ChannelOrderNo": "CO1691142041",
    "ChannelPolicyNo": "CP1691142041",
    "DuePremium": 10,
    "EffectiveDate": "2021-04-22",
    "ExpiryDate": "2022-04-21T23:59:59",
    "LocalCurrencyCode": "USD",
    "OrgCode": "10002",
    "PolicyElementId": 24200202802,
    "PolicyId": "24200202802,568B8E411743F0BCD9737F335F798F99",
    "PolicyStatus": 1,
    "PolicyType": "1",
    "PremiumBookExchangeRate": 1,
    "PremiumCurrencyCode": "USD",
    "PremiumLocalExchangeRate": 1,
    "ProductCode": "TBTI",
    "ProductId": 351925022,
    "ProductVersion": "1.0",
    "ProposalDate": "2021-04-22",
    "ProposalNo": "PTBTI2023740000000008",
    "SchemaVersion": 2,
    "SumInsured": 300000,
    "TechProductCode": "TR_POC",
    "TechProductId": 3516410623456,
    "VersionSeq": 0,
    "PolicyCustomerList": [
        {
            "@type": "PolicyCustomer-PolicyCustomer",
            "BusinessObjectId": 1000000290,
            "CustomerName": "Apitest202111",
            "DateOfBirth": "1988-06-08",
            "IdNo": "0629",
            "IdType": "1",
            "IsInsured": "N",
            "IsOrgParty": "N",
            "IsPolicyHolder": "Y",
            "ParentPolicyElementId": 24200202802,
            "PolicyStatus": 2,
            "SequenceNumber": 1,
            "CustomerType": "IndiCustomer",
            "Gender": "F",
            "TempData": {
                "Mask-IdNo": "7TyIEK6o+ecn3L9/3YHLAw==",
                "IdNo": "7TyIEK6o+ecn3L9/3YHLAw==",
                "MaskAfter-IdNo": "0629"
            }
        }
    ],
    "PolicyLobList": [
        {
            "@type": "PolicyLob-TR_POC",
            "BusinessObjectId": 351861068,
            "ParentPolicyElementId": 24200202802,
            "PolicyStatus": 2,
            "ProductCode": "TBTI",
            "ProductElementCode": "TBTI",
            "ProductElementId": 351925023,
            "ProductId": 351925022,
            "ProductLobId": 351925023,
            "SequenceNumber": 1,
            "TechProductCode": "TR_POC",
            "TechProductId": 3516410623456,
            "PolicyRiskList": [
                {
                    "@type": "PolicyRisk-R10007",
                    "BusinessObjectId": 351861075,
                    "PolicyStatus": 2,
                    "ProductElementCode": "R10007",
                    "ProductElementId": 351926021,
                    "RiskName": "Test",
                    "SequenceNumber": 1,
                    "CustomerName": "Customer",
                    "DateOfBirth": "1988-10-01",
                    "IdNo": "IdNo",
                    "IdType": "1",
                    "PolicyCoverageList": [
                        {
                            "@type": "PolicyCoverage-PolicyCoverage",
                            "BusinessObjectId": 528044248,
                            "PolicyStatus": 2,
                            "ProductElementCode": "C100416",
                            "ProductElementId": 351926024,
                            "SequenceNumber": 1,
                            "SumInsured": 300000,
                            "PolicyBenefitList": [
                                {
                                    "@type": "PolicyBenefit-PolicyBenefit",
                                    "BusinessObjectId": 528055840,
                                    "PolicyStatus": 2,
                                    "ProductElementCode": "B00248",
                                    "ProductElementId": 522209920,
                                    "SequenceNumber": 1
                                }
                            ]
                        },
                        {
                            "@type": "PolicyCoverage-PolicyCoverage",
                            "BusinessObjectId": 528044248,
                            "PolicyStatus": 2,
                            "ProductElementCode": "C100692",
                            "ProductElementId": 351926030,
                            "SequenceNumber": 2,
                            "SumInsured": 300000
                        },
                        {
                            "@type": "PolicyCoverage-PolicyCoverage",
                            "BusinessObjectId": 528044248,
                            "PolicyStatus": 2,
                            "ProductElementCode": "C100715",
                            "ProductElementId": 351926027,
                            "SequenceNumber": 3,
                            "SumInsured": 300000
                        }
                    ],
                    "TempData": {
                        "Mask-IdNo": "Jmf1vghdrScrTdpdeyKu7w==",
                        "IdNo": "Jmf1vghdrScrTdpdeyKu7w==",
                        "MaskAfter-IdNo": "IdNo"
                    }
                }
            ],
            "TotalInsuredCount": 1
        }
    ]
}
```

