更新
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\model\tcm;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
/**
|
||||
* 诊单复诊到期快照模型(每诊单一行,当前周期 = 最新有效业务订单)
|
||||
*
|
||||
* 写入方:RevisitDueService::refreshDiagnoses(cron / 钩子 / 列表自愈)与需求 4 的延迟/已联系/关闭接口。
|
||||
* 时间相关状态(到期/预警/超期/过号/已约)不落列,由 RevisitDueCalculator::deriveState 按事实列 + today 推导。
|
||||
*
|
||||
* @package app\common\model\tcm
|
||||
*/
|
||||
class DiagnosisRevisitDue extends BaseModel
|
||||
{
|
||||
protected $name = 'tcm_diagnosis_revisit_due';
|
||||
|
||||
// 自动时间戳类型设置为整型(表无 delete_time 列)
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'create_time';
|
||||
protected $updateTime = 'update_time';
|
||||
protected $deleteTime = false;
|
||||
|
||||
// 取出字段保持整型,前端按需要再格式化
|
||||
protected $dateFormat = false;
|
||||
|
||||
/** 周期状态:进行中 */
|
||||
public const CLOSED_OPEN = 0;
|
||||
/** 周期状态:已挂号(自动关闭,待面诊) */
|
||||
public const CLOSED_BOOKED = 2;
|
||||
/** 周期状态:已面诊(自动关闭) */
|
||||
public const CLOSED_VISITED = 3;
|
||||
/** 周期状态:人工关闭 */
|
||||
public const CLOSED_MANUAL = 4;
|
||||
/** 周期状态:失效(无医助 / 诊单删除或禁用 / 无有效订单) */
|
||||
public const CLOSED_INVALID = 5;
|
||||
|
||||
/** @var array<int,string> */
|
||||
public const CLOSED_STATE_TEXT_MAP = [
|
||||
self::CLOSED_OPEN => '进行中',
|
||||
self::CLOSED_BOOKED => '已挂号',
|
||||
self::CLOSED_VISITED => '已面诊',
|
||||
self::CLOSED_MANUAL => '人工关闭',
|
||||
self::CLOSED_INVALID => '失效',
|
||||
];
|
||||
|
||||
/** 用药起算来源:无 */
|
||||
public const ANCHOR_NONE = 0;
|
||||
/** 用药起算来源:物流签收 */
|
||||
public const ANCHOR_SIGN = 1;
|
||||
/** 用药起算来源:人工发货日志 */
|
||||
public const ANCHOR_SHIP = 2;
|
||||
/** 用药起算来源:下单时间 */
|
||||
public const ANCHOR_CREATE = 3;
|
||||
|
||||
/** @var array<int,string> */
|
||||
public const ANCHOR_SRC_TEXT_MAP = [
|
||||
self::ANCHOR_NONE => '',
|
||||
self::ANCHOR_SIGN => '签收起',
|
||||
self::ANCHOR_SHIP => '发货起',
|
||||
self::ANCHOR_CREATE => '下单起',
|
||||
];
|
||||
|
||||
/** 天数来源:缺失(或配置兜底) */
|
||||
public const DAYS_SRC_NONE = 0;
|
||||
/** 天数来源:订单 medication_days */
|
||||
public const DAYS_SRC_ORDER = 1;
|
||||
/** 天数来源:处方 usage_days */
|
||||
public const DAYS_SRC_RX = 2;
|
||||
|
||||
/** @var array<int,string> */
|
||||
public const DAYS_SRC_TEXT_MAP = [
|
||||
self::DAYS_SRC_NONE => '缺开药天数',
|
||||
self::DAYS_SRC_ORDER => '订单',
|
||||
self::DAYS_SRC_RX => '处方',
|
||||
];
|
||||
|
||||
/** 锚点订单之后最新有效挂号状态:无 */
|
||||
public const APPT_NONE = 0;
|
||||
/** 已约(doctor_appointment.status=1) */
|
||||
public const APPT_BOOKED = 1;
|
||||
/** 已面诊(status=3) */
|
||||
public const APPT_VISITED = 3;
|
||||
/** 已过号(status=4) */
|
||||
public const APPT_MISSED = 4;
|
||||
|
||||
/** @var array<int,string> */
|
||||
public const APPOINTMENT_STATE_TEXT_MAP = [
|
||||
self::APPT_NONE => '未挂号',
|
||||
self::APPT_BOOKED => '已约',
|
||||
self::APPT_VISITED => '已面诊',
|
||||
self::APPT_MISSED => '已过号',
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 周期状态文本
|
||||
*/
|
||||
public function getClosedStateTextAttr($value, $data): string
|
||||
{
|
||||
$v = (int) ($data['closed_state'] ?? 0);
|
||||
|
||||
return self::CLOSED_STATE_TEXT_MAP[$v] ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 用药起算来源文本
|
||||
*/
|
||||
public function getAnchorSrcTextAttr($value, $data): string
|
||||
{
|
||||
$v = (int) ($data['anchor_src'] ?? 0);
|
||||
|
||||
return self::ANCHOR_SRC_TEXT_MAP[$v] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 开药天数来源文本
|
||||
*/
|
||||
public function getDaysSrcTextAttr($value, $data): string
|
||||
{
|
||||
$v = (int) ($data['days_src'] ?? 0);
|
||||
|
||||
return self::DAYS_SRC_TEXT_MAP[$v] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 挂号事实状态文本
|
||||
*/
|
||||
public function getAppointmentStateTextAttr($value, $data): string
|
||||
{
|
||||
$v = (int) ($data['appointment_state'] ?? 0);
|
||||
|
||||
return self::APPOINTMENT_STATE_TEXT_MAP[$v] ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 最近重算时间格式化(Y-m-d H:i)
|
||||
*/
|
||||
public function getComputedAtTextAttr($value, $data): string
|
||||
{
|
||||
$ts = (int) ($data['computed_at'] ?? 0);
|
||||
|
||||
return $ts > 0 ? date('Y-m-d H:i', $ts) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 下次提醒时间格式化(Y-m-d H:i)
|
||||
*/
|
||||
public function getNextRemindAtTextAttr($value, $data): string
|
||||
{
|
||||
$ts = (int) ($data['next_remind_at'] ?? 0);
|
||||
|
||||
return $ts > 0 ? date('Y-m-d H:i', $ts) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 用药起算日(Y-m-d)
|
||||
*/
|
||||
public function getAnchorDateAttr($value, $data): string
|
||||
{
|
||||
$ts = (int) ($data['anchor_ts'] ?? 0);
|
||||
|
||||
return $ts > 0 ? date('Y-m-d', $ts) : '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user