Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Оновлено згідно 14.12.2021 PreProd 8.3.0
Table of Contents

Authorize

...

Validate request using JSON schema

Expand
language
Code Block
json
 {
  "$schema": "http://json-schema.org/declaration_request_new/schema#",
  "type": "object",
  "properties": {
    "person_id": {
      "type": "string"
    },
    "employee_id": {
      "type": "string"
    },
    "division_id": {
      "type": "string"
    },
    "authorize_with": {
      "type": "string"
    }
  },
  "required": [
    "person_id",
    "employee_id",
    "division_id"
  ]
}

...

Take the doctor_id and the division_id from the token

Validate person person 

  • validate person_id UUID

    • in case error return 422

  • search person by person_id in MPI 

    • in case error return 404, "Such person doesn't exist"

  • validate person.auth_method != NA

    • in case error return 422, "Person must have authentication method"

  • validate person.status = ‘active’ and is_active =true

    • in case error return 404, "Such person doesn't exist"

Validate person verification status

  • validate patient's verification_status is not equal to NOT_VERIFIED.

    • in case of error return 409, "Patient is not verified"

Validate authorize_with

The person can pass the id of his auth_method which he wants to confirm the create declaration request. The necessary auth method can be found by making Get person's auth methods

  1. validate auth_method.id is UUID

    1. in case error return 422

  2. search auth method in MPI.person_authentication_method

    1. in case error return 422, "such authentication method doesn't exist"

  3. search auth method of this person where  MPI.person_authentication_method.person_id = $.person.id

    1. in case error return 422, "such authentication method does not belong to this person"

  4. validate that auth_method.type = NA

    1. in case error return 422, "Сannot be confirmed by a method with type= NA. Use a different method."

  5. validate that this method is active ( authentication_method.ended_at > now() and is_active = true)

...

Calculate patient age

Calculate patient age

Code Block
age = MONTHS_BETWEEN (now(), $.mpi.person.birth_date) / 12

Check that doctor speciality meets the patient age requirements

  1. Get doctor's speciality_officio (speciality object where speciality_officio == true)

  2. Check age requirements according to global parameters

Speciality officio

Age

FAMILY DOCTOR

All ages

THERAPIST

Greater or equal to $.data.adult_age

PEDIATRICIAN

Less than $.data.adult_age

Validate confidant person

...

  • in case error return 422 - msg "Confidant person is mandatory for children"

Processing

Search pending declaration requests

Search declarations in IL_DB.declaration_requests to prevent requests duplication:

...

Change status of all found declarations:

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

Calculate declaration end/start date

Declaration 

Start date:

Code Block
start_date = Current_date()

End date:

Code Block
if (person.age < prm.global_parametrs.adult_age)&(doctor.speciality = PEDIATRICIAN) {
  end_date = min(birth_date + prm.global_parametrs.adult_age - 1d, start_date + declaration_term - 1d);
} else {
  end_date = start_date + declaration_term - 1d;
}


Save declaration request

Insert record to IL.declaration_request in status 'NEW'

Generate upload URL

If auth_method_requests.auth_method_current = OFFLINE

...

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

Set auth_method_current

Set default auth method of person on IL.auth_method_request.auth_method_current - use use function in  in mpi, that return default auth method.

If auth_method_current = NA - return Error Error "person authentication method is undefined".

Generate verification code

If auth_method_requests.auth_method_current = OTP 

Invoke Initialize OTP to generate one time password and send it where auth_method_requests.auth_method_current = OTP.

cURL example

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

Generate human readable declaration number

  • Use algorithm to generate declaration_number

  • Declaration number should consist of a 4 serial symbols and 8 number symbols and looks like XXXX-12H4-245D

  • Add field to ops.declarations and il.declaration_requests - declaration_number 

  • Add declaration_number to print out form

...