Răsfoiți Sursa

added criteria test

= 3 ani în urmă
părinte
comite
5452a690db
1 a modificat fișierele cu 144 adăugiri și 0 ștergeri
  1. 144 0
      app/Console/Commands/TestCriteriaQueries.php

+ 144 - 0
app/Console/Commands/TestCriteriaQueries.php

@@ -0,0 +1,144 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\Client;
+use Illuminate\Console\Command;
+
+class TestCriteriaQueries extends Command
+{
+
+
+
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'criteria:test';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Test criteria queries';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+       
+        $testCriteria = [
+            'MCB Primary? YES',
+            [
+                'criteria'=>'MCP',
+                'arguments'=>[
+                    'pro_id'=>'d88b20df-4c2e-430a-a7a1-7d08fbbc1c82'
+                ]
+            ]
+        ];
+
+        $query = Client::whereRaw('id > :id', ['id' => 0]);
+
+        $query = $this->queryBuilder($query, $testCriteria);
+
+        $this->info("The count is: ".$query->count());
+    }
+
+   
+
+    function queryBuilder($query, $testCriteria){
+
+   
+
+        foreach($testCriteria as $criterion){
+
+            $clause = '';
+            $params = [];
+
+            if(is_string($criterion)){
+                $clause = $this->criteria[$criterion]['clause'];
+                $params = $this->criteria[$criterion]['arguments'];
+            }
+            if(is_array($criterion)){
+                $criteriaName = $criterion['criteria'];
+                $clause = $this->criteria[$criteriaName]['clause'];
+                $params = $criterion['arguments'];             
+            }
+
+            $this->info($query->toSql());
+            $this->info(json_encode($params));
+            $query = $query->whereRaw($clause, $params);
+        }
+    
+        return $query;
+    }
+    
+
+
+    protected $criteria = [
+
+        //with preset arguments
+        'Client active? YES' => "()",
+        'Client active? NO' => "()",
+        'MCP assigned? YES' => "()",
+        'MCP assigned? NO' => "()",
+        'Future MCP appointment? YES' => "()",
+        'Future MCP appointment? NO' => "()",
+
+        'MCB Primary? YES' => [
+            'clause' => 'is_part_b_primary = :is_part_b_primary',
+            'arguments'=>['is_part_b_primary'=>'YES']
+        ],
+
+        'MCB Primary? NO' => "()",
+        'Has active RM device? YES' => "()",
+        'Has active RM device? NO' => "()",
+        'Active device type? Weight' => "()",
+        'Active device type? BP' => "()",
+        'Active device type? Weight ONLY' => "()",
+        'Active device type? BP ONLY' => "()",
+        'Active device type? Weight + BP' => "()",
+        'Type 2 Diabetic' => "(client.id IN (SELECT client_id FROM dx))",
+
+        //with user defined arguments
+        'MCP' => [
+            'argument_ui_map' => [
+                'pro_uid' => [
+                    'field_type' => 'record',
+                    'table' => 'pro',
+                    'display' => '{name_display} - {npi}',
+                    'value' => 'uid' 
+                ]
+            ],
+            'arguments' => ['pro_uid'],
+            'clause' => "(client.mcp_pro_id = (SELECT pro.id FROM pro WHERE pro.uid = :pro_uid))"
+        ],
+        'Chart Creation Date Between' => [
+            'argument_ui_map' => [
+                'starting_date' => [
+                    'field_type' => 'date'
+                ],
+                'ending_date' => [
+                    'field_type' => 'date'
+                ]
+            ],
+            'arguments' => ['starting_date', 'ending_date'],
+            'clause' => "(client.created_at::DATE >= :starting_date AND client.created_at::DATE =< :ending_date)"
+        ]
+    ];
+}