PatientAuxiliaryDiagnosis.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\model;
  4. use think\Model;
  5. /**
  6. * 患者辅助诊疗信息模型
  7. * Class PatientAuxiliaryDiagnosis
  8. * @package app\model
  9. */
  10. class PatientAuxiliaryDiagnosis extends Model
  11. {
  12. /**
  13. * 数据表名称
  14. * @var string
  15. */
  16. protected $name = 'jm_patient_auxiliary_diagnosis';
  17. /**
  18. * 自动写入时间戳
  19. * @var bool
  20. */
  21. protected $autoWriteTimestamp = true;
  22. /**
  23. * 创建时间字段
  24. * @var string
  25. */
  26. protected $createTime = 'create_time';
  27. /**
  28. * 更新时间字段
  29. * @var string
  30. */
  31. protected $updateTime = 'update_time';
  32. /**
  33. * 类型常量定义
  34. */
  35. const TAG_AUXILIARY = 'auxiliary'; // 辅助诊疗
  36. const TAG_KNOWLEDGE = 'knowledge'; // 知识库
  37. const TAG_REVIEW = 'review'; // 医嘱审核
  38. /**
  39. * 性别常量定义
  40. */
  41. const GENDER_MALE = '男';
  42. const GENDER_FEMALE = '女';
  43. /**
  44. * 允许批量赋值的字段
  45. * @var array
  46. */
  47. protected $allowField = [
  48. 'zyh',
  49. 'name',
  50. 'content',
  51. 'tag',
  52. 'xb',
  53. 'nl',
  54. 'document',
  55. 'docter',
  56. 'ygdm',
  57. 'ksdm'
  58. ];
  59. /**
  60. * 字段类型转换
  61. * @var array
  62. */
  63. protected $type = [
  64. 'nl' => 'integer',
  65. 'create_time' => 'timestamp',
  66. 'update_time' => 'timestamp'
  67. ];
  68. /**
  69. * 根据住院号获取记录
  70. * @param string $zyh
  71. * @return array
  72. */
  73. public static function getByZyh(string $zyh): array
  74. {
  75. return self::where('zyh', $zyh)->select()->toArray();
  76. }
  77. /**
  78. * 根据类型获取记录
  79. * @param string $tag
  80. * @return array
  81. */
  82. public static function getByTag(string $tag): array
  83. {
  84. return self::where('tag', $tag)->select()->toArray();
  85. }
  86. /**
  87. * 根据科室代码获取记录
  88. * @param string $ksdm
  89. * @return array
  90. */
  91. public static function getByKsdm(string $ksdm): array
  92. {
  93. return self::where('ksdm', $ksdm)->select()->toArray();
  94. }
  95. /**
  96. * 根据员工代码获取记录
  97. * @param string $ygdm
  98. * @return array
  99. */
  100. public static function getByYgdm(string $ygdm): array
  101. {
  102. return self::where('ygdm', $ygdm)->select()->toArray();
  103. }
  104. /**
  105. * 添加记录
  106. * @param array $data
  107. * @return bool
  108. */
  109. public static function addRecord(array $data): bool
  110. {
  111. $model = new self();
  112. return $model->save($data);
  113. }
  114. /**
  115. * 更新记录
  116. * @param int $id
  117. * @param array $data
  118. * @return bool
  119. */
  120. public static function updateRecord(int $id, array $data): bool
  121. {
  122. return self::where('id', $id)->update($data);
  123. }
  124. /**
  125. * 删除记录
  126. * @param int $id
  127. * @return bool
  128. */
  129. public static function deleteRecord(int $id): bool
  130. {
  131. return self::where('id', $id)->delete();
  132. }
  133. /**
  134. * 根据住院号和类型更新或插入记录
  135. * @param string $zyh 住院号
  136. * @param string $tag 类型
  137. * @param array $data 更新或插入的数据
  138. * @return bool
  139. */
  140. public static function updateOrInsert(string $zyh, string $tag, array $data): bool
  141. {
  142. // 查找是否存在记录
  143. $record = self::where([
  144. 'zyh' => $zyh,
  145. 'tag' => $tag
  146. ])->find();
  147. if ($record) {
  148. // 存在则更新
  149. return $record->save(array_merge($data, [
  150. 'zyh' => $zyh,
  151. 'tag' => $tag
  152. ]));
  153. } else {
  154. // 不存在则插入
  155. $model = new self();
  156. return $model->save(array_merge($data, [
  157. 'zyh' => $zyh,
  158. 'tag' => $tag
  159. ]));
  160. }
  161. }
  162. }