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

RC_(CSI-1323)_Approve declaration request v3

Purpose

This WS is used to approve previously created Declaration Request.

Specification

Apiary

Key points

  1. In case if persons current authentication method is OTP, request body must contain verification_code field with OTP.

  2. For any other authentication method, request body must be empty, but additional documents upload is needed for OFFLINE authentication method.

Validate request

  1. Validate request using JSON schema

    1. In case validation failed - generate 422 error

JSON Schema 

{   "$schema": "http://json-schema.org/draft-04/schema#",   "type": "object",   "properties": {     "verification_code": {       "type": "string"     }   },   "required": [     "verification_code"   ],   "additionalProperties": false }

Authorize user

  1. Verify the validity of access token

  2. Check user scopes declaration_request:write in order to perform this action

    1. In case error - generate 401 response

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 confidant person relationship

If authorize_with of declaration request is not empty and contains auth method with type = THIRD_PERSON - validate that person from value is an approved confidant for a person from request – exists active and approved confidant person relationship between person from request and person_id from authentication method value (using following logic: Check confidant person relationship with person_id = person from request and confidant_person_id = value from auth method - expected :ok, :approved response)

  1. in case of error - return 409 ‘Cannot be confirmed by method with not approved confidant person relationship’

Get declaration request details

Get declaration request from IL_DB.declaration_request

Determine authorization method

Get authorization_method from IL_DB.declaration_request

SELECT IL_DB.declaration_request.authentication_method FROM   IL_DB.declaration_request WHERE IL_DB.declaration_request.id = :id

If authentication_method_current is NULL - return Error

If authentication_method_current == OFFLINE - check uploaded document

If authentication_method_current = OTP - verify SMS code

If authentication_method_current = NA - verify Parent declaration

Verify code

Invoke verification module to verify OTP

OTP Verification

Check uploaded documents

Invoke Media Content Storage to check documents exist

Media Content Storage

Verify Parent declaration

Get parent_declaration_id from IL_DB.declaration_requests.parent_declaration_id:

  • If parent_declaration_id is null, validate declaration request with current authentication_method_current = NA logic

  • If parent_declaration_id is not null, check that parent declaration exists and in status 'active'

    • In case of error - return 404 (‘Active parent declaration was not found’)

Processing

Generate printout form

Prepare data for declaration request printout form

  1. Call MAN service to render printout form

  2. Get template id from config (DECLARATION_REQUEST_PRINTOUT_FORM_TEMPLATE_ID)

  3. Prepare printout content based on declaration request data

  4. Render printout form and save to declaration request

If authorize_with of declaration request is not empty and contains auth method with type = THIRD_PERSON - confidant person is required, preload Confidant person object from MPI using auth method value:

  • get confidant person details from persons table

  • get confidant person documents from person_documents table

  • get relation documents from confidant_person_relationship_documents table

Use obtained data for following structure:

%{ full_name: get_full_name(confidant_person), phones: get_phone(confidant_person), birth_date: confidant_person |> Map.get("birth_date") |> convert_date(), gender: get_gender(confidant_person), birth_settlement: Map.get(confidant_person, "birth_settlement", ""), birth_country: Map.get(confidant_person, "birth_country", ""), documents_person: get_document(confidant_person, "documents_person", @documents_dict), tax_id: Map.get(confidant_person, "tax_id", ""), documents_relationship: get_document(confidant_person, "documents_relationship", @relationship_documents_dict), preferred_way_communication: get_preferred_way_communication(Map.get(confidant_person, "preferred_way_communication") || "––"), email: Map.get(confidant_person, "email") || "––" }

 

Set IL.declaration_request.printout_content:

MANResponse.$.data

Change patient_signed and process_disclosure_data_consent values

If parent_declaration_id is not null and authentication_method_current = NA, update following fields values at data_to_be_signed field:

  • patient_signed = null

  • process_disclosure_data_consent = null

Generate hash ‘seed’

Generate hash seed - Hash of previous block in declarations chain or other random component that should be signed with declaration

Change declaration request

  1. Change entity status in IL_DB.declaration_request to APPROVED

  2. Set status_reason to doctor_confirmed

  3. Set is_shareable to true

  4. Set updated_at - now() (Get current date-time)

  5. Set updated_by - user_id (Extract user from token)

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