<?php

namespace Application\Service\Extension\HelperV2;

use Application\Service\DB\Dictionary\FormGroup;
use Application\Service\Extension\Helper\ArrayHelper;
use Application\Service\Extension\Laminas;
use Application\Service\Extension\Store\Store;
use Exception;

class PatientHelper
{
    /**
     * @param int $patientId
     * @param int $formId
     * @param int|null $checkTimeId
     * @return array
     * @throws Exception
     */
    public function getPatientForm(int $patientId, int $formId, ?int $checkTimeId = null): array
    {
        return Store::app()->getOrSet([__CLASS__, __FUNCTION__, func_get_args()], function () use ($patientId, $formId, $checkTimeId) {
            return Laminas::$serviceManager->patientForm->fetchAll([
                'where' => ArrayHelper::filter([
                    'patient_id' => $patientId,
                    'form_id' => $formId,
                    'checktime_id' => Helper::app()->form->getGroupId($formId) == FormGroup::THROUGH_PROCESS ? null : $checkTimeId, // 贯穿全程屏蔽检查点
                    'is_del' => 0
                ])
            ]);
        });
    }
}