123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- declare(strict_types=1);
- namespace app\model;
- use think\Model;
- /**
- * 患者辅助诊疗信息模型
- * Class PatientAuxiliaryDiagnosis
- * @package app\model
- */
- class PatientAuxiliaryDiagnosis extends Model
- {
- /**
- * 数据表名称
- * @var string
- */
- protected $name = 'jm_patient_auxiliary_diagnosis';
- /**
- * 自动写入时间戳
- * @var bool
- */
- protected $autoWriteTimestamp = true;
- /**
- * 创建时间字段
- * @var string
- */
- protected $createTime = 'create_time';
- /**
- * 更新时间字段
- * @var string
- */
- protected $updateTime = 'update_time';
- /**
- * 类型常量定义
- */
- const TAG_AUXILIARY = 'auxiliary'; // 辅助诊疗
- const TAG_KNOWLEDGE = 'knowledge'; // 知识库
- const TAG_REVIEW = 'review'; // 医嘱审核
- /**
- * 性别常量定义
- */
- const GENDER_MALE = '男';
- const GENDER_FEMALE = '女';
- /**
- * 允许批量赋值的字段
- * @var array
- */
- protected $allowField = [
- 'zyh',
- 'name',
- 'content',
- 'tag',
- 'xb',
- 'nl',
- 'document',
- 'docter',
- 'ygdm',
- 'ksdm'
- ];
- /**
- * 字段类型转换
- * @var array
- */
- protected $type = [
- 'nl' => 'integer',
- 'create_time' => 'timestamp',
- 'update_time' => 'timestamp'
- ];
- /**
- * 根据住院号获取记录
- * @param string $zyh
- * @return array
- */
- public static function getByZyh(string $zyh): array
- {
- return self::where('zyh', $zyh)->select()->toArray();
- }
- /**
- * 根据类型获取记录
- * @param string $tag
- * @return array
- */
- public static function getByTag(string $tag): array
- {
- return self::where('tag', $tag)->select()->toArray();
- }
- /**
- * 根据科室代码获取记录
- * @param string $ksdm
- * @return array
- */
- public static function getByKsdm(string $ksdm): array
- {
- return self::where('ksdm', $ksdm)->select()->toArray();
- }
- /**
- * 根据员工代码获取记录
- * @param string $ygdm
- * @return array
- */
- public static function getByYgdm(string $ygdm): array
- {
- return self::where('ygdm', $ygdm)->select()->toArray();
- }
- /**
- * 添加记录
- * @param array $data
- * @return bool
- */
- public static function addRecord(array $data): bool
- {
- $model = new self();
- return $model->save($data);
- }
- /**
- * 更新记录
- * @param int $id
- * @param array $data
- * @return bool
- */
- public static function updateRecord(int $id, array $data): bool
- {
- return self::where('id', $id)->update($data);
- }
- /**
- * 删除记录
- * @param int $id
- * @return bool
- */
- public static function deleteRecord(int $id): bool
- {
- return self::where('id', $id)->delete();
- }
- /**
- * 根据住院号和类型更新或插入记录
- * @param string $zyh 住院号
- * @param string $tag 类型
- * @param array $data 更新或插入的数据
- * @return bool
- */
- public static function updateOrInsert(string $zyh, string $tag, array $data): bool
- {
- // 查找是否存在记录
- $record = self::where([
- 'zyh' => $zyh,
- 'tag' => $tag
- ])->find();
-
- if ($record) {
- // 存在则更新
- return $record->save(array_merge($data, [
- 'zyh' => $zyh,
- 'tag' => $tag
- ]));
- } else {
- // 不存在则插入
- $model = new self();
- return $model->save(array_merge($data, [
- 'zyh' => $zyh,
- 'tag' => $tag
- ]));
- }
- }
- }
|