# BizId Service
Biz id service is responsible for maintaing knowledge entity ids and corresponding values. It is for fast read via multiple services like ingestion, knowlegde search service, other functions.
## Common Termonologies:
**1. Entity Type Id:**
uint32 Id for Entity types of different domains.
eg. Customer (01) , Patient (02) ,etc.
**2. Primary BizId & BizIdType:**
`BizIdValue` : String form of defined Primary Biz Id Value.
`BizIdType` : uint32 Id of Primary Biz Id.
eg. Aadhar Card(01) : 12345
`BizIdType: 01`
`BizIdValue: "12345"`
**3. Telos Id:**
Uniquily generated uint64 for Primary Biz Id Value.
**4. Secondary Biz Ids:**
Biz Id other than Primary Biz Id:
Stored as a *Map<uint32 , String>*
eg.
``{
"pancard":"AAAA1111A",
"email":"abc@gmail.com",
"mobile":"9999999999"
}``
After replacing with BizIdType:
``
{
"02":"AAAA1111A",
"03":"abc@ril.com",
"04":"9999999999"
}
``
### Redis Storage Format:
We are storing data in Redis Cache as Interface HashOperations **<H,HK,HV>** in four differnt ways as below:
1. **<entityTypeId , bizIdValue , telosId>**
eg. `Customer-id (01) , <primary-biz-id-value ("12345") , biz-id/telosID (1000)>`
2. **<entityTypeId , telosId , bizIdValue>**
eg. `Customer-id (01) , <biz-id (1000) , primary-biz-id-value ("12345")>`
3. **<telosId , <bizIdType , bizIdValue>>**
eg. `1000, { "pan_card" , "AAAA1111A" ,"email" : "abc@gmail.com" , "adhar" : "12345"}`
4. **<entityTypeId , <bizIdValue , telosId>>**
eg. `"customer" : { "AAAA1111A" : 1000 , "abc@gmail.com" : 1000 ,"BBBB1111B" : 1001 , "xyz@gmail.com" : 1001 }`
#### APIs available:
* **Create APIs:**
1. `/bizId/create`
`rpc CreateTelosId`
This api is being used to create Redis Hash no. 1&2.
```
RequestProto{
uint32 entity_type = 1;
string primary_biz_id_value = 2;
}
ResponseProto{
uint32 entity_type = 1;
uint64 entity_instance_id = 2;
telos.core.base.Status status = 3;
}
```
2. `/bizId/createSecBizId`
`rpc CreateBizIdValue`
This api is being used to create Redis Hash no. 3&4.
The Secondary Biz Id Map would also store Primary Biz Id.
```
RequestProto{
uint32 entity_type_id = 1;
telos.core.knowledge.EntityBizIdMap biz_id_map = 2;
}
ResponseProto{
uint64 telos_id = 1;
telos.core.base.Status status = 2;
}
```
* **Get APIs:**
3. `/bizId/getIdFromPrimaryBizId`:
`rpc ReadTelosIdGivenPrimaryBizId`:
Get Telos Id to corresponding Primary Biz Id.
```
RequestProto{
uint32 entity_type_id = 1; // customer type id
string bizId_value = 2; // value of primary-biz-id adhar card = "12345"
}
ResponseProto{
uint64 telos_id = 1;
telos.core.base.Status status = 2;
}
```
4. `/bizId/getPrimaryBizIdValue`:
`rpc ReadPrimaryBizIdGivenTelosId`:
Get Primary Biz Id Value corresponding to Telos Id.
```
RequestProto{
uint32 entity_type_id = 1; // customer type id
uint64 telos_id = 2; // telos id
}
ResponseProto{
string bizId_value = 1; // Primary-Biz-Id value (Adhar Card:"12345")
telos.core.base.Status status = 2;
}
```
5. `/bizId/getSecondaryId`
`rpc ReadSecBizIdValueGivenSecBizIdType`
Get Secondary Biz Id Value corresponding to Biz Id Type.
```
RequestProto{
uint32 entity_type_id = 1; // customer type id
uint64 telos_id = 2; // telos id
uint32 bizId_type = 3; // ID(pancard)
}
ResponseProto{
uint64 telos_id = 1; // to map the response to entity
uint32 bizId_type = 2; // ID(pancard)
string bizId_value = 3; // Fetched Secondary-Biz-Id value (Pan Card:"GORPO1234U")
telos.core.base.Status status = 4;
}
```
6. `/bizId/getTelosIdFromSecBizId`
`rpc ReadTelosIdGivenBizId`
Get Telos Id Value corresponding to Biz Id Type.
```
RequestProto{
uint32 entity_type_id = 1; // customer type id
uint32 bizId_type = 3; // ID(pancard)
string bizId_value = 4; // Biz-Id value (PanCard:"GORPO1234U")
}
ResponseProto{
uint64 telos_id = 1; // Should be repeated??
telos.core.base.Status status = 4;
}
```
7. `/bizId/getSecBizIdFromPrimaryBizId`
`rpc ReadSecBizIdValueGivenPrimaryBizId`
Get Secondary Id Value corresponding to primary Biz Id Type.
```
RequestProto{
uint32 entity_type_id = 1; // customer type id
string bizId_value = 2; // Biz-Id value (Adharcard:"12345")
uint32 bizId_type = 3; // ID(pancard)
}
ResponseProto{
string bizId_value = 1; //Secondary-biz-id-value (pancard:"AAAA1111A")
telos.core.base.Status status = 4;
}
```
8. `/bizId/getPrimaryBizIdFromSecBizId`
`rpc ReadPrimaryBizIdGivenSecBizId`
Get primary Id Value corresponding to Secondary Biz Id.
```
RequestProto{
uint32 entity_type_id = 1; // customer type id
uint32 bizId_type = 3; // ID(pancard)
string bizId_value = 4; // Secondary-biz-id-value (pancard:"AAAA1111A")
}
ResponseProto{
string bizId_value = 1; //primary-biz-id-value (adharcard:"12345")
telos.core.base.Status status = 4;
}
```
9. `/bizId/getSecBizIdFromSecBizId`:
`rpc ReadSecBizIdGivenSecBizId`:
Get Secondary Id Value corresponding to Secondary Biz Id.
```
RequestProto{
uint32 entity_type_id = 1; // customer type id
uint32 bizId_type = 3; // ID(pancard)
string bizId_value = 4; // Secondary-biz-id-value (pancard:"AAAA1111A")
}
ResponseProto{
string bizId_value = 1; //sec-biz-id-value (Email:"abc@gmail.com")
telos.core.base.Status status = 4;
}
```
10. `rpc ReadAllBizIdGivenTelosId`:
Get all Biz Id of a entity.
```
RequestProto{
uint32 entity_type_id = 1; // ex. person entity type
uint64 telos_id = 3;
}
ResponseProto{
telos.core.knowledge.EntityBizIdMap biz_id_value = 1;
telos.core.base.Status status = 2;
}
```
11. `rpc UpdateBizId`
12. `rpc DeleteBizId`
##### **Link Keys:**
Link Key is the common Id/Key we use to identify same entity in different domains i.e Entity Types.
Example: Mukesh is a Customer(EntityTypeId: 01) in Retail domain with Telos Id: 100 and in HealthCare as Patient(EntityTypeId: 02) with Telos Id: 200,
There for Mukesh, Link Id is the common id in both domain to identify that Mukesh is the same person.
Initial Implementation:
`<EntityTypeId, <bizIdValue , linkId>>`.
`<EntityTypeId, <linkId , bizIdValue>>`.
eg:
```
<Customer(01) , Primary-biz-id , linkId>
<Customer(01) , linkId , Primary-biz-id>
<Patient(02) , Primary-biz-id , linkId>
<Patient(02) , linkId , Primary-biz-id>
```
Checks can be done via comparing