Midaz as a Pharmacy Ledger

Context

Although the concept of a ledger is closely associated with financial transactions, Midaz can be used to store a wide variety of applications that require transactions to function. A classic example of this is using Midaz for inventory management in a pharmacy.

Let's suppose a large pharmaceutical company called Doe's Pharma operates in the United States, Canada, Brazil, Spain, and Angola. For this, in North America, it has another parent organization with two ledgers, and for the other countries, it has directly linked ledgers, as shown in Figure 1.

Implementation

Imagine that the pharmaceutical company has various medications, including Novalgina, Dipirona, and Aspirin. Each of these medications would be an instrument created using the Create an Instrument endpoint, as shown below.

POST /v1/organizations/{{id}}/ledgers/{{id}}/instruments

Body:

{
  "name": "NOVALGINE",
  "type": "others",
  "code": "NOV-12345-S-BL", //SKU
  "metadata": {
    "internalRate": 5
  }
}

201:

{
  "id": "bb907427-5a8c-4622-b1ce-801b70e40d0c",
  "organizationId": "cc15194a-6bc9-4ebb-b15d-43411a54ba4b",
  "ledgerId": "77b0fb8b-1bd9-4810-9c6d-7e80064fab0c",
  "name": "NOVALGINE",
  "type": "others",
  "code": "ABC-12345-S-BL", //SKU
  "metadata": {
    "internalRate": 5
  }
  "status": {
    "code": "ACTIVE",
    "description": null
  },
  "createdAt": "2024-02-08T17:03:12+0300",
  "updatedAt": "2024-02-08T17:03:12+0300",
  "deletedAt": null
}

Once this is done, a portfolio could be created for each store in the network using the Create a Portfolio endpoint.

POST /v1/organizations/{{id}}/ledgers/{{id}}/portfolios

Body:

{
  "entityId": "1b8037e8-459d-4bf4-a1f9-0d075b500910",
  "name": "Doe's Pharma Soho",
  "status": {
    "code": "available",
    "description": null
  },
  "metadata": {
    "plainAddress": "447, Broadway"
  }
}

201:

{
  "id": "298c1e79-00b8-4f4b-a045-dd7300213b7a",
  "entityId": "1b8037e8-459d-4bf4-a1f9-0d075b500910",
  "ledgetId": "77b0fb8b-1bd9-4810-9c6d-7e80064fab0c",
  "organizationId": "5f3a4c55-8b28-4276-bed7-f7c8a4bb44e8",
  "name": "Doe's Pharma Soho",
  "status": {
    "code": "available",
    "description": null
  },
  "metadata": {
    "plainAddress": "447, Broadway"
  }
  "createdAt": "2024-02-08T16:59:31+0300",
  "updatedAt": "2024-02-08T16:59:31+0300",
  "deletedAt": null
}

And for each pharmacy, two accounts would be created: one to represent the quantity of medications in the stock and the other for the quantity of medications on the shelves for sale, using the Create an Account endpoint.

POST /v1/organizations/{{id}}/ledgers/{{id}}/portfolios/{{id}}/accounts

Body:

{
  "instrumentCode": "NOV-12345-S-BL",
  "alias": "soho_main",
  "type": "deposit"
}

201:

{
  "id": "776c4fcd-62dc-4aaa-842c-6bbcbe35ed76",
  "entityId": "1b8037e8-459d-4bf4-a1f9-0d075b500910",
  "ledgetId": "77b0fb8b-1bd9-4810-9c6d-7e80064fab0c",
  "organizationId": "5f3a4c55-8b28-4276-bed7-f7c8a4bb44e8",
  "parentAccountId": null,
  "productId": null,
  "name": "My NOV-12345-S-BL account",
  "status": {
    "code": "ACTIVE",
    "description": null
  },
  "allowSending": true,
  "allowReceiving": true,
  "alias": "soho_main",
  "instrumentCode": "NOV-12345-S-BL",
  "type": "deposit",
  "balance": {
    "available": 0,
    "onHold": 0,
    "scale": 0
  },
  "createdAt": "2024-02-08T16:59:31+0300",
  "updatedAt": "2024-02-08T16:59:31+0300",
  "deletedAt": null
}

With this setup, whenever a medication is sold, it would move from the soho_main account to the @external/NOV-12345-S-BL account (the account representing assets leaving the ledger because they were sold). Whenever inventory is moved from the stock to the shelves, it would move from the soho_warehouse account to the soho_main account, and whenever it is restocked, the reverse path would be followed. Thus, during report generation, the total inventory of the pharmacy, as well as the purchases and sales of medications, could be generated using Midaz's infrastructure.

Going even further, if users were to pay using a digital account from Doe's Pharma, the financial flow could also be handled using Midaz.

Last updated