Savings Search & Calculation Service

REST API for searching medications and calculating savings on packs

Overview

This service provides two main endpoints:

API Endpoints

POST /api/search

Search for medication packs. Returns a list of matching packs with details.


Request Body:
{
  "query": "metacam"
}
                

Response:
{
  "ok": true,
  "query": "metacam",
  "indexed_docs": 123,
  "total_results": 2,
  "query_time_ms": 12,
  "results": [
    {
      "id": "0196b5de-7370-7270-9b3e-7f278499806d",
      "score": 2.0,
      "fields": {
        "active_ingredients": ["Meloxicam"],
        "brand_name": "Metacam",
        "created_at": "2025-05-09T17:02:58.982075+00:00",
        "display_name": "Metacam 2mg/ml",
        "formulation": "Injection",
        "packs": [
          {
            "availability": "A",
            "content_hash": "",
            "created_at": "2025-05-09T17:23:17.854005Z",
            "display_label": "10 ml / 1 vial",
            "id": "0196b60c-d822-718b-989f-216152f608e9",
            "item_count": 10.0,
            "item_packaging": "glass vial",
            "item_unit": "ml",
            "med_profile_id": "0196b5de-7370-7270-9b3e-7f278499806d",
            "pack_count": 1,
            "pack_packaging": "",
            "pack_unit": "vial",
            "packshot": "metacam_2mg-ml_10_ml_pack",
            "updated_at": "2025-05-09T17:23:17.854005Z"
          },
          {
            "availability": "U",
            "content_hash": "",
            "created_at": "2025-05-09T17:23:17.854005Z",
            "display_label": "20 ml / 1 vial",
            "id": "0196b60c-d822-78ee-972c-5916c3cb5bc9",
            "item_count": 20.0,
            "item_packaging": "glass vial",
            "item_unit": "ml",
            "med_profile_id": "0196b5de-7370-7270-9b3e-7f278499806d",
            "pack_count": 1,
            "pack_packaging": "",
            "pack_unit": "vial",
            "packshot": "",
            "updated_at": "2025-05-09T17:23:17.854005Z"
          }
        ],
        "profile": {
          "active_ingredients": ["Meloxicam"],
          "bitesize": null,
          "brand_name": "Metacam",
          "brand_name_override": "",
          "conversion_params": null,
          "created_at": "2025-05-09T17:02:58.982075Z",
          "dispense_unit": null,
          "dose_instructions": "",
          "dose_unit": null,
          "fivr_id": null,
          "formulation": "injection",
          "give_unit": null,
          "id": "0196b5de-7370-7270-9b3e-7f278499806d",
          "manufacturer": "",
          "strength_units": ["mg/ml"],
          "strength_values": [2.0],
          "target_species": ["cat"],
          "therapeutic_terms": ["anti inflammatory nsaid"],
          "therapeutic_vernacular": [
            "non-steroidal anti-inflammatory",
            "anti-inflammatory",
            "pain relief medication",
            "arthritis medication",
            "lameness treatment"
          ],
          "updated_at": "2025-05-09T17:02:58.982075Z"
        },
        "profile_id": "0196b5de-7370-7270-9b3e-7f278499806d",
        "strength_units": ["mg/ml"],
        "strength_values": [2.0],
        "target_species": ["Cat"],
        "therapeutic_vernacular": [
          "NonSteroidalAntiInflammatory",
          "AntiInflammatory",
          "PainReliefMedication",
          "ArthritisMedication",
          "LamenessTreatment"
        ],
        "updated_at": "2025-05-09T17:02:58.982075+00:00"
      }
    },
    { "...": "additional results omitted for brevity" }
  ]
}
                

POST /api/calculate

Calculate savings for a medication pack.


Request Body:
{
  "pack_id": "uuid",
  "pack_count": 2,
  "time_course": 30,
  "current_cost": 25.00
}
                

Response:
{
  "pack_id": "uuid",
  "pack_count": 2,
  "time_course": 30,
  "current_cost": 25.00,
  "best_price_per_pack": 8.50,
  "currency": "GBP",
  "delivery_cost": 2.99,
  "delivery_type": "standard",
  "total_pack_cost": 17.00,
  "total_cost_including_delivery": 19.99,
  "estimated_annual_cost": 243.87,
  "supplier_id": "uuid",
  "delivery_times_days": [1,2],
  "processing_times_days": [1],
  "savings_per_treatment": 5.01,
  "savings_percentage": 20.04,
  "annual_savings": 61.32
}
                

Quickstart

  1. Search for a medication pack using /api/search and note the id of the pack you want.
  2. Send a POST request to /api/calculate with your pack's id, desired pack_count, time_course (days), and your current_cost.
  3. Review the response for savings details and supplier info.

Health Check

GET /api/health — Returns healthy if the service is running.