Explorar o código

fixed care month bill generation

= %!s(int64=3) %!d(string=hai) anos
pai
achega
0cca446d01

+ 62 - 0
app/Models/CareMonth.php

@@ -142,4 +142,66 @@ class CareMonth extends Model
         return  date('t') - date('j');
 
     }
+
+    public function calculateBillabilityForMcp(){
+
+
+        $strategy = $this->mcp->mcp_rpm_payment_strategy; 
+        if(!$strategy){
+            return [
+                'billable' => false, 
+                'reason' => 'MCP RPM strategy has not been set.'
+            ];
+        }
+        
+        $mcpRpmPaymentAmount =  $this->mcp->mcp_rpm_payment_amount;
+        $has16PlusDays = $this->number_of_days_with_remote_measurements >= 16;
+        $hasMcpBilled20Minutes = $this->rm_total_time_in_seconds_by_mcp >= 1200;
+        $hasMcpInteracted = $this->has_mcp_interacted_with_client_about_rm;
+        if($strategy == 'X16_DAYS'){
+            //only check for 16 days
+            if($has16PlusDays){
+                return [
+                    'billable' => true, 
+                    'amount' => $mcpRpmPaymentAmount
+                ];
+            } else {
+                //not billable
+                return [
+                    'billable' => false, 
+                    'reason' => "This care month does not have 16 or more measurement days."
+                ];
+            }
+        }
+    
+        if($strategy == 'X16_DAYS_20_MINS_ON_OWN_MCP_COM_DURING_CM'){
+            if ($has16PlusDays && $hasMcpBilled20Minutes && $hasMcpInteracted) {
+                return [
+                    'billable' => true, 
+                    'amount' => $mcpRpmPaymentAmount
+                ];
+            } else {
+                if(!$has16PlusDays){
+                    return [
+                        'billable' => false, 
+                        'reason' => 'Care month does not have 16 or more measurement days.'
+                    ];
+                }
+                if(!$hasMcpBilled20Minutes){
+                    return [
+                        'billable' => false, 
+                        'reason' => 'Care month does not have 20 minutes billed time.'
+                    ];
+                }
+                if(!$hasMcpInteracted){
+                    return [
+                        'billable' => false, 
+                        'reason' => 'Care month does MCP interaction.'
+                    ];
+                }
+                
+            }
+        }
+    
+    }
 }

+ 1 - 0
app/Models/Pro.php

@@ -1384,4 +1384,5 @@ WHERE crfu.client_rep_pro_id = :pro_id
   ORDER BY crfu.created_at DESC;
         "), ["pro_id" => $this->id, 'date' => date('Y-m-d')]);
     }
+
 }

+ 40 - 17
resources/views/app/patient/care-month/dashboard.blade.php

@@ -342,14 +342,6 @@
                                 </div>
                                 @endif
 
-                                {{--@if(($daysDiff !== -1 && $daysDiff <= 90) &&
-                                    $careMonth->number_of_days_with_remote_measurements >= 16 &&
-                                    $careMonth->has_mcp_interacted_with_client_about_rm)
-                                    <div class="mt-2 border border-info p-2">
-                                        @include('app.rm-bills.inline', ['patient' => $patient, 'entityType' => 'CareMonth', 'entityUid' => $careMonth->uid, 'label' => 'RM'])
-                                    </div>
-                                @endif--}}
-
                                 <div class="mt-2">
                                     {{-- rm reasons --}}
                                     <div class="mb-2">
@@ -357,16 +349,47 @@
                                     </div>
                                 </div>
 
-                                <div class="mb-2">
-                                    @if($careMonth->rmBill && $careMonth->rmBill->code != 'RMB')
-                                        @if(true && 'TODO Check if MCP and echo as needed for rme/rmm')
-
-                                        @endif
-                                        @if($performer->pro->id == $careMonth->mcp_pro_id)
-                                            Reimbursement: {{ $careMonth->rmBill->hcp_payment_amount }}
-                                        @endif
+                                @if($careMonth->mcpRmGenericBill == null )
+                                    
+                                    @php 
+                                        $rpmBillability = $careMonth->calculateBillabilityForMcp();
+                                    @endphp 
+
+                                    @if(!$rpmBillability['billable'])
+                                        <div class="alert alert-info">{{$rpmBillability['reason']}}</div>
+                                    @else 
+                                        <div moe relative class="d-inline-block">
+                                            <a class="font-weight-bold" href="" show start>Bill for {{$rpmBillability['amount']}}</a>
+                                            <form url="/api/careMonth/generateRmGenericBillForMcpAndAutoSign" right>
+                                                <input type="hidden" name="uid" value="{{$careMonth->uid}}">
+                                                <p>Bill ${{$rpmBillability['amount']}} for this care month?</p>
+                                                <div class="mb-0">
+                                                    <button class="btn btn-success btn-sm" submit>Bill &amp; Sign</button>
+                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                </div>
+                                            </form>
+                                        </div>   
                                     @endif
-                                </div>
+                                @else 
+                                    <div class="font-weight-bold">
+                                        Billed: ${{$careMonth->mcpRmGenericBill->generic_pro_expected_payment_amount}} 
+                                        @if($careMonth->mcpRmGenericBill->is_signed_by_generic_pro)
+                                            <span class="text-success"><i class="fa fa-check"></i> Signed </span>
+                                        @else 
+                                            <div moe relative class="d-inline-block">
+                                                <a class="font-weight-bold" href="" show start>Sign</a>
+                                                <form url="/api/bill/signAsGenericPro" right>
+                                                    <input type="hidden" name="uid" value="{{$careMonth->mcpRmGenericBill->uid}}">
+                                                    <p>Sign this bill?</p>
+                                                    <div class="mb-0">
+                                                        <button class="btn btn-success btn-sm" submit>Sign</button>
+                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                    </div>
+                                                </form>
+                                            </div>
+                                        @endif 
+                                    </div>
+                                @endif
                             </div>
                         </div>
                     </div>

+ 17 - 1
spec/rpt-queries.sql

@@ -105,4 +105,20 @@ COPY (
     client_engagement_status_category as status
   FROM client 
   WHERE shadow_pro_id IS NULL
-) TO '/tmp/client_appts.csv' CSV HEADER;
+) TO '/tmp/client_appts.csv' CSV HEADER;
+
+
+COPY (
+  SELECT 
+    cl.name_first,
+    cl.name_last,
+    appt.raw_date, 
+    appt.status,
+    mcp.name_first, 
+    mcp.name_last
+  FROM appointment  appt 
+  LEFT JOIN pro mcp ON appt.pro_id = mcp.id 
+  LEFT JOIN client cl ON appt.client_id = cl.id 
+  WHERE appt.raw_date >= '01-05-2022'::DATE
+  AND cl.shadow_pro_id IS NOT NULL
+) TO '/tmp/appts.csv' CSV HEADER;