123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?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()
- {
-
- $testSteps = [
- 'MCB Primary? YES',
- [
- 'criteriaName'=>'MCP',
- 'arguments'=>[
- 'pro_id'=>'d88b20df-4c2e-430a-a7a1-7d08fbbc1c82'
- ]
- ]
- ];
- $query = Client::whereRaw('id > :id', ['id' => 0]);
- $query = $this->queryBuilder($query, $testSteps);
- $this->info("The count is: ".$query->count());
- $records = $query->get();
- foreach($records as $record){
- $this->info($record->uid);
- }
- }
-
- function queryBuilder($query, $testCriteria){
- foreach($testCriteria as $criterion){
- $clause = '';
- $params = [];
- if(is_string($criterion)){
- // $clause = $this->criteria[$criterion]['clause'];
- // $params = $this->criteria[$criterion]['arguments'];
- $query = $query->whereRaw($this->criteria[$criterion]);
- }
- if(is_array($criterion)){
- $criteriaName = $criterion['criteriaName'];
- $clause = $this->criteria[$criteriaName]['clause'];
- $params = $criterion['arguments'];
- $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' => "(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)"
- ]
- ];
- }
|