Versions Compared

Key

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

Specification

...

Code Block
"""
Fields to filter medication in the system.
"""
input MedicationFilter {
  "Primary key identifier from the database."
  databaseId: UUID
  "Medicalation name."
  name: String
  "Activeness status."
  isActive: Boolean
  "Medication form."
  form: String
  "INNMDosage filter."
  innmDosages: INNMDosageFilter
  "Manufacturer filter."
  manufacturer: ManufacturerFilter
  "Anatomical Therapeutic Chemical Classification System"
  atcCode: String
}

"""
Manufacturer filter.
"""
input ManufacturerFilter {
  "Manufactorer name"
  name: String
}

"""
Methods to use when ordering `Medication`.
"""
enum MedicationOrderBy {
  "Sort Medication by form in ascending order."
  FORM_ASC
  "Sort Medication by form in descending order."
  FORM_DESC
  "Sort Medication by inserted_at in ascending order."
  INSERTED_AT_ASC
  "Sort Medication by inserted_at in descending order."
  INSERTED_AT_DESC
  "Sort Medication by manufacturer in ascending order."
  MANUFACTURER_ASC
  "Sort Medication by manufacturer in descending order."
  MANUFACTURER_DESC
  "Sort Medication by name in ascending order."
  NAME_ASC
  "Sort Medication by name in descending order."
  NAME_DESC
}

"""
A connection to a list of `Medication` items.
"""
type MedicationConnection {
  "Information to aid in pagination."
  pageInfo: PageInfo!
  "A list of nodes."
  nodes: [Medication]
  "A list of edges."
  edges: [MedicationEdge]
}

"""
An edge in a connection of `Medication`.
"""
type MedicationEdge {
  "The item at the end of the edge."
  node: Medication!
  "A cursor for use in pagination."
  cursor: String!
}

"""
Input for `createMedication` mutation.
User must have scopes **medication:write**
"""
input CreateMedicationInput {
  "Certificate number"
  certificate: String!
  "A day when certificate expired"
  certificateExpiredAt: Date!
  "Anatomical Therapeutic Chemical Classification System"
  atcCodes: [String]!
  "A container in medication (vacuum packed box, jar, etc.)"
  container: CreateContainerInput!
  "Daily dose of medication, recommended by WHO"
  dailyDosage: Float
  "Form of medication. The value should be present in the `MEDICATION_FORM` dictionary."
  form: String!
  "Ingredients in medication"
  ingredients: [CreateMedicationIngredientInput]!
  "Company that creates medication"
  manufacturer: CreateManufacturerInput!
  "Medication name"
  name: String!
  "A minimum quantity that could be sold"
  packageMinQty: Int!
  "Quantity of pills in medication"
  packageQty: Int!
}
"""
Input for `Container` of `createMedication` mutation.
"""
input CreateContainerInput {
  "Numerator unit. The value should be present in the `MEDICATION_UNIT` dictionary."
  numeratorUnit: String!
  "Numerator value"
  numeratorValue: Int!
  "Denumerator unit. The value should be present in the `MEDICATION_UNIT` dictionary."
  denumeratorUnit: String!
  "Denumerator value"
  denumeratorValue: Int!
}
"""
Input for `MedicationIngredient` of `createMedication` mutation.
"""
input CreateMedicationIngredientInput {
  "The size or frequency of a dose of a medicine or drug."
  dosage: CreateDosageInput!
  "Is the component primary or not"
  isPrimary: Boolean!
  "innmDosage ID"
  innmDosage: ID!
}
"""
Input for `Dosage` of `createMedication` mutation.
"""
input CreateDosageInput {
  "Numerator unit. The value should be present in the `MEDICATION_UNIT` dictionary."
  numeratorUnit: String!
  "Numerator value"
  numeratorValue: Int!
  "Denumerator unit. The value should be present in the `MEDICATION_UNIT` dictionary."
  denumeratorUnit: String!
  "Denumerator value"
  denumeratorValue: Int!
}
"""
Input for `Manufacturer` of `createMedication` mutation.
"""
input CreateManufacturerInput {
  "Manufacturer country"
  country: String!
  "Manufacturer name"
  name: String!
}
"""
Return type for `createMedication` mutation.
"""
type CreateMedicationPayload {
  "Created `Medication`."
  medication: Medication
}
"""
Input for `deactivateMedication` mutation.

User must have scopes **medication:deactivate**
"""
input DeactivateMedicationInput {
  "The ID of an object"
  id: ID!
}

"""
Return type for `deactivateMedication` mutation.
"""
type DeactivateMedicationPayload {
  "Deactivated `Medication`."
  medication: Medication
}

"""
Trade mark medication. User must have a scope **medication:read**
"""
type Medication implements Node {
  "The ID of an object"
  id: ID!
  "Primary key identifier from the database"
  databaseId: UUID!
  "Medication name"
  name: String!
  "Company that creates medication"
  manufacturer: Manufacturer!
  "Anatomical Therapeutic Chemical Classification System"
  atcCodes: [String]!
  "Form of medication. The value should be present in the `MEDICATION_FORM` dictionary."
  form: String
  "A container in medication (vacuum packed box, jar, etc.)"
  container: Container!
  "Quantity of pills in medication"
  packageQty: Int!
  "A minimum quantity that could be sold"
  packageMinQty: Int!
  "Daily dose of medication, recommended by WHO"
  dailyDosage: Float
  "Certificate number"
  certificate: String!
  "A day when certificate expired"
  certificateExpiredAt: Date!
  "Ingredients in medication"
  ingredients: [MedicationIngredient]!
  "is_active status"
  isActive: Boolean!
  "type od medication"
  type: MedicationType
  "Date and time when record was inserted"
  insertedAt: DateTime!
  "Date and time when record was updated"
  updatedAt: DateTime!
}
"""
A company that makes medication.
"""
type Manufacturer {
  "Manufacturer name"
  name: String!
  "Manufacturer country"
  country: String!
}
"""
The kind of container that this package comes as.
"""
type Container {
  "Numerator unit. The value should be present in the `MEDICATION_UNIT` dictionary."
  numeratorUnit: String!
  "Numerator value"
  numeratorValue: String!
  "Denumerator unit. The value should be present in the `MEDICATION_UNIT` dictionary."
  denumeratorUnit: String!
  "Denumerator value"
  denumeratorValue: String!
}
"""
A component part of medication.
"""
type MedicationIngredient implements Ingredient {
  "The size or frequency of a dose of a medicine or drug."
  dosage: Dosage!
  "Is the component primary or not"
  isPrimary: Boolean!
  "International Nonproprietary Name"
  innmDosage: INNMDosage!
}
"""
Medication type.
"""
enum MedicationType {
  "Trade name"
  BRAND
  "Medicinal forms"
  INNM_DOSAGE
}

Purpose

This WS is designed to create new medication.

Input parameters 

  • name

  • manufacturer

     (object)

  • code_atc

  • form

  • container

     info

  • package_qty

  • package_min_qty

  • certificate

  • expired_certificate_at

  • ingredients (array)

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

Validate request

Validate request using features.

...

Table of Contents
minLevel1
maxLevel3

Required parameters are marked with "*"

Якщо інформації по відповідному параметру немає, потрібно зазначити: “APIparagraph not found”.

Purpose*

This WS is designed to create new medication.

Specification*

Page Properties

Link

https://uaehealthapi.docs.apiary.io/#reference/internal.-nhs-admin/medications/create-medication

Resource

/medications

Scope

medication:write

Components

API paragraph not found

Microservices

API paragraph not found

Protocol type

REST

Request type

POST

Sync/Async

Sync

Logic*

This method is used to create Medications. Fields descriptions are listed in request Example view.

Request structure*

See on Apiary

Example:

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

Request data validation*

Validate FK 

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.

Expand
Code Block
Feature: Create medication

  Scenario Outline: Successful creation
    Given my scope is "medication:write"
    And my client type is "NHS"
    And my consumer ID is "1ad3c0e6-e2fc-2d3c-a15c-5101874165a7"
    And the following INNM dosages exist:
      | databaseId        |
      | <innmDosageId>  |
    When I create medication with attributes:
      | name   | atcCodes   | certificate   | certificateExpiredAt   | container   | dailyDosage   | form   | ingredients   | manufacturer   | packageMinQty   | packageQty   |
      | <name> | <atcCodes> | <certificate> | <certificateExpiredAt> | <container> | <dailyDosage> | <form> | <ingredients> | <manufacturer> | <packageMinQty> | <packageQty> |
    Then no errors should be returned
    And request id should be returned
    And I should receive requested item
    And the name of the requested item should be <name>

    Examples:
      | name      | innmDosageId                           | atcCodes               | certificate | certificateExpiredAt | container                                                                                           | dailyDosage | form                           | ingredients                                                                                                                                                                                      | manufacturer                        | packageMinQty | packageQty |
      | "Ниферон" | "01c9b8ae-fe41-4390-8f3c-4744f5b13717" | ["C08CA01", "C08CA02"] | "100-fA-11" | "2019-12-12"         | {"numerator_unit": "ML", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 50}   | 0.02        | "AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 100}, "is_primary": true}]   | {"name": "Bayer", "country": "GER"} | 1             | 5          |
      | "Ниферон" | "01c9b8ae-fe41-4390-8f3c-4744f5b13717" | ["C08CA01", "C08CA02"] | "100-fA-11" | "2019-12-12"         | {"numerator_unit": "ML", "numerator_value": 0.5, "denumerator_unit": "ML", "denumerator_value": 50} | 0.01        | "AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 0.5, "denumerator_unit": "ML", "denumerator_value": 50}, "is_primary": true}] | {"name": "Bayer", "country": "GER"}  | 1             | 5          |

  Scenario: Create with incorrect scope
    Given my scope is "medication:read"
    And my consumer ID is "04796283-74b8-4632-9f7f-9e227ae9426e"
    When I create medication with attributes:
      | name      | atcCodes               | certificate | certificateExpiredAt | container                      
|
 
dailyDosage
 
|
 
form
                           
|
 
ingredients
                                    | dailyDosage | form                           | ingredients                                                                                                                   
|
  
manufacturer
                        
|
 
packageMinQty
 
|
 
packageQty
 
|
       
|
 
"Ниферон"
 
|
 
"01c9b8ae-fe41-4390-8f3c-4744f5b13717"
 
|
 
["C08CA01", "
                       | manufacturer                        | packageMinQty | packageQty |
      | "Ниферон" | ["C08CA01", "C08CA02"] | "100-fA-11" | "2019-12-12"         | {"numerator_unit": "ML", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 50}
 | 0.02        | "AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 100}, "is_primary": true}] 
| {"name": "Bayer", "country": "GER"} | 1             | 5          |
    Then the 
|
"
Ниферон
FORBIDDEN" 
| "01c9b8ae-fe41-4390-8f3c-4744f5b13717" | ["C08CA01", "C08CA02"] | "100-fA-11" | "2019-12-12"
error should be returned
    And request id should be returned
   
| {"numerator_unit": "ML", "numerator_value": 0.5, "denumerator_unit": "ML", "denumerator_value": 50} | 0.01
 And I should not receive requested item

  Scenario: Create with incorrect client
    Given my scope 
|
is "
AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 0.5, "denumerator_unit": "ML", "denumerator_value": 50}, "is_primary": true}] | {"name": "Bayer", "country": "GER"} | 1
medication:write"
    And my client type is "MSP"
    And my consumer ID is "089c0204-a191-4537-ab92-56dca268443c"
    When I create medication with attributes:
      | name      | atcCodes      
|
 
5
        | certificate | certificateExpiredAt | container 
Scenario:
 
Create
 
with
 
incorrect
 
scope
     
Given
 
my
 
scope
 
is
 
"medication:read"
     
And
 
my
 
consumer
 
ID
 
is
 
"04796283-74b8-4632-9f7f-9e227ae9426e"
     
When
 
I
 
create
 
medication
 
with
 
attributes:
       
|
 
name
      
|
 
atcCodes
               
|
 
certificate
 
|
 
certificateExpiredAt
 
|
 
container
                    | dailyDosage | form                           | ingredients                                      
|
 
dailyDosage
 
|
 
form
                           
|
 
ingredients
                                                                                                               | manufacturer                        | packageMinQty | packageQty |
      | "Ниферон" | ["C08CA01", "C08CA02"] | "100-fA-11" | "2019-12-12"         | {"numerator_unit": "ML", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 
| manufacturer
50} | 0.02        | "AEROSOL_FOR_INHALATION_DOSED" | 
| packageMinQty | packageQty | | "Ниферон" | ["C08CA01", "C08CA02"] | "100-fA-11" | "2019-12-12" |
[{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "
ML
DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 
50
100}
| 0.02 | "AEROSOL_FOR_INHALATION_DOSED"
, "is_primary": true}] | 
[
{"
innmDosageId
name": "
01c9b8ae-fe41-4390-8f3c-4744f5b13717
Bayer", "
dosage
country": 
{
"
numerator_unit": "DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 100}, "is_primary": true}] | {"name": "Bayer", "country": "GER"} | 1 |
GER"} | 1             | 5          |
    Then the "FORBIDDEN" error should be returned
    And request id should be returned
    And I should not receive requested item

  Scenario Outline: Create with 
incorrect
invalid 
client
params
    Given my scope is "medication:write"
    And my client type is "
MSP
NHS"
    And my consumer ID is "
089c0204
94e4301f-
a191
2d28-
4537
4403-
ab92
b59f-
56dca268443c
b5865e9ca26f"
    When I create medication with attributes:
      | name
   | atcCodes   | certificate   | certificateExpiredAt   | container   | 
certificate
dailyDosage 
|
 
certificateExpiredAt
 | 
container
form   | ingredients   | manufacturer   | packageMinQty   | packageQty   |
      | <name> | <atcCodes> | <certificate> | <certificateExpiredAt> | <container> | <dailyDosage> | <form> | <ingredients> | <manufacturer> | <packageMinQty> | <packageQty> |
    Then the "UNPROCESSABLE_ENTITY" error should be returned
    And request id should be returned
    And I should not receive requested item

    Examples:
      | 
dailyDosage
name      | 
form
innmDosageId                           | 
ingredients
atcCodes               | certificate | certificateExpiredAt | container                                                                                          | dailyDosage | form                           | ingredients                                       
|
 
manufacturer
                        
|
 
packageMinQty
 
|
 
packageQty
 
|
       
|
 
"Ниферон"
   
|
 
["C08CA01",
 
"C08CA02"]
 
|
 
"100-fA-11"
 
|
 
"2019-12-12"
         
|
 
{"numerator_unit":
 
"ML",
 
"numerator_value":
 
1,
 
"denumerator_unit":
 
"ML",
 
"denumerator_value":
 
50}
 
|
 
0.02
        
|
 
"AEROSOL_FOR_INHALATION_DOSED"
 
|
 
[{"innmDosageId":
 
"01c9b8ae-fe41-4390-8f3c-4744f5b13717",
 
"dosage":
 
{"numerator_unit":
 
"DOSE",
 
"numerator_value":
 
1,
 
"denumerator_unit":
 
"ML",
 
"denumerator_value":
 
100},
 
"is_primary":
 
true}]
 
|
 
{"name":
 
"Bayer",
 
"country":
 
"GER"} | 1
                  
|
 
5
          
|
     
Then
 
the
 
"FORBIDDEN"
 
error
 
should
 
be
 
returned
     
And
 
request
 
id
 
should
| 
be
manufacturer 
returned
     
And
 
I
 
should
 
not
 
receive
 
requested
 
item
    
Scenario
 
Outline:
 
Create
 
with
 
invalid
 
params
   | packageMinQty 
Given
| 
my
packageQty 
scope
|
is
 
"medication:write"
     
And
| 
my
"Ниферон" 
client type is "NHS"
| "01c9b8ae-fe41-4390-8f3c-4744f5b13717" | ["INVALID"]     
And
 
my
 
consumer
 
ID
 
is "94e4301f-2d28-4403-b59f-b5865e9ca26f
   | "100-fA-11" | "2019-12-12"     
When
 
I
 
create
 
medication
 
with attributes
| {"numerator_unit": "ML", "numerator_value": 1, "denumerator_unit": "ML", 
| name
"denumerator_value": 50}  | 
atcCodes
0.02   
|
 
certificate
   
|
 
certificateExpiredAt
| 
container | dailyDosage | form | ingredients | manufacturer | packageMinQty | packageQty |
"AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 100}, "is_primary": true}] | {"name": "Bayer", "country": "GER"} | 1             | 5 
<name>
   
|
 
<atcCodes>
 
|
 
<certificate>
 
|
 
<certificateExpiredAt>
 |
<container>
  
|
 
<dailyDosage>
 
|
 
<form>
 | 
<ingredients>
"Ниферон" | 
<manufacturer>
"01c9b8ae-fe41-4390-8f3c-4744f5b13717" |
<packageMinQty>
 ["C08CA01", "C08CA02"] | 
<packageQty>
"100-fA-11" | "2019-12-12"    
Then
 
the
 
"UNPROCESSABLE_ENTITY"
 
error
 
should
 
be returned And request id should be returned
| {"numerator_unit": "ML", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 50}  | 0.02     
And
 
I
 
should
 
not receive requested item Examples: | name | innmDosageId
| "AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 100}, "is_primary": true}] | {"name": "Bayer", "country": "GER"} | 1             | 5          
|
atcCodes

      
| 
certificate
"Ниферон" | 
certificateExpiredAt
"01c9b8ae-fe41-4390-8f3c-4744f5b13717" | 
container
["C08CA01", "C08CA02"] | "100-fA-11" | "2019-12-12"         | {"numerator_unit": "ML", "numerator_value": 1, "denumerator_unit": "MKG", "denumerator_value": 50} | 0.02        | "AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 
100}, "is_primary": true}] | {"name": "Bayer", "country": "GER"} | 1             
| dailyDosage | form
| 5          
|
ingredients | manufacturer | packageMinQty | packageQty | | "Ниферон" | "01c9b8ae-fe41-4390-8f3c-4744f5b13717" | ["INVALID"] | "100-fA-11" | "2019-12-12" | {"numerator_unit": "ML", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 50} | 0.02 | "AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 100}, "is_primary": true}] | {"name": "Bayer", "country": "GER"} | 1 | 5 | | "Ниферон" | "01c9b8ae-fe41-4390-8f3c-4744f5b13717" | ["C08CA01", "C08CA02"] | "100-fA-11" | "2019-12-12" | {"numerator_unit": "ML", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 50} | 0.02 | "AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 100}, "is_primary": true}] | {"name": "Bayer", "country": "GER"} | 1 | 5 | | "Ниферон" | "01c9b8ae-fe41-4390-8f3c-4744f5b13717" | ["C08CA01", "C08CA02"] | "100-fA-11" | "2019-12-12" | {"numerator_unit": "ML", "numerator_value": 1, "denumerator_unit": "MKG", "denumerator_value": 50} | 0.02 | "AEROSOL_FOR_INHALATION_DOSED" | [{"innmDosageId": "01c9b8ae-fe41-4390-8f3c-4744f5b13717", "dosage": {"numerator_unit": "DOSE", "numerator_value": 1, "denumerator_unit": "ML", "denumerator_value": 100}, "is_primary": true}] | {"name": "Bayer", "country": "GER"} | 1 | 5 |

Validate FK 

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`)

Create new Medication

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

...


Processing*

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

Response structure*

See on Apiary

Example:

Expand
titleResponse example
Code Block
{
  "meta": {
    "code": 201,
    "url": "https://example.com/resource",
    "type": "object",
    "request_id": "req-adasdoijasdojsda"
  },
  "data": {
    "id": "09b2bffb-699a-43c0-bc9a-5066d9b9b5a8",
    "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,
    "daily_dosage": "12",
    "certificate": "UA/4514/01/01",
    "certificate_expired_at": "2021-02-09",
    "ingredients": [
      {
        "id": "1349a693-4db1-4a3f-9ac6-8c2f9e541982",
        "name": "Амідарон",
        "dosage": {
          "numerator_unit": "MG",
          "numerator_value": 200,
          "denumerator_unit": "PILL",
          "denumerator_value": 1
        },
        "is_primary": true
      }
    ],
    "is_active": true,
    "inserted_at": "2017-04-20T19:14:13Z",
    "inserted_by": "e1453f4c-1077-4e85-8c98-c13ffca0063e",
    "updated_at": "2017-04-20T19:14:13Z",
    "updated_by": "2922a240-63db-404e-b730-09222bfeb2dd"
  }
}

Expand
titleResponse example
Code Block
{
  "meta": {
    "code": "422",
    "url": "https://example.com/resource",
    "type": "object",
    "request_id": "req-adasdoijasdojsda"
  },
  "error": {
    "type": "unverified",
    "message": "Denumerator unit from Dosage ingredients must be is equal Numerator unit from Container medication!"
  }
}

Post-processing processes*

API paragraph not found

HTTP status codes*

Page Properties

HTTP status code

Message

What caused the error

 201

 

 

 422