Versions Compared

Key

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

Table of Contents
Specification 

...

Search Medication Request

  1. Search record by `$.id` in column `medication_request.id
    1. If not found -  Search record by `$.id` in column `medication_request.request_number`
      1. If not found - Return  404 in case "Not found record in DB with this ID!"

Validate FK

  1.  Read data from `ops_db.medication_requests` by `id`
  2. Validate legal_entity_id - legal_entity_id exists
    • Return 422 in case validation fails (422 EView)
  3. Validate employee_id - employee_id exists
    • Return 422 in case validation fails (422 EView)
  4. Validate division_id - division_id exists
    • Return 422 in case validation fails (422 EView)
  5. Validate medical_program_id - medical_program_id exists
    • Return 422 in case validation fails (422 EView)
  6. Validate all medication_id - medication_id exists
    • Return 422 in case validation fails (422 EView)
  7. Validate person_id - mpi_id exists
    • Return 422 in case validation fails (422 EView)

...

  1. Get `my_party_id`  from `$.context.user_id`
    1. Return 500 in case ("Not found party for this user!")  
  2. Get list from `prm.employees` for this `party_id`  & `$.context.legal_entity_id`
  3. Search Medication requests by filters: 


  4. Code Block
    languagesql
    SELECT * FROM medication_request MR
        INNER JOIN employees E
            ON E.party_id = my_party_id
                AND (E.id = $.employee_id OR $.employee_id IS NULL)
                AND (E.legal_entity_id == $.context.legal_entity_id OR $.context.legal_entity_id IS NULL)
        LEFT JOIN declarations D
            ON D.Employee_id = E.id 
                AND E.status = ACTIVE
                AND D.status = ACTIVE
                AND MR.person_id = D.person_id
    WHERE (MR.id = $.id OR MR.request_number = $.id) 
    	AND MR.employee_id == E.id
    	AND MR.is_active = TRUE
       


...

  1. Search Medication request by $.id: 

    Code Block
    languagesql
    SELECT * FROM medication_request MR
    WHERE (MR.id = $.id OR MR.request_number = $.id) 
    	AND MR.is_active = TRUE
       


Response (output)

...