Skip to content

Creating Prescriptions

Creating Prescriptions

DELPHOS supports two prescription creation paths: manual creation by the physician and auto-creation from a completed consultation session. Both paths produce a prescription in draft status ready for item management, safety checking, and signing.

Prescription Lifecycle

draft → pending_review → validated → signed → submitted → dispensed
│ │
└────────────────────────────────→ cancelled ───────────────┘
StatusDescription
draftInitial state — editable, items can be added or modified
pending_reviewSubmitted for review; requires at least one item
validatedReviewed and approved; valid_until must be provided
signedSigned by the prescribing doctor; signed_by UUID required
submittedSent to pharmacy or dispensing system
dispensedMedication dispensed to the patient (terminal state)
cancelledVoided — reason is required (terminal state)

Manual Prescription Creation

Creates a standalone prescription not linked to a consultation. Items are added in separate calls after creation.

Endpoint

POST /v1/prescriptions

Request body

FieldTypeRequiredDefaultDescription
patient_idUUIDYesFK to patients table
doctor_idUUIDYesFK to doctors table
consultation_idUUIDNonullOptional link to a consultation session
originstringNo"manual""manual", "consultation", or "imported"
prescription_typestringNo"standard""standard" or "controlled"
notesstringNonullFree-text notes

Response

Returns { prescription: PrescriptionDetail }. Manual prescriptions start with empty items and interactions arrays.

Terminal window
curl -X POST "https://your-instance.delphos.app/v1/prescriptions" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"patient_id": "d4e5f6a7-b8c9-0123-defa-234567890123",
"doctor_id": "e5f6a7b8-c9d0-1234-efab-345678901234",
"prescription_type": "standard",
"notes": "Patient reports difficulty swallowing tablets."
}'

Auto-Creation from a Consultation

The auto-create endpoint reads medication entities extracted from a completed consultation, matches them against the drug database, runs drug interaction safety checks, and assembles a draft prescription ready for physician review.

Endpoint

POST /v1/prescriptions/auto-create

Request body

FieldTypeRequiredDescription
consultation_idUUIDYesFK to consultation_sessions
patient_idUUIDYesFK to patients
doctor_idUUIDYesFK to doctors (prescribing physician)

Status codes

CodeMeaning
201Prescription created — full detail with items and interactions
409Prescription already exists for this consultation
422No medication entities found in the consultation
500Internal error during creation
Terminal window
curl -X POST "https://your-instance.delphos.app/v1/prescriptions/auto-create" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"consultation_id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
"patient_id": "d4e5f6a7-b8c9-0123-defa-234567890123",
"doctor_id": "e5f6a7b8-c9d0-1234-efab-345678901234"
}'

Managing Prescription Items

Items represent individual medications. They can be added to draft or pending_review prescriptions.

Add an item

POST /v1/prescriptions/{prescription_id}/items
FieldTypeRequiredDescription
medication_namestringYesMedication name as prescribed
dosagestringYesDosage string, e.g. "500mg"
routestringYesAdministration route, e.g. "oral"
frequencystringYesDosing frequency, e.g. "8/8h"
active_ingredientstringNoActive ingredient (principio ativo)
durationstringNoTreatment duration, e.g. "7 dias"
quantityintegerNoPrescribed quantity (must be >= 1)
unitstringNoUnit of measure, e.g. "comprimidos"
instructionsstringNoPatient-facing instructions
clinical_notesstringNoInternal notes for the prescriber
cmed_medication_idUUIDNoOptional link to the drug database
Terminal window
curl -X POST "https://your-instance.delphos.app/v1/prescriptions/PRESCRIPTION_ID/items" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"medication_name": "Amoxicilina",
"active_ingredient": "AMOXICILINA TRIIDRATADA",
"dosage": "500mg",
"route": "oral",
"frequency": "8/8h",
"duration": "7 dias",
"quantity": 21,
"unit": "capsulas",
"instructions": "Tomar 1 capsula de 500mg via oral a cada 8 horas."
}'

Update an item

PATCH /v1/prescriptions/{prescription_id}/items/{item_id}

All fields are optional. Only provided fields are changed.

Remove an item

DELETE /v1/prescriptions/{prescription_id}/items/{item_id}

Update Prescription Metadata

Only prescriptions in draft or pending_review status can be updated.

PATCH /v1/prescriptions/{prescription_id}
FieldTypeDescription
notesstringUpdated free-text notes
valid_untildatetimeUpdated expiry datetime
prescription_typestring"standard" or "controlled"

Status Transitions

Advance the prescription through its lifecycle with a single endpoint.

PATCH /v1/prescriptions/{prescription_id}/status
FieldTypeRequired whenDescription
statusstringAlwaysTarget status value
signed_byUUIDstatus = "signed"UUID of the signing doctor
valid_untildatetimestatus = "validated"Prescription expiry timestamp
reasonstringstatus = "cancelled"Cancellation reason text
Terminal window
curl -X PATCH "https://your-instance.delphos.app/v1/prescriptions/PRESCRIPTION_ID/status" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"status": "signed", "signed_by": "e5f6a7b8-c9d0-1234-efab-345678901234"}'

List and Retrieve Prescriptions

List prescriptions

GET /v1/prescriptions

Optional query parameters: patient_id, doctor_id, status, origin, consultation_id, date_from, date_to, limit (1-100, default 20), offset (default 0).

Response shape: { items: [...], total: integer, limit: integer, offset: integer }.

Get a single prescription

GET /v1/prescriptions/{prescription_id}

Returns the full PrescriptionDetail including items, detected interactions, safety summary, and signing readiness fields:

FieldDescription
can_signfalse when critical/contraindicated interactions are unacknowledged
blocking_interactions_countCount of interactions blocking signing
pending_acknowledgements_countCount of all unacknowledged interactions

Templates

Reuse common medication sets across prescriptions.

Save as a template

POST /v1/prescriptions/{prescription_id}/save-as-template
FieldTypeRequiredDescription
namestringYesUnique template name within the tenant
descriptionstringNoOptional description

Returns 201. Returns 409 if the template name already exists.

Create from a template

POST /v1/prescriptions/from-template
FieldTypeRequiredDescription
template_idUUIDYesTemplate to copy items from
patient_idUUIDYesFK to patients
doctor_idUUIDYesFK to doctors
consultation_idUUIDNoOptional consultation link

Returns 201 with the created prescription containing all items from the template.


Complete Manual Workflow

  1. Create prescriptionPOST /v1/prescriptions returns a draft prescription with an empty items list.

  2. Add medicationsPOST /v1/prescriptions/{id}/items for each medication.

  3. Run safety checkPOST /v1/prescriptions/{id}/safety-check detects drug interactions.

  4. Acknowledge interactions — Review any flagged interactions (see Drug Safety).

  5. Submit for reviewPATCH /v1/prescriptions/{id}/status with {"status": "pending_review"}.

  6. ValidatePATCH /v1/prescriptions/{id}/status with {"status": "validated", "valid_until": "2026-05-14T23:59:00Z"}.

  7. SignPATCH /v1/prescriptions/{id}/status with {"status": "signed", "signed_by": "doctor-uuid"}.