123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace App\Console\Commands;
- use App\Repositories\Models\TCM\Combinations;
- use App\Repositories\Models\TCM\Prescription;
- use App\Repositories\Models\TCM\Recipels;
- use App\Services\CombinationService;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- /**
- * Class PresenterCommand
- * @package Prettus\Repository\Generators\Commands
- * @author Anderson Andrade <contato@andersonandra.de>
- */
- class InitRecipelsCommand extends Command
- {
- /**
- * The name of command.
- *
- * @var string
- */
- protected $name = 'init:recipels';
- /**
- * The description of command.
- *
- * @var string
- */
- protected $description = 'Create a new recipels.';
- /**
- * The type of class being generated.
- *
- * @var string
- */
- protected $type = 'Recipels';
- /**
- * Execute the command.
- *
- * @return void
- * @see fire()
- */
- public function handle()
- {
- DB::table('tcm_recipels')->truncate();
- DB::table('tcm_combinations')->truncate();
- $prescriptions = Prescription::query()->get();
- foreach ($prescriptions as $prescription) {
- $this->init($prescription);
- }
- $this->line('ok');
- }
- public function init(Prescription $prescription)
- {
- Recipels::query()->where('prescription_id', $prescription->id)->delete();
- $data = [];
- $prescription->load(['patient', 'medical_record']);
- foreach ($prescription->drugs as $drug) {
- $d = [
- 'patient_id' => $prescription->patient_id,
- 'name' => $prescription->patient->name,
- 'sex' => $prescription->patient->sex,
- 'age' => $prescription->patient->age,
- 'medical_record_id' => $prescription->medical_record_id,
- 'chinese_tra_diagnosis' => $prescription->medical_record ? $prescription->medical_record->chinese_tra_diagnosis : '--',
- 'prescription_id' => $prescription->id,
- // 'drug_id' => isset($drug['drug']) ? $drug['drug']['id'] : 0,
- 'drug_id' => $drug['id'],
- 'drug' => $drug['name'],
- 'dose' => $drug['dose'],
- 'unit' => $drug['unit'],
- 'use' => isset($drug['use']) ? (int)$drug['use'] : 0,
- 'use_name' => isset($drug['use_name']) ? $drug['use_name'] : '',
- 'admin_id' => $prescription->admin_id
- ];
- $data[] = $d;
- }
- Recipels::query()->insert($data);
- //组合分析
- $names = array_column($prescription->drugs, 'name');
- $combinations = CombinationService::combinationALL($names);
- $cd = [];
- foreach ($combinations as $combination) {
- $cd[] = [
- 'name' => '-' . arr2str($combination, '-') . '-',
- 'count' => count($combination),
- 'prescription_id' => $prescription->id,
- 'admin_id' => $prescription->admin_id
- ];
- }
- Combinations::query()->insert($cd);
- }
- }
|