provider-endpointsLab Provider

Lab Provider

Function-calling namespace: labProvider

  • Base URL: https://api.aivida.in
  • Engine endpoint: POST /api
  • Auth: Stack token middleware enabled in optional mode.

All APIs in this namespace require providerCode (v1 supported value: thyrocare).

Architecture and flow diagrams are documented in Provider Overview.

Endpoint Summary

apiNamePurpose
catalogFetch provider catalog (minPrice, maxPrice, gender, page, pageSize)
getPincodesFetch serviceability details
priceBreakupGet provider-side price computation for cart payload
searchSlotsSearch available collection slots
createOrderPay-then-book order creation
getOrderFetch provider order details by externalOrderId
listOrdersList provider orders by date/sort/page
cancelOrderRequest provider cancellation
rescheduleOrderRequest provider reschedule
getReportPull report, store in Aivida FileStorage, insert lab_result_files

Pay-Then-Book Guard (createOrder)

  • Requires organizationId, patientId, paymentId, payload.
  • paymentId must exist in Aivida with status=success.
  • If payment is already linked to a provider order, API returns existing mapping (idempotent=true) and does not rebook.
  • Success response returns:
    • providerOrderId
    • labOrderId
    • externalOrderId

Thyrocare Env Setup

Set these env vars in backend runtime (secrets should come from env/secret manager, not hardcoded in code):

THYROCARE_BASE_URL=https://api-sandbox.thyrocare.com
THYROCARE_PARTNER_ID=<partner_id>
THYROCARE_USERNAME=<username>
THYROCARE_PASSWORD=<password>
THYROCARE_ENTITY_TYPE=DSA
THYROCARE_CLIENT_TYPE=ALL
THYROCARE_API_VERSION=v1
THYROCARE_TIMEOUT_SECONDS=30

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
    "namespace": "labProvider",
    "apiName": "catalog",
    "data": {
      "providerCode": "thyrocare",
      "page": 1,
      "pageSize": 10
    }
  }'

Example Response

{
  "status": "ok",
  "data": {
    "providerCode": "thyrocare",
    "providerRaw": {}
  }
}

Payload Notes (Important)

  • searchSlots requires pincode, appointmentDate, and patient items in payload.
  • listOrders requires startDate and endDate; provider rejects future endDate.
  • createOrder is pay-then-book and fails fast if payment is missing/non-success.
  • providerRaw always contains passthrough provider payload for debugging and completeness.

Smoke Test Script

Run smoke checks from backend:

cd backend
./scripts/thyrocare_smoke.sh

Run full booking flow smoke (payment-first path):

cd backend
ORG_ID=org_test_thyro \
PAYMENT_ID=<payment_with_status_success> \
PATIENT_ID=<aivida_patient_id> \
./scripts/thyrocare_smoke.sh