ЕСОЗ - публічна документація

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 37 Next »

Validate request


Validate request using JSON schema

JSON Schema
{

  "$schema": "http://json-schema.org/draft-04/schema#",

  "definitions": {

    "phone": {

      "type": "object",

      "properties": {

        "type": {

          "type": "string",

          "enum": [

            "MOBILE",

            "LANDLINE"

          ]

        },

        "number": {

          "type": "string",

          "pattern": "^\\+38[0-9]{10}$"

        }

      },

      "required": [

        "type",

        "number"

      ],

      "additionalProperties": false

    },

    "name": {

      "type": "string",

      "pattern": "^(?!.*[ЫЪЭЁыъэё@%&$^#])[a-zA-ZА-ЯҐЇІЄа-яґїіє0-9№\\\"!\\^\\*)\\]\\[(._-].*$"

    },

    "tax_id": {

      "type": "string",

      "pattern": "^[1-9]([0-9]{7}|[0-9]{9})$",

      "minLength": 10

    },

    "address": {

      "type": "object",

      "properties": {

        "type": {

          "type": "string",

          "description": "Dictionary: ADDRESS_TYPE"

        },

        "country": {

          "type": "string"

        },

        "area": {

          "$ref": "#/definitions/name"

        },

        "region": {

          "$ref": "#/definitions/name"

        },

        "settlement": {

          "$ref": "#/definitions/name"

        },

        "settlement_type": {

          "type": "string"

        },

        "settlement_id": {

          "type": "string"

        },

        "street_type": {

          "type": "string"

        },

        "street": {

          "$ref": "#/definitions/name"

        },

        "building": {

          "type": "string",

          "pattern": "^[1-9]([0-9]{1,2})?(([ \\-]{1})?(?![ЫЪЭЁыъэё])[А-ЯҐЇЄа-яґїє]{1})?((\\s)?(\\\\|\/)(\\s)?[1-9]([0-9]{1,2})?(([ \\-]{1})?(?![ЫЪЭЁыъэё])[А-ЯҐЇЄа-яґїє]{1})?)?$"

        },

        "apartment": {

          "type": "string"

        },

        "zip": {

          "type": "string",

          "pattern": "^[0-9]{5}$"

        }

      },

      "required": [

        "type",

        "country",

        "area",

        "settlement",

        "settlement_type",

        "settlement_id",

        "building"

      ],

      "additionalProperties": false

    },

    "document": {

      "type": "object",

      "properties": {

        "type": {

          "type": "string",

          "enum": [

            "PASSPORT",

            "NATIONAL_ID",

            "BIRTH_CERTIFICATE",

            "TEMPORARY_CERTIFICATE",

            "COURT_DECISION"

          ]

        },

        "number": {

          "type": "string"

        }

      },

      "required": [

        "type",

        "number"

      ],

      "additionalProperties": false

    },

    "authentication_method": {

      "type": "object",

      "properties": {

        "type": {

          "type": "string",

          "enum": [

            "OTP",

            "OFFLINE"

          ]

        },

        "phone_number": {

          "type": "string",

          "pattern": "^\\+38[0-9]{10}$"

        }

      },

      "required": [

        "type",

        "phone_number"

      ],

      "additionalProperties": false

    }

  },

  "type": "object",

  "properties": {

    "declaration_request": {

      "type": "object",

      "properties": {

        "start_date": {

          "type": "string",

          "format": "date-time",

          "description": "Should be defined on the client side."

        },

        "person": {

          "type": "object",

          "properties": {

            "first_name": {

              "type": "string",

              "items": {

                "$ref": "#/definitions/name"

              },

              "minLength": 1

            },

            "last_name": {

              "type": "string",

              "items": {

                "$ref": "#/definitions/name"

              },

              "minLength": 1

            },

            "second_name": {

              "type": "string",

              "items": {

                "$ref": "#/definitions/name"

              },

              "minLength": 1

            },

            "birth_date": {

              "type": "string",

              "format": "date"

            },

            "birth_country": {

              "type": "string",

              "minLength": 1

            },

            "birth_settlement": {

              "type": "string",

              "items": {

                "$ref": "#/definitions/name"

              },

              "minLength": 1

            },

            "gender": {

              "type": "string",

              "enum": [

                "MALE",

                "FEMALE"

              ]

            },

            "email": {

              "type": "string",

              "format": "email"

            },

            "tax_id": {

              "type": "string",

              "items": {

                "$ref": "#/definitions/tax_id"

              }

            },

            "secret": {

              "type": "string",

              "items": {

                "$ref": "#/definitions/name"

              },

              "minLength": 6

            },

            "documents": {

              "type": "array",

              "minItems": 1,

              "items": {

                "$ref": "#/definitions/document"

              }

            },

            "addresses": {

              "type": "array",

              "items": {

                "$ref": "#/definitions/address"

              },

              "minItems": 2

            },

            "phones": {

              "type": "array",

              "items": {

                "$ref": "#/definitions/phone"

              }

            },

            "authentication_methods": {

              "type": "array",

              "items": {

                "$ref": "#/definitions/authentication_method"

              }

            },

            "emergency_contact": {

              "type": "object",

              "properties": {

                "first_name": {

                  "type": "string",

                  "items": {

                    "$ref": "#/definitions/name"

                  },

                  "minLength": 1

                },

                "last_name": {

                  "type": "string",

                  "items": {

                    "$ref": "#/definitions/name"

                  },

                  "minLength": 1

                },

                "second_name": {

                  "type": "string",

                  "items": {

                    "$ref": "#/definitions/name"

                  },

                  "minLength": 1

                },

                "phones": {

                  "type": "array",

                  "items": {

                    "$ref": "#/definitions/phone"

                  },

                  "minItems": 1

                }

              },

              "required": [

                "first_name",

                "last_name",

                "phones"

              ],

              "additionalProperties": false

            },

            "confidant_person": {

              "type": "array",

              "items": {

                "type": "object",

                "properties": {

                  "relation_type": {

                    "type": "string",

                    "enum": [

                      "PRIMARY",

                      "SECONDARY"

                    ]

                  },

                  "first_name": {

                    "type": "string",

                    "items": {

                      "$ref": "#/definitions/name"

                    },

                    "minLength": 1

                  },

                  "last_name": {

                    "type": "string",

                    "items": {

                      "$ref": "#/definitions/name"

                    },

                    "minLength": 1

                  },

                  "second_name": {

                    "type": "string"

                  },

                  "birth_date": {

                    "type": "string",

                    "format": "date"

                  },

                  "birth_country": {

                    "type": "string",

                    "minLength": 1

                  },

                  "birth_settlement": {

                    "type": "string",

                    "items": {

                      "$ref": "#/definitions/name"

                    },

                    "minLength": 1

                  },

                  "gender": {

                    "type": "string",

                    "enum": [

                      "MALE",

                      "FEMALE"

                    ]

                  },

                  "tax_id": {

                    "type": "string",

                    "items": {

                      "$ref": "#/definitions/tax_id"

                    }

                  },

                  "secret": {

                    "type": "string",

                    "items": {

                      "$ref": "#/definitions/name"

                    },

                    "minLength": 6

                  },

                  "documents_person": {

                    "type": "array",

                    "minItems": 1,

                    "items": {

                      "$ref": "#/definitions/document"

                    }

                  },

                  "documents_relationship": {

                    "type": "array",

                    "minItems": 1,

                    "items": {

                      "$ref": "#/definitions/document"

                    }

                  },

                  "phones": {

                    "type": "array",

                    "items": {

                      "$ref": "#/definitions/phone"

                    }

                  }

                },

                "required": [

                  "relation_type",

                  "first_name",

                  "last_name",

                  "birth_date",

                  "birth_country",

                  "birth_settlement",

                  "gender",

                  "secret",

                  "documents_person",

                  "documents_relationship"

                ],

                "additionalProperties": false

              },

              "description": "Should be set if this Person is disabled, underage, etc."

            },

            "patient_signed": {

              "type": "boolean",

              "enum": [

                false

              ]

            },

            "process_disclosure_data_consent": {

              "type": "boolean",

              "enum": [

                true

              ]

            }

          },

          "required": [

            "first_name",

            "last_name",

            "birth_date",

            "birth_country",

            "birth_settlement",

            "gender",

            "secret",

            "documents",

            "addresses",

            "authentication_methods",

            "emergency_contact",

            "patient_signed",

            "process_disclosure_data_consent"

          ],

          "additionalProperties": false,

          "description": "Object that described a Patient. Confidant person should be set for disabled persons, underage persons, etc."

        },

        "employee_id": {

          "type": "string",

          "minLength": 36,

          "description": "Employee ID with `type=DOCTOR` selected from available Employees as a third contract party."

        },

        "division_id": {

          "type": "string",

          "minLength": 36,

          "description": "Registered Medical Service Provider Division identifier."

        },

        "scope": {

          "type": "string",

          "enum": [

            "family_doctor"

          ]

        }

      },

      "required": [

        "person",

        "employee_id",

        "division_id",

        "scope"

      ],

      "additionalProperties": false

    }

  }

}


Authorize

    1. Verify the validity of access token
    2. Check user scope declaration_request:create in order to perform this action

Validate doctor

Get employee details

Invoke Get employee details

Validate Response $.data.employee_type == DOCTOR

Calculate patient age

Calculate patient age

age = MONTHS_BETWEEN (now(), $.declaration_request.person.birth_date) / 12

Get global parameters

Invoke Global parameters to get following parameters:

  • ADULT_AGE
  • DECLARATION_TERM
cURL example
curl -X GET \
  {:host}/prm/api/global_parameters
Response example
{
  "meta": {
    "url": "http://api-svc.prm/api/global_parameters",
    "type": "object",
    "request_id": "ikff7hcf0hhto5c06irl9i976kc3s41m",
    "code": 200
  },
  "data": {
    "verification_request_expiration": "30",
    "employ_request_expiration": "30",
    "declaration_term": "30",
    "declaration_request_expiration": "30",
    "billing_date": "2",
    "adult_age": "18",
    "type": "global_parameter"
  }
}


Check that doctor speciality meets the patient age requirements

Check age requirements according to values in response from previous step.

Doctor specialityAge
FAMILY DOCTORAll ages
THERAPISTGreater or equal to $.data.adult_age
PEDIATRICIANLess than $.data.adult_age

Check phone number

Invoke Check phone number WS in order to check phone number exists in DB.

Phone number: $.declaration_request.person.phones.[0].number

cURL example
curl -k -L '{:host}/verifications/+380508887700'
Successful response example
{
    "meta": {
        "url": "http://dev.ehealth.world/verifications/+380936235985",
        "type": "object",
        "request_id": "b98ie5d0j3fn7vcbbmksa4k45ptue2ca",
        "code": 200
    },
    "data": {
        "phone_number": "+380936235985"
    }
}
Failed response example
{
    "meta": {
        "url": "http://dev.ehealth.world/verifications/+380936235986",
        "type": "object",
        "request_id": "b4adrhrj5og9ogqanb57dqj0v1qkbb9j",
        "code": 404
    },
    "error": {
        "type": "not_found"
    }
}


Search pending declaration requests

Search declarations in IL_DB.declaration_requests to prevent requests duplication:

  • if tax_id is not null
WHERE IL_DB.declaration_requests.data.declaration_request.person.tax_id = :($.declaration_request.person.tax_id)
  AND IL_DB.declaration_requests.data.declaration_request.legal_entity_id = :($.declaration_request.legal_entity_id)
  AND IL_DB.declaration_requests.data.declaration_request.employee_id = :($.declaration_request.employee_id)
  AND IL_DB.declaration_requests.status IN ('NEW', 'APPROVED')
  • if tax_id is null
WHERE IL_DB.declaration_requests.data.declaration_request.person.first_name = :($.declaration_request.person.first_name) 
  AND IL_DB.declaration_requests.data.declaration_request.person.last_name = :($.declaration_request.person.last_name) 
  AND IL_DB.declaration_requests.data.declaration_request.person.birth_date = :($.declaration_request.person.birth_date)
  AND IL_DB.declaration_requests.data.declaration_request.legal_entity_id = :($.declaration_request.legal_entity_id)
  AND IL_DB.declaration_requests.data.declaration_request.employee_id = :($.declaration_request.employee_id)
  AND IL_DB.declaration_requests.status IN ('NEW', 'APPROVED')


Cancel declaration requests

Change status of all found declarations:

SET   IL_DB.declaration_requests.status = 'CANCELED'
WHERE IL_DB.declaration_requests.id IN (:LIST)

Calculate declaration end/start date

Start date:

start_date = Current_date()

End date:

if (person.age < 18) {
  end_date = min(birth_date + 18y - 1d, start_date + declaration_term);
} else {
  end_date = start_date + declaration_term;
}


Save declaration request

Insert record to IL.declaration_request in status 'NEW'

Search MPI

Search patient in MPI using personal information

Query paramSource

first_name

$.declaration_request.person.first_name

last_name

$.declaration_request.person.last_name
second_name$.declaration_request.person.second_name
birth_date$.declaration_request.person.birth_date
tax_id$.declaration_request.person.tax_id
phone_number$.declaration_request.person.phones.number
birth_certificate$.declaration_request.person.documents
  • if declaration_request has tax_id
    • search using tax_id + birth_date
  • if declaration_request doesn't have tax_id
    • search using first_name+last_name+birth_date
  • if patient age in declaration_request < 16
    • search using birth_certificate+birth_date


Sample request
curl -k -L '{:host}/api/persons?first_name=Олена&last_name=Пчілка&birth_date=1991-08-19&tax_id=3126509816&phone_number=%2B380508887700&birth_certificate=FG456789'


Determine default auth method for new MPI

Invoke Gandalf to obtain auth method according to internal rules:

cURL example
curl --user GNDF_CLIENT_ID:GNDF_CLIENT_SECRET \
     --header 'X-Application: GNDF_APPLICATION_ID'  \
     --data '{"phone_availability": {value}, "preferable_auth_method": {value}}' \
     {:host}/api/v1/tables/GNDF_TABLE_ID/decisions

Set IL.declaration_request.authentication_method_current:

Update auth method
{
  "authentication_method": GandalfResponse.$.data.final_decision,
  "authentication_number": DeclarationRequest.$.declaration_request.person.authentication_methods.[0].number
}


Determine preferable auth method for existing MPI

Set IL.declaration_request.authentication_method_current:

Update auth method
{
  "authentication_method": SearchMPIResponse.$.data.authentication_method.type,
  "authentication_number": SearchMPIResponse.$.data.authentication_method.number
}


Generate printout form

Invoke MAN to render print form.

Request mapping:

ParameterSource
idDECLARATION REQUEST
cURL example
curl --request POST \
     --header 'Accept: text/html' \
     --header 'Content-Type: application/json' \
     {:host}/templates/{:declaration_printout_id}/actions/render


Set IL.declaration_request.printout_content:

MANResponse.$.data

Generate upload URL

Each link is generated for one one-page document in jpeg format. Document should be no more than 10MB.

Document URL's generation logic

For Online and Offline

1. Generetae URL with type person.DECLARATION_FORM 

For Offline only

2. If $.declaration_request.person.tax_id not null:

  • Generate URL with type person.SSN

3. For each $.declaration_request.person.documents:

  • Generate URL's with type person.{$.declaration_request.person.documents.[:].type}

4. If $.declaration_request.person.confidant_person.[:].tax_id not null, for each:

  • Generate URL with type confidant_person.{confidant_person.type}.SSN

5. For each $.declaration_request.person.confidant_person.[:].documents_person:

  • Generate URL's with type confidant_person.{confidant_person.type}.{$.declaration_request.person.confidant_person.[:].documents_person.[:].type}

6. For each $.declaration_request.person.confidant_person.[:].documents_relationship:

  • Generate URL's with type confidant_person.{confidant_person.type}.{$.declaration_request.person.confidant_person.[:].documents_relationship.[:].type}

Invoke Media Content Storage to generate upload URL for each document obtained by executing logic above

IL.declaration_request.documents structure:


{
   "documents":[
      {
         "type":"person.SSN",
		 "url": "https://storage.googleapis.com/..."
      }
   ]
}

Save documents to DB.

Generate verification code

Invoke Initialize OTP to generate one time password and send it to client number.

Phone_number: IL.declaration_request.authentication_method_current.$.authentication_number

cURL example
curl -X POST \
  http://localhost:4000/verifications \
  -H 'content-type: application/json' \
  -d '{
  "phone_number": "+380936235985"
}'

Generate link for personal online cabinet 

Extract person.email from request

  1. if person.email is not null
    1. generate link to personal online cabinet - TBD


  • No labels