Vijayakrishnan 3 éve
szülő
commit
88c29df04b
1 módosított fájl, 82 hozzáadás és 0 törlés
  1. 82 0
      app/Http/Controllers/PracticeManagementController.php

+ 82 - 0
app/Http/Controllers/PracticeManagementController.php

@@ -3621,5 +3621,87 @@ ORDER BY c.name_last, c.name_first
         return view('app.practice-management.notes-resolution-center', compact('rows', 'paginator'));
     }
 
+    public function notesResolutionCenterV2(Request $request) {
+
+        $columns = "(c.name_first || ' ' || c.name_last) as client_name,
+            (hcp.name_first || ' ' || hcp.name_last) as hcp_name,
+            (na.name_first || ' ' || na.name_last) as na_name,
+            c.chart_number,
+            c.uid as client_uid,
+            n.effective_dateest,
+            n.uid,
+            n.detail_json,
+	        n.is_claim_closed,
+	        n.visit_number,
+            ROUND(b.number_of_units * 60) as minutes,
+
+ n.note_reason_icd1 AS icd1,
+ n.note_reason_icd1description AS icd1description,
+ n.note_reason_icd2 AS icd2,
+ n.note_reason_icd2description AS icd2description,
+ n.note_reason_icd3 AS icd3,
+ n.note_reason_icd3description AS icd3description,
+ n.note_reason_icd4 AS icd4,
+ n.note_reason_icd4description AS icd4description,
+ n.note_reason_memo AS icd_memo
+
+            ";
+        $from = "FROM note AS n
+            LEFT JOIN pro AS hcp ON n.hcp_pro_id = hcp.id
+            LEFT JOIN pro AS na ON n.ally_pro_id = na.id
+            JOIN client AS c ON n.client_id = c.id
+	    JOIN bill AS b ON (b.note_id = n.id AND b.is_cancelled IS NOT TRUE AND b.code ILIKE '%treatment%')
+            ";
+        $where = "WHERE
+            n.is_signed_by_hcp IS TRUE AND
+            -- n.is_claim_closed IS NOT TRUE AND
+            n.is_cancelled IS NOT TRUE AND 
+            n.created_at::DATE >= '2022-01-01'::DATE AND
+            c.client_engagement_status_category <> 'DUMMY' AND
+            c.name_first NOT ILIKE '%test%' AND 
+            c.name_last NOT ILIKE '%test%' AND
+            n.id IN (SELECT note_id FROM bill WHERE code ILIKE '%treatment%' AND bill.is_cancelled IS NOT TRUE AND note_id IS NOT NULL) AND
+            -- n.id NOT IN (SELECT note_id FROM claim WHERE note_id IS NOT NULL) AND
+            c.is_part_b_primary = 'YES' AND
+            c.latest_eligible_refresh_at::DATE >= '2022-01-01' AND
+            c.mpb_remaining = 0 AND
+            c.created_at::DATE >= '2022-01-01'::DATE
+            ";
+        $filters = [];
+        if($request->input('f')) {
+            $filters[] =  "(n.detail_json IS NOT NULL AND ((n.detail_json)::json->'farah_decision')::text = '\"" . $request->input('f') . "\"')";
+        }
+        if($request->input('s')) {
+            $filters[] =  "(n.detail_json IS NOT NULL AND ((n.detail_json)::json->'shawn_decision')::text = '\"" . $request->input('s') . "\"')";
+        }
+        if(count($filters)) {
+            $filters = 'AND ' . implode(' AND ',  $filters);
+        }
+        else {
+            $filters = '';
+        }
+        // $filters = '';
+        $orderBy = "ORDER BY c.id ASC, n.effective_dateest ASC";
+
+        $countQuery = "SELECT count(*) {$from} {$where} {$filters}";
+        // dd($countQuery);
+        $countResult = DB::select($countQuery);
+        $total = $countResult[0]->count;
+
+        $defaultPageSize = 50;
+
+        $page = $request->input('page') ?: 1;
+        $perPage = $request->input('per_page') ?: $defaultPageSize;
+        $offset = ($page - 1) * $perPage;
+
+        $dataQuery = "SELECT {$columns} {$from} {$where} {$filters} {$orderBy} OFFSET {$offset} LIMIT {$perPage}";
+        $rows = DB::select($dataQuery);
+
+        $paginator = new LengthAwarePaginator($rows, $total, $request->input('per_page') ?: $defaultPageSize, $request->input('page') ?: 1);
+        $paginator->setPath(route('practice-management.notes-resolution-center'));
+
+        return view('app.practice-management.notes-resolution-center-v2', compact('rows', 'paginator'));
+    }
+
    
 }