|
|
|
<?php
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace App\Http\Resources\Outpatient\Pending;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
class PendingListsResource extends JsonResource
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function toArray(Request $request = null): array
|
|
|
|
{
|
|
|
|
if (empty($this->resource)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$lists = [];
|
|
|
|
foreach ($this->resource['response'] as $v) {
|
|
|
|
// 按就诊编号合并处方
|
|
|
|
if (!isset($lists[$v['visitNumber']])) {
|
|
|
|
$lists[$v['visitNumber']] = [
|
|
|
|
'category' => $v['visitType'],
|
|
|
|
'visit_date' => date('Y-m-d', strtotime($v['visitDate'])),
|
|
|
|
'diagnosis' => $v['outpatientDiagnosis'],
|
|
|
|
'dept_id' => $v['treatmentDepartment'],
|
|
|
|
'dept_name' => $v['departmentName'],
|
|
|
|
'reg_id' => $v['regId'],
|
|
|
|
'prescription_ids' => $v['prescriptionId'],
|
|
|
|
'total_prescription_amount' => (float) $v['prescriptionAmount'],
|
|
|
|
'doctor_name' => $v['doctorName'],
|
|
|
|
'remark' => $v['remarks'],
|
|
|
|
'is_self_pay' => $v['isexpense'],
|
|
|
|
'prescription_numbers' => $v['nrescriptionNumber'],
|
|
|
|
'exec_address' => $v['takeMedicine'] ?: '',
|
|
|
|
'visit_no' => $v['visitNumber'],
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// 拼接处方号
|
|
|
|
$lists[$v['visitNumber']]['prescription_ids'] .= ','. $v['prescriptionId'];
|
|
|
|
$lists[$v['visitNumber']]['prescription_numbers'] .= ','. $v['nrescriptionNumber'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 子处方列表
|
|
|
|
$lists[$v['visitNumber']]['prescription_lists'][] = [
|
|
|
|
'prescription_id' => $v['prescriptionId'],
|
|
|
|
'single_prescription_amount' => (float) $v['singleAmount'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_values($lists);
|
|
|
|
}
|
|
|
|
}
|