Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Purpose

This WS is designed to update contract by NHS by creating new contract request. Contract request is created with contract number, and parent contract is added to request. NHS Admin can change only fields that are on nhs side. 

Specification

GraphQL

Authorize

    1. Verify the validity of access token

      1. in case of error return 401 ('Access denied')

    2. Check user

  1. scope 
    1. scope contract_request:create

  2.  in
    1.  in order to perform this action

      1. in case of error generate 401 response ('Invalid scopes')

Verify role

Extract from token:

  1. Validate client_id (is_blocked=false)

    1. in case of error return 403 Error ('Client is blocked')

  2. Check legal_entity is active

    • in case error return 403 - ('Client is not active')

  3. Check legal_entity.type = 'NHS'

    1. in case error return 403 forbidden

Digital signature

Decode content that is encrypted in an electronic digital signature.
Use Digital signature WS. Method checks digital signature and returns result.

Validate EDRPOU

  1. Check

    that 

    that EDRPOU in Certificate details exists and not empty

    1. in case of error return 422 error ('Invalid EDRPOU in DS')

  2. Check

    that 

    that EDRPOU in Certificate details is equal

    to 

    to EDPOU in legal entity

    1. Get client_id from token.

    2. Find prm.legal_entities id by client_id

    3. Compare 

      Compare EDRPOU in Certificate with legal_entities.edrpou

    4. In case validation fails - generate 422 error

  3. Check that SURNAME in Certificate details is equal to LAST_NAME in Party

    1. Get user_id → user_parties.party_id → parties.last_name and compare to surname from DS

      1. Convert prm.parties.LAST_NAME and Certificate details.SURNAME to uppercase

      2. Compare prm.parties.LAST_NAME and Certificate details.SURNAME as Cyrillic letters

      3. In case validation fails - generate 422 error

Validate DRFO

  1. Get parties.tax_id using party_users.party_id by user_id.

  2. Compare DRFO in Certificate with party.tax_id

    1. Convert DRFO and TAX_ID to uppercase

    2. Compare DRFO and TAX_ID as Cyrillic letters

    3. Convert DRFO to Cyrillic and compare as Cyrillic letters

  3. In case validation fails - generate 422 error

Validations

  1. contract request number structure XXXX-1234-5678-C , where:

    1. XXXX - series: numbers + only some letters (A, E, H, K, M, P, T, X)

    2. 1234-5678 - randomly generated numbers and letters A, E, H, K, M, P, T, X. 

  2. contract_number is in request

    1. in case error return 409, "Contract number should be in payload"

  3. check there is a contract with such contract_number 

    1. in case of error return 422 error ('Contract with such contract number does not exist')

  4. contrat status = VARIFIED

    1. in case of error return 409 error ('Can not update terminated contract')

  5. Contract.is_suspended = false

    1. in case error 409, "suspended contract should be updated by contractor_owner"

  6. Check only next fields are different from contract

    1. nhs_signer_id

    2. nhs_signer_base

    3. nhs_contract_price (for capitation contracts only)

    4. nhs_payment_method

    5. issue_city

    6. Misc

    7. assignee_id

      1. in case error return 422, "Not allowed to change field $.field"

  7. Validate end_date:

    1. if $contract_number and $end_date is passed in request:

      1. the $end_date must be greater or equal then the $start_date

        1. in case of error return 422 ('The year of end_date should be one year greater or equal to start_date')

      2. the $end_date should be less than $end_date from the previous contract and less than or equal to three month

        1. in case of error return 422 ('The end_date should be greater than of the previous contract and less than or equal to three months')

    2. if $contract_number w/o $end_date is passed in request:

      1. $end_date is taken from the previous contract.


Search pending contract requests

1. Find there is no contract request 

  • for same contractor_legal_entity_id

  • within same period [start_date, end_date]

  • status in ('NEW', 'IN_PROCESS','APPROVED', 'NHS_SIGNED', 'PENGIND_NHS_SIGN')

  • id_form

  • type

  • medical_program_id (for reimbursement contracts)

In case there is such contract request change its' status to 'TERMINATE'

Save contract request

  1. status=APPROVED

  2. parent_contract_id=contract_id

  3. update fields from request, other fields should be taken from contract.

Mapping for request

contract request

old contract

edited fields by nhs

other

contractor_legal_entity_id

contractor_legal_entity_id



contractor_owner_id

contractor_owner_id



contractor_base

contractor_base



contractor_payment_details

contractor_payment_details



contractor_rmsp_amount

contractor_rmsp_amount



start_date

start_date



end_date

end_date



nhs_legal_entity_id



token.client_id

nhs_signer_id


nhs_signer_id


nhs_signer_base


nhs_signer_base


contractor_signed



false

issue_city


issue_city


status



APPROVED

status_reason



null

nhs_contract_price


nhs_contract_price


nhs_payment_method


nhs_payment_method


contract_number

contract_number



id_form

id_form



contractor_divisions



Code Block
SELECT id 


from contract_divisions 


where contract_id=parent_contract_id;

misc


misc


assignee_id


assignee_id


type

type



medical_program_id

medical_program_id



Save signed contract request to media storage

  1. Get url for contract request upload.


    Parameter
    Source
    action'GET'
    bucket'CONTRACT_REQUEST'
    resource_id: CONTRACT_REQUEST_ID
    resource_name: CONTRACT_REQUEST_APPROVED
    timestamp:TIMESTAMP


  2. Upload signed contract request to media storage

Event manage

After contract request was created by NHS as change to existed contract this change should be shown in event manager


field

value

example

event_type

ContractRequestCreateEvent


entity_type

{$.contract.type}ContractRequest

CapitationContractRequest/ReimbursementContractRequest

entity_id

$.id


properties.contract.old_value

$.parent_id


event_time

$.update_at


changed_by

$.user_id


inserted_at

now()


updated_at

now()