Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Оновив згідно PSYHO-177.
Table of Contents

Purpose

This WS allows to create medical program provision by divisions of user’s legal entity. It shows what divisions provides medical program according to legal entity contract.

Key points

  1. This is a REST method.

  2. Only authenticated and authorized legal entity owner with appropriate scope can create a Medical program provision.

  3. Request should be signed with DS.

  4. User can add multiple divisions at once to provide a medical program.

Specification

Apiary

Authorization

  • Verify the validity of access token

    • in case of error - return 401 “Invalid access token” in case of validation fails

  • Verify that token is not expired

    • in case of error - return 401 “Invalid access token”

  • Check user scopes in order to perform this action (scope = 'medical_program_provision:write')

    • return 403 “Your scope does not allow to access this resource. Missing allowances: medical_program_provision:write” in case of invalid scope(s)

Validate Digital Sign

  • Validate request is signed

    • in case of error - return 422 “document must be signed by 1 signer but contains 0 signatures”

  • Check DS is valid and not expired

  • Validate that DS belongs to the user

    • Check that DRFO from DS and party.tax_id matches

      • in case of error - return 409 “Signer DRFO doesn't match with requester tax_id“

Validate legal entity

  • Extract client_id from token.

  • Check client scopes in order to perform this action (scope = 'medical_program_provision:write')

    • in case of error - return 403 “Your scope does not allow to access this resource. Missing allowances: medical_program_provision:write”

  • Check legal entity status (status = ACTIVE, SUSPENDED)

    • In case of error - return 422 “Legal entity is not active”

Validate request

  1. Validate contract_number:

    1. Select contract_number from contracts where:

      1. type = REIMBURSEMENT

      2. is_active=true

      3. status = VERIFIED 

      4. contractor_legal_entity = client_id (from token)

        1. in case of error - return 422 “Your legal entity has no reimbursement contract with number <contract_number> or it is not active”

  2. Validate medical_program_id:

    1. Сheck program exists and active

      1. in case of error - return 422 “Medical program not found”

    2. Check medical program belongs to the contract

      1. in case of error - return 422 “Medical program does not belong to contract”

  3. Validate divisions :

    1. Check divisions are not duplicated in the array

      1. in case of error - return 422 “Division list has duplicated identifiers in the request”

    2. For each division in the array:

      1. Validate it exists and active (is_active = true and status = ACTIVE):

        1. in case of error - return 422 “Division with id <id> does not exist or not active”

      2. If chart parameter DISPENSE_DIVISION_DLS_VERIFY is on, then validate it DLS verified (dls_verified=true)

        1. in case of error - return 422 “Division with id <id> is not verified in DLS”

      3. Validate it belongs to the legal entity (client_id from token)

        1. in case of error - return 422 “Division with id <id> does not belong to legal entity”

      4. Validate there is no existing active records with the same division, medical program and contract number

        1. in case of error - return 422 “The medical program has already been provided by division with id <id> according to the contract“

Service logic

  1. Save signed content to media storage. Look at Bucket structure for details.

  2. Save records to the database according to Data model