# Policy Statistics and PaaS Query

## Basic Concept

Although InsureMO mostly features a headless PaaS platform with a primary focus on API to perform business transaction, it's an important factor to allow everyone to be able to view the general business transaction status and perform basic query and search.

From the platform prospective, a set of frequently-used statistics dashboards and technical queries are provided to facilitate system administrator to have a view on the overall business status by use of our platform.

## User Scenario

For anybody who wants to know the overall business transaction status and perform basic technical search.

## Special Constraint

This section is only applicable for those proposal, policy and endorsement which has been persisted in InsureMO. It's not applicable for quotation and micro-insurance scenarios. For group policy, it will not display risk or schedule level information. 


## Policy Statistics 

In this section, user will be able to choose the search criteria such as the product and date range to view the overall transaction summary of the following types:

* **Number of transaction amount**: to get an overall understanding of how many cases have been created or issued in the past. 
* **Number of premium amount**: to get an overall understanding of the amount of premiums that have been generated or issued in the past. 
* **Average issuance efficiency from creation to insurance**: to get an overall understanding of how fast the policy is to be issued from creation.
* **Statistics Report**: to get Statistics Report according to the required conditions.

If you want to have more specific tailored dashboard, you can click on the link at the bottom of the page, go to query page to search, and export data in excel format. The following business transaction category filters are also provided for our user with a personalized statistics view:

*  Whether it's a new business or endorsement
*  Whether it's renewal
*  Whether it's pending cases or issued cases

![Policy Statistics](./image/statistics/statistics_dashboard1.png)

### Search Condition

1. By default, platform will provide some available search criteria. User can click on the filter icon which in the upper right corner of the Search Condition Card, to add or remove search conditions on the page.
2. If user wants to add or hide some criteria in the filter, user can contact development team to configure them in policy & endorsement index via **Index Management** module.
3. User can also click on the policy tab, endorsement tab and total tab in the upper left corner to obtain the data.

![Policy Statistics](./image/statistics/searchCondition1.png)
![Policy Statistics](./image/statistics/searchCondition2.png)

### Total Number of Transaction

1. User can view the transaction quantity by year, month or day.
2. User can choose Issued or Pending to view the transaction quantity that have been issued or non-issued.
3. Both column bar and line charts are provided in case different users might have different favorites.
4. User can see the details, and the page displayed the date and quantity range, with different colors indicating different policy status. In the upper right corner, users can also switch between Data View, Column Bar Chart and Line Chart, or Save it as image.

![Policy Statistics](./image/statistics/statistics_dashboard4.png)
![Policy Statistics](./image/statistics/statistics_dashboard5.png)

### Total Premium Amount

1. User can view the total premium by year, month or day.
2. User can choose Issued or Pending to view the total premium that have been issued or non-issued.
3. Both column bar and line charts are provided in case different users might have different favorites.
4. User can see the details, and the page displayed the date and premium range, with different colors indicating different policy status. In the upper right corner, users can also switch between Data View, Column Bar Chart and Line Chart, or Save it as image.

![Policy Statistics](./image/statistics/statistics_dashboard6.png)
![Policy Statistics](./image/statistics/statistics_dashboard7.png)

### Total Issuance Efficiency(Average Hour)

1. User can view the issuance efficiency by year, month or day.
2. Both column bar and line charts are provided in case different users might have different favorites.
3. User can see the details, and the page displayed the date and issuance efficiency range, with different colors indicating different policy status. In the upper right corner, users can also switch between Data View, Column Bar Chart and Line Chart, or Save it as image.

![Policy Statistics](./image/statistics/statistics_dashboard8.png)
![Policy Statistics](./image/statistics/statistics_dashboard9.png)

### Get My Own Statistics Report

1. User can choose the criteria for Group Type, Average Field and Sum Field.
2. Group Type is a condition, Average Field and Sum Field is the statistical result calculated based on the condition, which also support export.
3. The fields in Group Type, Average Field and Sum Field are configured in Index. If user wants to add or hide some data, user can contact development team to configure them in policy & endorsement index via **Index Management** module.
If the added field type is string, it displays in Group Type, if field type is double or long, it displays in Average Field and Sum Field.

![Policy Statistics](./image/statistics/statistics_dashboard10.png)

## PaaS Query

For our SaaS or application deals, a business query screen is provided for business user to search out the business record. If it's a PaaS deal, there's a query API to fetch the past data for query purpose.

Sometimes, it's not so user-friendly to call API for simple query purpose. For such scenario, you can try to use some of the most common search criteria to search out the proposal/policy from the platform in a technical way.

Now the PaaS query is all configuration driven. User can customize his/her own search conditions and results in a configurable way.

Although it is the most efficient way to query policies, because all the product UI must follow the InsureMO format and no customization is allowed, the user experience might be acceptable but not as good as that on a customized UI. For example, there will be some redundant technical fields displayed, and UI section will be arranged according to the data model structure. If this is something not good, the platform can provide you with the source code to customize this page or directly adopt Easy PA to achieve.

In addition, to properly generate the target query UI, it's still necessary that configuration side must get clear requirements and configure more related matters. For example, the things such as code table must be tagged with the field and all code values must be fetched. For each dynamic field, business field label must be properly attached.


### PaaS Policy Query

#### Search Policy

Before checking the policy details, user needs to perform the policy search first. Now system lists out all the available search 
fields based on index configuration and user preference component. 

For more details about user preference, see [User Preference Guide](https://docs.insuremo.com/ics/app_framework/user_preference).

![Policy Query](./image/statistics/statistics_policy_query.png)


#### Export Policy

To facilitate user's operation, system also allows user to export the query results via Excel by clicking **Export All**:

![Policy Export](./image/statistics/statistics_policy_export.png)

Due to potential large data to export, it will be running in asynchronous mode and UI will be locked. Please don't close the window and wait for Excel to be generated.

![statistics_policy_export_async](./image/statistics/statistics_policy_export_async.png)

The exported file will contain all the selected fields as columns.

![Export Policy](./image/product_cfg_sample/policy_query_fields_exportall.png)

Custom column names for exported files are supported—refer to the [Export API Sample](https://docs.insuremo.com/gi_insurance_service/policy_transaction_api#policy-export---api-sample) for details.

#### Configuration for Policy Search & Export

By default, platform will provide some available search criteria. If user wants to add more criteria or hide some of them, user can contact development team to configure them in policy & endorsement index via **Index Management** module. 

![Policy Configure](./image/statistics/statistics_policy_configure.png)

So if user want the field to display in query results of the column field, please set the index field property "**Need Display**" to "**Yes**". For more details on how to configure index fields, see [Search Index Guide](/ics/app_framework/search).


#### Load Policy

Once any of the policy record is located, user will be able to enter and view the detailed policy information in the generic policy detail page. 

In the policy query page, there are two choices:

1. **Load Latest Version**: System will load the latest policy version. If there are multiple endorsements finished, it will load the version after the latest endorsement.

2. **Load 1st Issuance Version**: System will load the first policy version upon the policy issuance. If there are multiple endorsements finished, it will stick to the same version and user need go to endorsement query to see policy version at time of endorsement.

![Policy Version](./image/statistics/statistics_policy_query_version.png)

Once entering the version, system will display all policy object information based on policy API:

![Policy Detail](./image/statistics/statistics_policy_detail.png)

Below are some of the detailed tips on using this page:

1. The policy layout is the typical table layout which is by default expanded. This layout is the standard platform setting that cannot be changed by tenant. 
2. The policy table and field strictly follow the policy object structure definition. Some of the special policy objects which are not part of standard policy object will not display quotation, group policy, micro-insurance, underwriting history, etc.
3. All fields are in read-only status. There are special treatments to display UI labels and value formats like String, Number, Date and Code Value according to data dictionary configuration. 
4. User will be able to change the table display column and its sequence by product. System will save all these into user/tenant preference and keep such preference setting.
5. If any user has the menu authority, he/she can view all the policies without more authority control.

#### Configuration for Policy Load

On the policy detail screen, platform will display all the fields that have been persisted in the policy JSON object via UI. User can check the following aspects of configuration if necessary:

1. Data Dictionary model and object configuration -> section/table display  
2. Data Dictionary field binding configuration -> field display  
2.1 Code Table -> display dropdown  
2.2 Field Label -> display UI label  
2.3 Field Type -> display string, number or date  

![Field Configure](./image/statistics/statistics_policy_field_configure_dd.png)


### PaaS Endorsement Query

If there's endorsement performed on the policy, user will be able to view endorsement details as well.

![Endo Detail](./image/statistics/statistics_endo_detail.png)


## Internationalization

Policy Query (PAAS) UI internationalization data is maintained in **Global Configuration → UI Label Translation → Group Statistics**.  

### Label Translation

* If a key is missing there, the system falls back to **Menu** and then **Monitor**.
* If the same key exist in **Menu**, **Monitor** and **Statistics**, **Statistics** takes precedence.
* To customize, override the translation record with the **same key** . For the same key, the system prioritizes tenant-level data.

Sample keys:

| UI Element | Key | Example Value |
|------------|-----|---------------|
| Policy tab | Policy | Policy |
| Endorsement tab | Endorsement | Endorsement |
| Total tab | Total | Total |
| Policy search placeholder | PolicyQueryKeywordPlaceHolder | Proposal No, Policy No |
| Endorsement search placeholder | EndoQueryKeywordPlaceHolder | Policy No, Endo No |

![Internationalization](./image/statistics/DashboardS.png)

![Internationalization](./image/statistics/PolicyQueryS.png)

![Internationalization](./image/statistics/EndoQueryS.png)

![Internationalization](./image/statistics/i18nOver.png)

### DD-driven UI Translation

The details pages for policy and endorsement query are **automatically generated via DD configuration**. The platform already provides internationalization translations for some common fields; for product-specific fields, tenants need to supplement the translation data themselves. The following are the DD-driven UI Translation Matching Rules.

*  **Section Titles**
   1. Prioritize using `objectCode` as the key to retrieve i18n translations. 
   2. If no match is found, use `objectName` as the key to continue searching. 
   3. If still no result, display the node default value (e.g., `PolicyCustomerList`).

*  **Fields Under Sections**
   1. Prioritize using `fieldName` from the DD configuration as the key to retrieve i18n translations. 
   2. If no match is found, use `fieldLabel` as the key to continue searching. 
   3. If still no result, directly display `fieldName`.

![Internationalization](./image/statistics/ddDriven.png)

## PA Query via Skills

The `insuremo-gi-pa-query` skill provides programmatic API access to query PA policy and endorsement data. It covers the following business domains:

* **Policy** — load policy data, query by proposal/policy number, and retrieve fee calculation for new business
* **Endorsement** — load endorsement data, query endorsement history, and look up policy by version
* **Policy Fee Info** — fee calculation for new business and endorsement scenarios
* **Underwriting** — load policy underwriting information





