Purpose
This WS is designed to create new medication.
Specification
Logic
This method is used to create Medications. Fields descriptions are listed in request Example view.
Request structure
See on Apiary
Example:
Authorize
Verify the validity of access token
Check user scope (scope = 'medication:write') in order to perform this action
In case error - generate 401 response
Request to process the request using a token in the headers
Headers
Наприклад:
Content-Type:application/json
Authorization:Bearer c2778f3064753ea70de870a53795f5c9
Request data validation
Validate FK
Purpose validation: Check on existing Substance/Innm in ingredients
Check exist `Medications` by $.ingredients[].id.
if invalid - return 422 error (message: "INNM in ingredients is not found!")
Validate status & type ingredients
Purpose validation: Id's in ingredients must be active
Invoke GetInnmByID($.ingredients[].id). Check exist any innm.is_active=FALSE.
if exists - return 422 error (message: "INNM in ingredients must be active!")
Purpose validation: Ingredients for TYPE=BRAND must be TYPE=INNM_DOSAGE
Check exists Ingredients with type=BRAND.
if exists - return 422 error (message: "Only INNM_DOSAGE can be ingredients!")
Validate status ingredients.is_primary
Purpose validation: in ingredients only one item must be is primary (TRUE)
Calculate count() where is_primary=TRUE in ingredients. Check count()>=1.
if invalid - return 422 error (message: "One of ingredients must be is primary!")
Validate Equal Dosage & Container
Purpose validation: Denumerator unit from Ingredients.dosage must be equal Numerator unit from Container.
Check exist any ($.ingredients[].dosage.denumerator_unit != $.container.numerator_unit).
if invalid - return 422 error (message: "Denumerator unit from Dosage ingredients must be equal Numerator unit from Container medication!")
Validate multiplicity
Purpose validation: Package_qty for container_dosage must have multiplicity package_min_qty. Result (Mod or % operator) must = 0 .
MEDICATION - Validate multiplicity (Mod == 0) $.package_qty Mod $.package_min_qty == 0
if result NOT 0 - return 409 error (message: "Only a multiplicity package quantity for the minimum package quantity medication!")
Validate atc code
Validate value according to regex ^[abcdghjlmnprsvABCDGHJLMNPRSV]{1}[0-9]{2}[a-zA-Z]{2}[0-9]{2}$
in case of error return ('Invalid code')
Check that all elements in array of atc_code are different
in case of error return 422 error (message `atc codes are duplicated`)
Validate request
Validate request using features.
Processing
Saving innm dosage and medication occurs in one table - prm.medications. They are separated by the parameter type - innm_dosage and brand. Therefore, some fields may not be filled in when creating an innm dosage or medication. For example, max_daily_dosage is filled for innm dosage, but not filled for medication, etc.
Create new record in Medications
Fill data
Destination | Source |
---|---|
id | |
name | $.name |
TYPE | MEDICATION |
is_active | TRUE |
form | $.form |
ingredients | $.ingredients |
container | $.container |
package_qty | $.package_qty |
package_min_qty | $.package_min_qty |
code_atc | $.code_atc |
manufacturer | $.manufacturer |
certificate | $.certificate |
expired_certificate_at | $.expired_certificate_at |
inserted_at | :timestamp |
inserted_by | user_id |
updated_at | :timestamp |
updated_by | user_id |
daily_dosage | number |
Create new Ingredients
Create new record in Ingredients from $.ingredients
Fill data
Destination | Source |
---|---|
id | |
dosage | $.ingredients.dosage |
parent_id | medication_id |
innm_child_id | NULL |
medication_child_id | $.ingredients.innm_dosage_id |
is_primary | $.ingredients.is_primary |
inserted_at | :timestamp |
inserted_by | user_id |
updated_at | :timestamp |
updated_by | user_id |
Response structure
See on Apiary
Example:
Post-processing processes
API paragraph not found