Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevel1
maxLevel3

Required parameters are marked with "*"

...

Purpose*

This WS is designed to create new medication.

...

Expand
titleRequest example
Code Block
{
  "name": "Амідарон",
  "manufacturer": {
    "name": "ПАТ \"Київський вітамінний завод\"",
    "country": "UA"
  },
  "code_atc": [
    "М01АЕ01",
    "C01BD01"
  ],
  "form": "PILL",
  "container": {
    "numerator_unit": "PILL",
    "numerator_value": 1,
    "denumerator_unit": "PILL",
    "denumerator_value": 1
  },
  "package_qty": 30,
  "package_min_qty": 10,
  "certificate": "UA/4514/01/01",
  "certificate_expired_at": "2021-02-09",
  "daily_dosage": "12",
  "ingredients": [
    {
      "id": "1349a693-4db1-4a3f-9ac6-8c2f9e541982",
      "dosage": {
        "numerator_unit": "MG",
        "numerator_value": 200,
        "denumerator_unit": "PILL",
        "denumerator_value": 1
      },
      "is_primary": true
    }
  ]
}

Authorize*

  1. Verify the validity of access token

  2. Check user scope (scope = 'medication:write') in order to perform this action

    1. 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

...

Purpose validation: Check on existing Substance/Innm in ingredients 

  1. Check exist `Medications` by $.ingredients[].id.

    1. 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  

  1. Invoke GetInnmByID($.ingredients[].id). Check exist any innm.is_active=FALSE.

    1. if exists - return 422 error (message: "INNM in ingredients must be active!")

Purpose validation: Ingredients for TYPE=BRAND must be TYPE=INNM_DOSAGE

  1. Check exists Ingredients with type=BRAND.

    1. 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)  

  1. Calculate count() where is_primary=TRUE in ingredients. Check count()>=1.

    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.

  1. Check exist any  ($.ingredients[].dosage.denumerator_unit != $.container.numerator_unit).

    1. 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 .

  1. MEDICATION - Validate multiplicity (Mod == 0) $.package_qty Mod $.package_min_qty == 0

  2. if result NOT 0 - return 409 error (message: "Only a multiplicity package quantity for the minimum package quantity medication!")

Validate atc code

  1. Validate value according to regex ^[abcdghjlmnprsvABCDGHJLMNPRSV]{1}[0-9]{2}[a-zA-Z]{2}[0-9]{2}$

    1. in case of error return ('Invalid code')

  2. Check that all elements in array of atc_code are different 

    1. in case of error return 422 error (message `atc codes are duplicated`)

Validate request

Validate request using features.

...

Info

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.

  1. Create new record in Medications 

  2. 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

  1. Create new record in Ingredients from $.ingredients

  2. 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

...