PatientDao.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. package thyyxxk.webserver.dao.his.inpatient;
  2. import org.apache.ibatis.annotations.*;
  3. import thyyxxk.webserver.entity.dictionary.CodeName;
  4. import thyyxxk.webserver.entity.inpatient.dismiss.ZyDisYbDiag;
  5. import thyyxxk.webserver.entity.inpatient.patient.*;
  6. import java.util.Date;
  7. import java.util.List;
  8. @Mapper
  9. public interface PatientDao {
  10. @Select("select " +
  11. "RTRIM(a.bed_no) bedNo, " +
  12. "RTRIM(a.inpatient_no) inpatientNo, " +
  13. "a.admiss_times, " +
  14. "RTRIM(a.name) as name, " +
  15. "sex=isnull(a.sex, 9), " +
  16. "mdtrtId=(select b.mdtrt_id from t_si_pat_info b where b.pat_no=a.inpatient_no " +
  17. "and b.times=a.admiss_times and b.ledger_sn=a.times_billed), " +
  18. "injurySerialNo=(select serial_no from t_injury_si_pat_info where pat_no=a.inpatient_no " +
  19. "and times=a.admiss_times and ledger_sn=a.times_billed), " +
  20. "medType=a.med_type, " +
  21. "dismissOrder=(select count(1) from yz_act_order b where b.inpatient_no=a.inpatient_no " +
  22. "and b.admiss_times=a.admiss_times and status_flag > '1' and isnull(group_no,'00')='00' " +
  23. "and order_code in ('06026','06053','05973'))," +
  24. "orderNoCount = (select count(1) " +
  25. " from yz_act_order c " +
  26. " where a.inpatient_no = c.inpatient_no " +
  27. " and c.admiss_times = a.admiss_times " +
  28. " and c.status_flag = '1' " +
  29. " and c.enter_oper = #{userCode}), " +
  30. " rtrim(refer_physician) refer_physician, " +
  31. " (select rtrim(name) from a_employee_mi where code = refer_physician) as refer_physician_name, " +
  32. " rtrim(consult_physician) consult_physician, " +
  33. " (select rtrim(name) from a_employee_mi where code = consult_physician) as consult_physician_name, " +
  34. " rtrim(dept_director) dept_director, " +
  35. " (select rtrim(name) from a_employee_mi where code = dept_director) as dept_director_name, " +
  36. " total_charge, " +
  37. " balance, " +
  38. " rtrim(admiss_diag_str) as admiss_diag_str, " +
  39. " rtrim(clinic_diag_str) as clinic_diag_str, " +
  40. " responce_type_name = (select rtrim(name) from zy_zd_responce_type where code = responce_type)," +
  41. " admiss_date,zkys," +
  42. " zkys_name =(select rtrim(name) from a_employee_mi where code = zkys) " +
  43. "from zy_actpatient a left join batj_ba2 ba on (a.inpatient_no = ba.zyh and a.admiss_times = ba.zycs) " +
  44. "where a.ward like #{ward} ${sql} " +
  45. "ORDER BY cast(a.bed_no AS int)")
  46. List<Overview> getOverView(@Param("ward") String ward,
  47. @Param("userCode") String userCode,
  48. @Param("sql") String sql);
  49. @Select("<script>" +
  50. "select inpatientNo=rtrim(a.inpatient_no),a.admiss_times,a.med_type,b.social_no,dis_date," +
  51. "zkys= (select zkys from batj_ba2 ba where ba.zyh = a.inpatient_no and ba.zycs = a.admiss_times)," +
  52. "mz_no = (select rtrim(mz_no) from a_patient_mi where a_patient_mi.inpatient_no = a.inpatient_no)," +
  53. "zk_ward,zk_ward_name = (select rtrim(name) from zd_unit_code where code=zk_ward), " +
  54. "name=rtrim(a.name),sex=isnull(a.sex, b.sex),act_ipt_days=(datediff(day, admiss_date, isnull(dis_date,getdate()))), " +
  55. "birthDate=(convert(varchar(10), birth_date, 21)),home_tel=rtrim(b.home_tel), " +
  56. "admissPhysician=rtrim(a.admiss_physician),b.psn_cert_type, " +
  57. "insutype=(select top 1 insutype from t_si_pat_info with(nolock) where pat_no=#{inpatientNo} and " +
  58. "times=a.admiss_times order by ledger_sn desc), " +
  59. "admissPhysicianName=rtrim((select name FROM a_employee_mi WHERE code = a.admiss_physician)), " +
  60. "referPhysician=rtrim(a.refer_physician), " +
  61. "referPhysicianName=rtrim((select name FROM a_employee_mi WHERE code = a.refer_physician)), " +
  62. "admissDiagStr=rtrim(isnull(a.admiss_diag_str,'')), " +
  63. "clinicDiagStr=rtrim(isnull(a.clinic_diag_str,'')), " +
  64. "admissWard=rtrim(isnull(a.ward,a.admiss_ward)), " +
  65. "admissWardName=(select rtrim(name) from zd_unit_code where code=a.ward), " +
  66. "admissDept=rtrim(a.admiss_dept), a.matn_type,smallDept=rtrim(a.small_dept), " +
  67. "smallDeptName=rtrim((select name from zd_unit_code where code=small_dept)), " +
  68. "admiss_date,ybRegisterDate=isnull(yb_register_date, admiss_date), " +
  69. "responceType=a.med_type,a.dise_code,a.dise_name, " +
  70. "zkWard=rtrim(a.zk_ward),ward=(a.ward),a.latechb_flag,a.pret_flag,ledgerSn=a.times_billed, " +
  71. "admissStatus=rtrim(a.admiss_status), " +
  72. "dismissOrder=(select count(1) from yz_act_order y where y.inpatient_no=b.inpatient_no " +
  73. "and y.admiss_times=a.admiss_times and status_flag>'1' and isnull(group_no,'00')='00' " +
  74. "and order_code in ('06026','06053','05973')), " +
  75. "disDiagStatus=(select RTRIM(dis_diag_status) from zy_dis_diag_yb where inpatient_no=a.inpatient_no " +
  76. "and admiss_times=a.admiss_times and dis_diag_no=1), " +
  77. "operation=rtrim(a.operation),a.zy_serial_no, " +
  78. "bedNo=rtrim(a.bed_no),a.admdvs,a.exp_content, " +
  79. "dutyNurse=(select rtrim(job_nurse) from batj_ba2 t where t.zyh=a.inpatient_no and t.zycs=a.admiss_times), " +
  80. "rtrim(b.country) as country, rtrim(b.nation_code) as nation," +
  81. "rtrim(b.relation_name) as contactName, rtrim(relation_code) as contactRelation, " +
  82. "rtrim(b.relation_street) as contactAddrName, rtrim(relation_tel) as contactPhone, " +
  83. "mdtrtId=(select mdtrt_id from t_si_pat_info where pat_no=a.inpatient_no and times=a.admiss_times and ledger_sn=a.times_billed), " +
  84. "injurySerialNo=(select serial_no from t_injury_si_pat_info where pat_no=a.inpatient_no " +
  85. "and times=a.admiss_times and ledger_sn=a.times_billed), " +
  86. "chargeYb=(select isnull(charge_yb, '0.00') from zy_ledger_file where inpatient_no=a.inpatient_no " +
  87. "and admiss_times=a.admiss_times and ledger_sn=a.times_billed), " +
  88. "totalCharge=(select rtrim(isnull(total_charge, '0.00')) from zy_ledger_file where inpatient_no=a.inpatient_no " +
  89. "and admiss_times=a.admiss_times and ledger_sn=a.times_billed), " +
  90. "injuryArea=(select injury_area from t_injury_si_pat_info where pat_no=a.inpatient_no " +
  91. "and times=a.admiss_times and ledger_sn=a.times_billed) FROM ${table} a with(nolock), " +
  92. "a_patient_mi b with(nolock) WHERE a.inpatient_no=#{inpatientNo} " +
  93. "<if test=\"times != null and times != 0 \">" +
  94. "and a.admiss_times =#{times} " +
  95. "</if>" +
  96. " AND b.inpatient_no=a.inpatient_no" +
  97. "</script>")
  98. Patient getPatientInfo(@Param("inpatientNo") String inpatientNo, @Param("table") String table, @Param("times") Integer times);
  99. @Select("select parent_code from t_region where code=#{code}")
  100. Integer selectParentRegion(Integer code);
  101. @Select("select dis_diag_no, " +
  102. "rtrim(dis_diag) disDiag, " +
  103. "rtrim(dis_diag_comment) disDiagComment, " +
  104. "dis_diag_status, " +
  105. "opName=(select rtrim(name) from a_employee_mi where code=op_id_code) " +
  106. "from zy_dis_diag_yb where inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes}")
  107. List<ZyDisYbDiag> getYibaoDisDiags(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);
  108. @Select("select * from zy_dis_diag_yb where inpatient_no=#{patNo} and admiss_times=#{times}")
  109. List<ZyDisYbDiag> getZyDisYbDiags(@Param("patNo") String patNo, @Param("times") Integer times);
  110. @Select("SELECT dis_diag_no, " +
  111. "rtrim(dis_diag) disDiag, " +
  112. "rtrim(dis_diag_comment) disDiagComment, " +
  113. "disDiagStatusName=(select rtrim(name) from zd_dis_diag_status WHERE code=dis_diag_status), " +
  114. "opName=(select rtrim(name) from a_employee_mi where code=op_id_code) " +
  115. "from ba_first_page1 where inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes}")
  116. List<ZyDisYbDiag> getBingliDisDiags(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);
  117. @Select("select rtrim(inpatient_no) from a_patient_mi where social_no=#{idCard}")
  118. List<String> getInpatientNo(@Param("idCard") String idCard);
  119. @Select("SELECT item_no, inpatient_no, admiss_times, agency, expirestart, file_sfz " +
  120. "FROM zy_xnh_record_sfz WHERE inpatient_no=#{inpatientNo} AND admiss_times=#{admissTimes}")
  121. List<IdCard> getIdCard(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);
  122. @Select("SELECT item_no,inpatient_no,admiss_times,file_xnh AS file_sfz FROM zy_xnh_record " +
  123. "WHERE inpatient_no=#{inpatientNo} AND admiss_times=#{admissTimes}")
  124. List<IdCard> getScanFile(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);
  125. @Select("select settle_type from zy_ledger_file where inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes} " +
  126. "and ledger_sn=(select isnull(max ( ledger_sn ), min ( ledger_sn )) from zy_ledger_file where " +
  127. "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes})")
  128. Integer getSettleType(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);
  129. @Select("select count(id) from zy_retract_yb where inpatientNo=#{inpatientNo} " +
  130. "and admissTimes=#{admissTimes} and requestType=#{requestType}")
  131. Integer getRequestCount(@Param("inpatientNo") String inpatientNo,
  132. @Param("admissTimes") Integer admissTimes,
  133. @Param("requestType") Integer requestType);
  134. @Select("select * from zy_retract_yb where inpatientNo=#{inpatientNo} and " +
  135. "admissTimes=#{admissTimes} and requestType=#{requestType}")
  136. List<ToYbkRequest> getRetractRequests(@Param("inpatientNo") String inpatientNo,
  137. @Param("admissTimes") Integer admissTimes,
  138. @Param("requestType") Integer requestType);
  139. @Insert("insert into zy_retract_yb (inpatientNo, admissTimes, name, sex, responceType, ybType, treatType, " +
  140. "remark, inputId, inputName, inputTimes, statusFlag, requestType) values (#{inpatientNo}, #{admissTimes}, " +
  141. "#{name}, #{sex}, #{responceType}, #{ybType}, #{treatType}, #{remark}, #{inputId}, #{inputName}," +
  142. "#{inputTimes}, 1, #{requestType})")
  143. void submitNewRequest(ToYbkRequest indata);
  144. @Select("select isnull(max ( ledger_sn ), isnull(min ( ledger_sn ), 1)) from zy_ledger_file where " +
  145. "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes}")
  146. Integer getLedgerSn(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);
  147. @Update("update zy_actpatient set yb_register_date=#{ybRegisterDate},med_type=#{medType},responce_type=#{responceType}, " +
  148. "admdvs=#{admdvs},refer_physician=#{referPhysician},matn_type=#{matnType},latechb_flag=#{latechbFlag}," +
  149. "pret_flag=#{pretFlag},dise_code=#{diseCode},dise_name=#{diseName},exp_content=#{expContent},name=#{name} " +
  150. "where inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes}")
  151. void updateZyActpatient(Patient param);
  152. @Select("select count(1) from batj_ba2 with(nolock) where bah=#{bah} and zycs=#{times}")
  153. int isBatjBa2Exist(@Param("bah") String bah, @Param("times") int times);
  154. @Insert("insert into batj_ba2 (bah, zyh, zycs, job_nurse) values (#{bah}, #{bah}, #{times}, #{dutyNurse})")
  155. void createBatjBa2(@Param("bah") String bah, @Param("times") int times, @Param("dutyNurse") String dutyNurse);
  156. @Update("update batj_ba2 set job_nurse=#{dutyNurse} where zyh=#{bah} and zycs=#{times}")
  157. void updateBatjBa2(@Param("bah") String bah, @Param("times") int times, @Param("dutyNurse") String dutyNurse);
  158. @Update("update a_patient_mi set psn_cert_type=#{certType},social_no=#{sfz},country=#{country},nation_code=#{nation}, " +
  159. "relation_name=#{contactName},relation_code=#{contactRelation},relation_street=#{contactAddrName}, " +
  160. "relation_tel=#{contactPhone} where inpatient_no=#{zyh}")
  161. void updateAPatientMi(@Param("certType") String certType, @Param("sfz") String sfz, @Param("zyh") String zyh,
  162. @Param("country") String country, @Param("nation") String nation,
  163. @Param("contactName") String contactName, @Param("contactRelation") String contactRelation,
  164. @Param("contactAddrName") String contactAddrName, @Param("contactPhone") String contactPhone);
  165. @Select("select * from zy_in_diag_yb where inpatient_no=#{inpatientNo} and admiss_times=#{times} order by diag_no")
  166. List<ZyInYbDiag> getZyInYbDiag(@Param("inpatientNo") String inpatientNo, @Param("times") Integer times);
  167. @Delete("delete from zy_in_diag_yb where inpatient_no=#{inpatientNo} and admiss_times=#{times}")
  168. void deleteOldZyInYbDiag(@Param("inpatientNo") String inpatientNo, @Param("times") Integer times);
  169. @Insert("<script>" +
  170. "insert into zy_in_diag_yb (inpatient_no, admiss_times, diag_no, " +
  171. "icd_code, icd_text, oper_id, op_date, diag_type) values " +
  172. "<foreach collection='list' item='diag' separator=','>" +
  173. "(#{diag.inpatientNo},#{diag.admissTimes},#{diag.diagNo}," +
  174. "#{diag.icdCode},#{diag.icdText},#{operId},getdate(),#{diag.diagType})" +
  175. "</foreach>" +
  176. "</script>")
  177. void insertNewZyInYbDiag(@Param("operId") String operId, @Param("list") List<ZyInYbDiag> list);
  178. @Insert("<script>" +
  179. "insert into zy_in_diag_yb (inpatient_no, admiss_times, diag_no, " +
  180. "icd_code, icd_text, oper_id, op_date, diag_type) values " +
  181. "<foreach collection='diags' item='diag' separator=','>" +
  182. "(#{inpatientNo},#{admissTimes},#{diag.diagNo},#{diag.icdCode}," +
  183. "#{diag.icdText},#{staffId},getdate(),#{diag.diagType})" +
  184. "</foreach>" +
  185. "</script>")
  186. void insertSiZyInYbDiag(SaveSiZyDiags param);
  187. @Select("select convert (varchar(12),dateadd (day,0,start_time),111) from yz_act_order where " +
  188. "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes} and status_flag > '1' " +
  189. "and isnull(group_no,'00')='00' and order_code in ('06026','06053','05973') ")
  190. String getActOrderDisDate(@Param("inpatientNo") String inpatientNo,
  191. @Param("admissTimes") Integer admissTimes);
  192. @Select("select act_order_no from yz_sequence")
  193. float getActOrderNo();
  194. @Update("update yz_sequence set act_order_no=#{no}")
  195. void updateActorOrderNo(float no);
  196. @Insert("insert into yz_act_order " +
  197. "(act_order_no, inpatient_no, admiss_times, order_code, order_time, frequ_code, enter_time, " +
  198. "enter_oper, start_time, end_time, infant_flag, drug_flag, performance_time, " +
  199. "physician, confirm_time, signer, status_flag, status_time,drug_specification,order_name,discription, " +
  200. "ward_code,dept_code,exec_unit) " +
  201. "values (#{actOrderNo}, #{inpatientNo}, #{admissTimes}, '06026', #{dismissOrderDate}, 'ONCE', #{dismissOrderDate}, " +
  202. "#{staffId}, #{dismissOrderDate}, #{dismissOrderDate}, 0, 0, #{dismissOrderDate}, #{staffId}, " +
  203. "#{dismissOrderDate}, #{staffId}, 5, #{dismissOrderDate},'诊疗项目','今日结账出院','0.00 本项目不包含费用'," +
  204. "#{admissWard},#{admissWard},#{admissWard})")
  205. void insertNewDismissActOrder(@Param("actOrderNo") float actOrderNo,
  206. @Param("inpatientNo") String inpatientNo,
  207. @Param("admissTimes") Integer admissTimes,
  208. @Param("dismissOrderDate") Date dismissOrderDate,
  209. @Param("staffId") String staffId,
  210. @Param("admissWard") String admissWard);
  211. @Select("select * from zy_dis_diag_yb where inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes}")
  212. List<ZyDisYbDiag> getDisDiags(@Param("inpatientNo") String inpatientNo,
  213. @Param("admissTimes") Integer admissTimes);
  214. @Select("select rtrim(admiss_diag) code,rtrim(admiss_diag_str) name from zy_actpatient where " +
  215. "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes}")
  216. CodeName getAdmissDiag(@Param("inpatientNo") String inpatientNo,
  217. @Param("admissTimes") Integer admissTimes);
  218. @Insert("insert into zy_dis_diag_yb (inpatient_no, admiss_times, dis_diag_no, dis_diag_type, dis_diag, " +
  219. "dis_diag_comment, op_id_code, op_diag_date, dis_diag_bzfx, dis_diag_status, si_diag_type) " +
  220. "values (#{inpatientNo}, #{admissTimes}, 1, 13, #{code}, #{name}, #{staffId}, getDate(), '普通', 0, 1)")
  221. void insertDisDiag(@Param("inpatientNo") String inpatientNo,
  222. @Param("admissTimes") Integer admissTimes,
  223. @Param("code") String code,
  224. @Param("name") String name,
  225. @Param("staffId") String staffId);
  226. @Insert("<script>" +
  227. "insert into zy_dis_diag_yb (inpatient_no, admiss_times, dis_diag_no, dis_diag_type, dis_diag, " +
  228. "dis_diag_comment, op_id_code, op_diag_date, dis_diag_bzfx, dis_diag_status, si_diag_type) values " +
  229. "<foreach collection='list' item='diag' separator=','>" +
  230. "(#{diag.inpatientNo},#{diag.admissTimes},#{diag.diagNo}, 13, " +
  231. "#{diag.icdCode},#{diag.icdText},#{staffId},getdate(), '普通', 0, 1)" +
  232. "</foreach>" +
  233. "</script>")
  234. void insertDisDiags(@Param("staffId") String staffId, @Param("list") List<ZyInYbDiag> list);
  235. @Update("update zy_detail_charge set charge_date=#{newDate} where inpatient_no=#{zyh} " +
  236. "and admiss_times=#{times} and CONVERT(varchar(20), charge_date, 20) <= #{admdate}")
  237. void correctFeeChargeTimeBeforeAdmiss(@Param("zyh") String zyh,
  238. @Param("times") int times,
  239. @Param("admdate") Date admdate,
  240. @Param("newDate") Date newDate);
  241. @Select("select start_time from yz_act_order where inpatient_no=#{patNo} and admiss_times=#{times} " +
  242. "and status_flag > '1' and isnull(group_no, '00')='00' and order_code in ('06026','06053','05973')")
  243. Date selectActOrderDisDate(@Param("patNo") String patNo, @Param("times") Integer times);
  244. @Update("update zy_detail_charge set charge_date=#{disdate} where inpatient_no=#{zyh} " +
  245. "and admiss_times=#{times} and charge_date>#{disdate}")
  246. void correctFeeChargeTimeAfterDismiss(@Param("zyh") String zyh,
  247. @Param("times") int times,
  248. @Param("disdate") Date disdate);
  249. @Update("update zy_ledger_file set deposit=(select isnull(sum(depo_amount),0) from zy_deposit_file f with(nolock) " +
  250. "where f.inpatient_no=#{zyh} and f.admiss_times=#{times} and f.ledger_sn=#{ledger} and f.status in ('1','2') ) " +
  251. "where inpatient_no=#{zyh} and admiss_times=#{times} and ledger_sn=#{ledger}")
  252. void recountDeposit(@Param("zyh") String zyh,
  253. @Param("times") int times,
  254. @Param("ledger") int ledger);
  255. @Update("execute zy_receive_drug #{zyh},#{times},#{zyh},#{infant} ")
  256. void zyReceiveDrug(@Param("zyh") String zyh,
  257. @Param("times") int times,
  258. @Param("infant") int infant);
  259. @Update("execute zy_receive_one #{zyh},#{times},#{zyh},#{infant} ")
  260. void zyReceiveOne(@Param("zyh") String zyh,
  261. @Param("times") int times,
  262. @Param("infant") int infant);
  263. @Update("execute dbo.zy_cngl_fyjs_list_yz #{zyh},#{times} ")
  264. void zyCnglFyjsListYz(@Param("zyh") String zyh,
  265. @Param("times") int times);
  266. @Update("update zy_detail_charge set charge_status='2' where " +
  267. "inpatient_no=#{zyh} and admiss_times=#{times} and ledger_sn=#{ledger} ")
  268. void updateZyDetailCharge(@Param("zyh") String zyh,
  269. @Param("times") int times,
  270. @Param("ledger") int ledger);
  271. @Update("execute zy_calc_detail_again_new #{zyh},#{times},#{ledger},1,1")
  272. void zyCalcDetailAgainNew(@Param("zyh") String zyh,
  273. @Param("times") int times,
  274. @Param("ledger") int ledger);
  275. @Update("update zy_ledger_file set balance=(deposit+isnull(charge_yb,0)-total_charge) where " +
  276. "inpatient_no=#{zyh} and admiss_times=#{times} and ledger_sn=#{ledger}")
  277. void updateBalance(@Param("zyh") String zyh,
  278. @Param("times") int times,
  279. @Param("ledger") int ledger);
  280. }