Patient.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use Mpdf\Tag\P;
  5. use think\Exception;
  6. use think\facade\Db;
  7. use function GuzzleHttp\Psr7\str;
  8. /**
  9. * 患者信息管理
  10. */
  11. class Patient extends Backend
  12. {
  13. /**
  14. * Patient模型对象
  15. * @var object
  16. * @phpstan-var \app\admin\model\Patient
  17. */
  18. protected object $model;
  19. protected string|array $defaultSortField = 'ID,desc';
  20. protected string|array $quickSearchField = ['ID'];
  21. protected array $noNeedLogin = ['asyncAttachment'];
  22. protected array $noNeedPermission = ['asyncAttachment'];
  23. public function initialize(): void
  24. {
  25. parent::initialize();
  26. $this->model = new \app\admin\model\Patient();
  27. }
  28. /**
  29. * 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
  30. */
  31. /**
  32. * 查看
  33. * @throws Throwable
  34. */
  35. public function index(): void
  36. {
  37. if ($this->request->param('select')) {
  38. $this->select();
  39. }
  40. list($where, $alias, $limit, $order) = $this->queryBuilder();
  41. $res = $this->model
  42. ->field($this->indexField)
  43. ->withJoin($this->withJoinTable, $this->withJoinType)
  44. ->alias($alias)
  45. ->where($where)
  46. ->order($order)
  47. ->paginate($limit);
  48. foreach ($res->items() as $k=>&$v)
  49. {
  50. $v->ID_CARDNUM = empty($v->ID_CARDNUM) ? '' : substr($v->ID_CARDNUM,0, 10) . '****' . substr($v->ID_CARDNUM,14);
  51. $v->NAME = mb_substr( $v->NAME, 0, 1) . str_repeat('*', ceil((strlen($v->NAME) - 1)/4));
  52. $len = strlen($v->INSUR_CARD_NO);
  53. $v->INSUR_CARD_NO = mb_substr( $v->INSUR_CARD_NO, 0, ceil($len/2)).str_repeat('*', ceil($len/2));
  54. }
  55. $this->success('', [
  56. 'list' => $res->items(),
  57. 'total' => $res->total(),
  58. 'remark' => get_route_remark(),
  59. ]);
  60. }
  61. public function asyncAttachment():void
  62. {
  63. try {
  64. $params = $this->request->post();
  65. $type = $params['file']; //文件流类型 文件后缀
  66. $url = '/attachment/'.time().'.'.$type;
  67. $filePath = $_SERVER['DOCUMENT_ROOT'].$url;
  68. // 确保目录存在
  69. $dirPath = dirname($filePath);
  70. if (!is_dir($dirPath)) {
  71. mkdir($dirPath, 0755, true); // 第三个参数 true 表示可以创建多级目录
  72. }
  73. // 写入文件
  74. $data = $params['data'];
  75. file_put_contents($filePath, $data);
  76. $arr = [
  77. 'report_code'=>$params['report_code'],
  78. 'type'=>$params['type'],
  79. 'url'=>$url
  80. ];
  81. Db::name('report_attachment')->insert($arr);
  82. $this->success('success');
  83. }catch (\Exception $e)
  84. {
  85. $this->error($e->getMessage());
  86. }
  87. }
  88. public function getAttachment(): void
  89. {
  90. $params = $this->request->post();
  91. $code = $params['report_code'];
  92. $url = Db::name('report_attachment')->where('report_code',$code)->value('url');
  93. if(!empty($url))
  94. {
  95. $this->success($url);
  96. }else{
  97. $this->error('无可用的附件');
  98. }
  99. }
  100. }