<?php

namespace Application\Service\Extension\Middleware\components;

use Application\Form\item\patient\PatientFormModel;
use Application\Service\Extension\Laminas;
use Application\Service\Extension\Middleware\BaseMiddlewareComponent;

/**
 * 自动更新患者访视表单进度情况
 */
class HandlePatientWorkBatch extends BaseMiddlewareComponent
{
    /** @var PatientFormModel $owner */
    public $owner;
    public int $operate_type;
    public function __construct(array $params = [])
    {
        parent::__construct($params);
        $params['operate_type'] = $params['operate_type'] ?? 11; // 默认新增

        $this->owner = &$params['owner'];
        $this->operate_type = &$params['operate_type'];
    }

    function execute()
    {
        Laminas::$serviceManager->projectPatientworkbatch->generatorWorkData([
            'item_id' => $this->owner->itemId,
            'itemsig_id' => $this->owner->itemsigId,
            'patient_id' => $this->owner->patientId,
            'checktime_id' => $this->owner->checktimeId,
            'form_id' => $this->owner->formId,
            'content_id'=> $this->owner->contentPrimaryKey
        ]);

        //异步处理访视进度情况信息
        $form_content_arr = !empty($this->owner->contentPrimaryKey) ? [$this->owner->contentPrimaryKey] : [];
        Laminas::$serviceManager->swTaskClient->send([
            'svName' => 'projectPatientworkbatch',
            'methodName' => 'multipleUpdateData',
            'params' => [
                'item_id' => $this->owner->itemId,
                'itemsig_id' => $this->owner->itemsigId,
                'patient_id' => $this->owner->patientId,
                'checktime_id' => $this->owner->checktimeId,
                'form_id' => $this->owner->formId,
                'operate_type'=>$this->operate_type,
                'content_id'=>!empty($form_content_arr) ? $form_content_arr : []
            ]
        ]);
        unset($form_content_arr);
    }
}