services:
  db:
    image: postgres:18
    volumes:
      - pg_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: aidbox
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  aidbox:
    image: healthsamurai/aidboxone:edge
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "8888:8080"
    environment:
      BOX_DB_HOST: db
      BOX_DB_PORT: "5432"
      BOX_DB_DATABASE: aidbox
      BOX_DB_USER: postgres
      BOX_DB_PASSWORD: postgres
      BOX_SETTINGS_MODE: read-write
      BOX_BOOTSTRAP_FHIR_PACKAGES: hl7.fhir.r4.core#4.0.1
      BOX_FHIR_BUNDLE_EXECUTION_VALIDATION_MODE: limited
      BOX_FHIR_COMPLIANT_MODE: "true"
      BOX_FHIR_CORRECT_AIDBOX_FORMAT: "true"
      BOX_FHIR_CREATEDAT_URL: https://aidbox.app/ex/createdAt
      BOX_FHIR_JSON_SCHEMA_DATETIME_REGEX: "#{:fhir-datetime}"
      BOX_FHIR_SCHEMA_VALIDATION: "true"
      BOX_FHIR_SEARCH_ENGINE: jsonpath
      BOX_FHIR_SEARCH_AUTHORIZE_INLINE_REQUESTS: "true"
      BOX_FHIR_SEARCH_CHAIN_SUBSELECT: "true"
      BOX_FHIR_SEARCH_COMPARISONS: "true"
      BOX_FHIR_SEARCH_INCLUDE_CONFORMANT: "true"
      BOX_FHIR_TERMINOLOGY_SERVICE_BASE_URL: https://tx.health-samurai.io/fhir
      BOX_FHIR_TERMINOLOGY_ENGINE: hybrid
      BOX_FHIR_TERMINOLOGY_ENGINE_HYBRID_EXTERNAL_TX_SERVER: https://tx.health-samurai.io/fhir
      BOX_SECURITY_DEV_MODE: "true"
      BOX_SECURITY_AUDIT_LOG_ENABLED: "true"
      BOX_ADMIN_ID: postgres
      BOX_ADMIN_PASSWORD: postgres
      BOX_ROOT_CLIENT_ID: root
      BOX_ROOT_CLIENT_SECRET: secret
      BOX_WEB_BASE_URL: http://localhost:8888
      BOX_WEB_PORT: "8080"
    healthcheck:
      test: curl -f http://localhost:8080/health || exit 1
      interval: 5s
      timeout: 5s
      retries: 90
      start_period: 30s

  mdmbox:
    image: healthsamurai/mdmbox:latest
    depends_on:
      aidbox:
        condition: service_healthy
    ports:
      - "3000:3000"
    environment:
      # Same database as Aidbox
      BOX_DB_HOST: db
      BOX_DB_PORT: "5432"
      BOX_DB_DATABASE: aidbox
      BOX_DB_USER: postgres
      BOX_DB_PASSWORD: postgres
      # Same Aidbox settings
      BOX_SETTINGS_MODE: read-write
      BOX_BOOTSTRAP_FHIR_PACKAGES: hl7.fhir.r4.core#4.0.1
      BOX_FHIR_BUNDLE_EXECUTION_VALIDATION_MODE: limited
      BOX_FHIR_COMPLIANT_MODE: "true"
      BOX_FHIR_CORRECT_AIDBOX_FORMAT: "true"
      BOX_FHIR_CREATEDAT_URL: https://aidbox.app/ex/createdAt
      BOX_FHIR_JSON_SCHEMA_DATETIME_REGEX: "#{:fhir-datetime}"
      BOX_FHIR_SCHEMA_VALIDATION: "true"
      BOX_FHIR_SEARCH_ENGINE: jsonpath
      BOX_FHIR_SEARCH_AUTHORIZE_INLINE_REQUESTS: "true"
      BOX_FHIR_SEARCH_CHAIN_SUBSELECT: "true"
      BOX_FHIR_SEARCH_COMPARISONS: "true"
      BOX_FHIR_SEARCH_INCLUDE_CONFORMANT: "true"
      BOX_FHIR_TERMINOLOGY_SERVICE_BASE_URL: https://tx.health-samurai.io/fhir
      BOX_FHIR_TERMINOLOGY_ENGINE: hybrid
      BOX_FHIR_TERMINOLOGY_ENGINE_HYBRID_EXTERNAL_TX_SERVER: https://tx.health-samurai.io/fhir
      BOX_SECURITY_DEV_MODE: "true"
      BOX_SECURITY_AUDIT_LOG_ENABLED: "true"
      BOX_ADMIN_ID: postgres
      BOX_ADMIN_PASSWORD: postgres
      BOX_ROOT_CLIENT_ID: root
      BOX_ROOT_CLIENT_SECRET: secret

volumes:
  pg_data: {}
