Specification
Apiary | |
JSON Schema request | |
JSON Schema response | SPECS |
Purpose
This WS is designed to create new innm (post).
Input parameters
- name
- form
- ingredients (array)
- id
- dosage info
- is_active_substance
Authorize
- Verify the validity of access token
- Check user scope (scope = 'innm:write') in order to perform this action
- In case error - generate 401 response
Validate request (JSON schema)
- Validate request using JSON schemas (new_medication_type_innm_schema.json):
- Return 422 with list of validation errors in case validation fails (422 EView)
Validate FK
Purpose validation: Check on existing Substance/Innm in ingredients
For Check exist `Substance` by $.ingredients[].id.
if invalid - return 422 error (message: "Substance in ingredients is not found!")
Validate status
Purpose validation: Id's in ingredients must be active
Invoke GetSubstanceByID($.ingredients[].id). Check exist any substance.is_active=FALSE.
if exists - return 422 error (message: "Substance in ingredients must be active!")
Validate status ingredients.is_active_substance
Purpose validation: in ingredients only one item must be is active substance (TRUE)
Calc count() where is_active_substance=TRUE in ingredients. Check count()=1.
if invalid - return 422 error (message: "One of ingredients must be is active substance!")
Validate substance duplication
Purpose validation: in ingredients substances can't be duplicated. Substances id has to be unique
Check uniqueness of $.ingredients[].id.
if invalid - return 422 error (message: "Ingredients can't be duplicated")
Create new Medication
- Create new record in Medications
- Fill data
Destination | Source |
---|---|
id | |
name | $.name |
type | INNM |
is_active | TRUE |
form | $.form |
ingredients | $.ingredients |
container | NULL |
package_qty | NULL |
package_min_qty | NULL |
code_atc | NULL |
manufacturer | NULL |
certificate | NULL |
expired_certificate_at | NULL |
inserted_at | :timestamp |
inserted_by | user_id |
updated_at | :timestamp |
updated_by | user_id |