MzChargeDetailMapper.java 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. package cn.hnthyy.thmz.mapper.his;
  2. import cn.hnthyy.thmz.entity.his.MzChargeDetail;
  3. import cn.hnthyy.thmz.pageDto.MzChargeDetailPageDto;
  4. import cn.hnthyy.thmz.vo.ThmzmxsrParamsVo;
  5. import org.apache.ibatis.annotations.Insert;
  6. import org.apache.ibatis.annotations.Param;
  7. import org.apache.ibatis.annotations.Select;
  8. import org.apache.ibatis.annotations.Update;
  9. import java.util.Date;
  10. import java.util.List;
  11. import java.util.Map;
  12. /**
  13. * 门诊收费记录表的数据层
  14. */
  15. public interface MzChargeDetailMapper {
  16. /**
  17. * 统计符合条件的费用信息
  18. *
  19. * @param mzChargeDetailPageDto
  20. * @return
  21. */
  22. @Select({"<script>",
  23. "select count(*) from (",
  24. "select patient_id from mz_charge_detail where bill_item_code <![CDATA[<>]]> 'TC' ",
  25. "<when test='mzChargeDetail.payMark!=null'>",
  26. " and pay_mark =#{mzChargeDetail.payMark,jdbcType=CHAR}",
  27. "</when>",
  28. "<when test='mzChargeDetail.payMark!=null and mzChargeDetail.payMark eq 0'>",
  29. " and confirm_flag <![CDATA[<>]]> 4 ",
  30. "</when>",
  31. "<when test='mzChargeDetail.patientId!=null'>",
  32. " and patient_id =#{mzChargeDetail.patientId,jdbcType=CHAR}",
  33. "</when>",
  34. "<when test='mzChargeDetail.times!=null'>",
  35. " and times =#{mzChargeDetail.times,jdbcType=INTEGER}",
  36. "</when>",
  37. "<when test='mzChargeDetail.name!=null'>",
  38. " and name like #{mzChargeDetail.name,jdbcType=CHAR}",
  39. "</when>",
  40. "<when test='mzChargeDetail.warnDept!=null'>",
  41. " and warn_dept = #{mzChargeDetail.warnDept,jdbcType=CHAR}",
  42. "</when>",
  43. "<when test='mzChargeDetail.doctorCode!=null'>",
  44. " and doctor_code =#{mzChargeDetail.doctorCode,jdbcType=CHAR}",
  45. "</when>",
  46. "<when test='opId!=null and mzChargeDetail.payMark eq 0 '>",
  47. " and cash_id =#{opId,jdbcType=CHAR}",
  48. "</when>",
  49. "<when test='opId!=null and mzChargeDetail.payMark eq 1 '>",
  50. " and input_id =#{opId,jdbcType=CHAR}",
  51. "</when>",
  52. "<when test='beginTime!=null and mzChargeDetail.payMark eq 5'>",
  53. " and price_time &gt;=#{beginTime,jdbcType=TIMESTAMP}",
  54. "</when>",
  55. "<when test='endTime!=null and mzChargeDetail.payMark eq 5'>",
  56. " and price_time &lt;=#{endTime,jdbcType=TIMESTAMP}",
  57. "</when>",
  58. "<when test='beginTime!=null and mzChargeDetail.payMark eq 0'>",
  59. " and charge_date &gt;=#{beginTime,jdbcType=TIMESTAMP}",
  60. "</when>",
  61. "<when test='endTime!=null and mzChargeDetail.payMark eq 0'>",
  62. " and charge_date &lt;=#{endTime,jdbcType=TIMESTAMP}",
  63. "</when>",
  64. "<when test='beginTime!=null and mzChargeDetail.payMark eq 1'>",
  65. " and input_date &gt;=#{beginTime,jdbcType=TIMESTAMP}",
  66. "</when>",
  67. "<when test='endTime!=null and mzChargeDetail.payMark eq 1'>",
  68. " and input_date &lt;=#{endTime,jdbcType=TIMESTAMP}",
  69. "</when>",
  70. " group by patient_id,times,receipt_no,name,",
  71. "<when test='mzChargeDetail.payMark eq 0'>",
  72. " charge_date,",
  73. "</when>",
  74. "<when test='mzChargeDetail.payMark eq 1'>",
  75. " input_date,",
  76. "</when>",
  77. "<when test='mzChargeDetail.payMark eq 5'>",
  78. " price_time,",
  79. "</when>",
  80. "real_no)As mz_charge_detail_page",
  81. "</script>"})
  82. int countMzChargeDetail(MzChargeDetailPageDto mzChargeDetailPageDto);
  83. /**
  84. * 按照费用类型查询费用明细
  85. *
  86. * @param patientId
  87. * @param times
  88. * @param payMark
  89. * @param billItemCode 0 ,1 都是in 2 not in
  90. * @param billItemTypes
  91. * @return
  92. */
  93. @Select({"<script>",
  94. "select rtrim(patient_id) patient_id,times,receipt_no,order_no,item_no,rtrim(charge_item_code) charge_item_code,rtrim(bill_item_code) bill_item_code,",
  95. "quantity,unit_price,rtrim(pay_mark) pay_mark,rtrim(serial) serial,rtrim(charge_item_type) charge_item_type,rtrim(country_flag) country_flag,rtrim(drug_flag) drug_flag,",
  96. "serial_no,rtrim(name) name,charge_date,confirm_time,rtrim(group_no) group_no,rtrim(confirm_id) confirm_id,drug_win,rtrim(input_id) input_id,input_date,",
  97. "rtrim(cashier_id) cashier_id,rtrim(windows_no) windows_no,rtrim(price_id) price_id,price_time,rtrim(exec_dept) exec_dept,rtrim(audit_code) audit_code,",
  98. "rtrim(gongnks_flag) gongnks_flag,rtrim(print_flag) print_flag,confirm_flag,rtrim(warn_dept) warn_dept,rtrim(jz_flag) jz_flag,group_order,rtrim(cash_id) cash_id,",
  99. "rtrim(doctor_code) doctor_code,rtrim(supply_code) supply_code,rtrim(frequency) frequency,drug_quan,rtrim(drug_unit) drug_unit,rtrim(doctor_flag) doctor_flag,inject_res,inject_times,",
  100. "rtrim(confirm_zs) confirm_zs,real_no,windows_no_yf,ybbx_flag,tc_no,tc_name,rtrim(detail_flag) detail_flag,gl_percent,rtrim(order_type) order_type,supply_no,instruction_code,",
  101. "instruction_text,order_days,rtrim(pay_self) pay_self,rtrim(try_flag) try_flag,rtrim(req_yj) req_yj,req_no,rtrim(group_type) group_type,order_bill,charge_bill_code,",
  102. "rtrim(self_flag) self_flag,rtrim(responce_type) responce_type,dec_amount,back_serial,input_time,cy_mtjs,cy_jsl,cy_zql,cy_fj,cy_ffcs,cy_fysm,supply_amount,rtrim(cy_jssm) cy_jssm,",
  103. "dept_no,gl_percent_ft,rtrim(yb_zf_flag) yb_zf_flag,orig_price,rtrim(try_result) try_result,rtrim(supply_exec) supply_exec,rtrim(cy_dj) cy_dj,rtrim(receive_flag) receive_flag,",
  104. "rtrim(chequ_type) chequ_type,rtrim(print_flag_yj) print_flag_yj,rtrim(confirm_flag_qx) confirm_flag_qx ",
  105. "from dbo.mz_charge_detail where pay_mark=#{payMark,jdbcType=CHAR} and patient_id =#{patientId,jdbcType=CHAR} and times = #{times,jdbcType=INTEGER} ",
  106. "<choose>",
  107. "<when test='billItemCode==2'>",
  108. " and bill_item_code not in",
  109. "</when>",
  110. "<otherwise>",
  111. " and bill_item_code in",
  112. "</otherwise>",
  113. " </choose>",
  114. "<foreach item='item' index='index' collection='billItemTypes' open='(' separator=',' close=')'>",
  115. "#{item}",
  116. "</foreach>",
  117. "</script>"})
  118. List<MzChargeDetail> selectMzChargeDetailByBillItemCode(@Param("patientId") String patientId, @Param("times") Integer times, @Param("payMark") String payMark, @Param("billItemCode") String billItemCode, @Param("billItemTypes") List<String> billItemTypes);
  119. /**
  120. * 分页查询收费合计信息
  121. *
  122. * @param mzChargeDetailPageDto
  123. * @return
  124. */
  125. @Select({"<script>",
  126. "select top ${pageSize} * FROM (SELECT ROW_NUMBER() OVER (ORDER BY mz_charge_detail_page.",
  127. "<when test='mzChargeDetail.payMark eq 5'>",
  128. "price_time",
  129. "</when>",
  130. "<when test='mzChargeDetail.payMark eq 0'>",
  131. "charge_date",
  132. "</when>",
  133. "<when test='mzChargeDetail.payMark eq 1'>",
  134. "input_date",
  135. "</when>",
  136. " desc) AS RowNumber,* from (" +
  137. "select rtrim(patient_id) patient_id,times,receipt_no,rtrim(name) name,",
  138. "<when test='mzChargeDetail.payMark eq 0'>",
  139. " charge_date,",
  140. "</when>",
  141. "<when test='mzChargeDetail.payMark eq 1'>",
  142. " input_date,",
  143. "</when>",
  144. "<when test='mzChargeDetail.payMark eq 5'>",
  145. " price_time,",
  146. "</when>",
  147. "real_no,sum(unit_price*quantity*drug_win) amount from mz_charge_detail where bill_item_code <![CDATA[<>]]> 'TC' ",
  148. "<when test='mzChargeDetail.payMark!=null'>",
  149. " and pay_mark =#{mzChargeDetail.payMark,jdbcType=CHAR}",
  150. "</when>",
  151. "<when test='mzChargeDetail.payMark!=null and mzChargeDetail.payMark eq 0'>",
  152. " and confirm_flag <![CDATA[<>]]> 4 ",
  153. "</when>",
  154. "<when test='mzChargeDetail.patientId!=null'>",
  155. " and patient_id =#{mzChargeDetail.patientId,jdbcType=CHAR}",
  156. "</when>",
  157. "<when test='mzChargeDetail.times!=null'>",
  158. " and times =#{mzChargeDetail.times,jdbcType=INTEGER}",
  159. "</when>",
  160. "<when test='mzChargeDetail.name!=null'>",
  161. " and name like #{mzChargeDetail.name,jdbcType=CHAR}",
  162. "</when>",
  163. "<when test='mzChargeDetail.warnDept!=null'>",
  164. " and warn_dept = #{mzChargeDetail.warnDept,jdbcType=CHAR}",
  165. "</when>",
  166. "<when test='mzChargeDetail.doctorCode!=null'>",
  167. " and doctor_code =#{mzChargeDetail.doctorCode,jdbcType=CHAR}",
  168. "</when>",
  169. "<when test='opId!=null and mzChargeDetail.payMark eq 0 '>",
  170. " and cash_id =#{opId,jdbcType=CHAR}",
  171. "</when>",
  172. "<when test='opId!=null and mzChargeDetail.payMark eq 1 '>",
  173. " and input_id =#{opId,jdbcType=CHAR}",
  174. "</when>",
  175. "<when test='beginTime!=null and mzChargeDetail.payMark eq 5'>",
  176. " and price_time &gt;=#{beginTime,jdbcType=TIMESTAMP}",
  177. "</when>",
  178. "<when test='endTime!=null and mzChargeDetail.payMark eq 5'>",
  179. " and price_time &lt;=#{endTime,jdbcType=TIMESTAMP}",
  180. "</when>",
  181. "<when test='beginTime!=null and mzChargeDetail.payMark eq 0'>",
  182. " and charge_date &gt;=#{beginTime,jdbcType=TIMESTAMP}",
  183. "</when>",
  184. "<when test='endTime!=null and mzChargeDetail.payMark eq 0'>",
  185. " and charge_date &lt;=#{endTime,jdbcType=TIMESTAMP}",
  186. "</when>",
  187. "<when test='beginTime!=null and mzChargeDetail.payMark eq 1'>",
  188. " and input_date &gt;=#{beginTime,jdbcType=TIMESTAMP}",
  189. "</when>",
  190. "<when test='endTime!=null and mzChargeDetail.payMark eq 1'>",
  191. " and input_date &lt;=#{endTime,jdbcType=TIMESTAMP}",
  192. "</when>",
  193. " group by patient_id,times,receipt_no,name,",
  194. "<when test='mzChargeDetail.payMark eq 0'>",
  195. " charge_date,",
  196. "</when>",
  197. "<when test='mzChargeDetail.payMark eq 1'>",
  198. " input_date,",
  199. "</when>",
  200. "<when test='mzChargeDetail.payMark eq 5'>",
  201. " price_time,",
  202. "</when>",
  203. "real_no) As mz_charge_detail_page",
  204. ") as A WHERE RowNumber >#{pageSize}*#{pageIndex} order by RowNumber asc",
  205. "</script>"})
  206. List<MzChargeDetail> selectMzChargeDetailWithPage(MzChargeDetailPageDto mzChargeDetailPageDto);
  207. /**
  208. * 查询收费合计信息
  209. *
  210. * @param mzChargeDetailPageDto
  211. * @return
  212. */
  213. @Select({"<script>",
  214. "select rtrim(patient_id) patient_id,times,receipt_no,rtrim(name) name,price_time," +
  215. "receipt_sn,sum(unit_price*quantity) amount from mz_charge_detail where 1=1 ",
  216. "<when test='mzChargeDetail.payMark!=null'>",
  217. " and pay_mark =#{mzChargeDetail.payMark,jdbcType=CHAR}",
  218. "</when>",
  219. "<when test='mzChargeDetail.patientId!=null'>",
  220. " and patient_id =#{mzChargeDetail.patientId,jdbcType=CHAR}",
  221. "</when>",
  222. "<when test='mzChargeDetail.name!=null'>",
  223. " and name like #{mzChargeDetail.name,jdbcType=CHAR}",
  224. "</when>",
  225. "<when test='mzChargeDetail.warnDept!=null'>",
  226. " and warn_dept = #{mzChargeDetail.warnDept,jdbcType=CHAR}",
  227. "</when>",
  228. "<when test='mzChargeDetail.doctorCode!=null'>",
  229. " and doctor_code =#{mzChargeDetail.doctorCode,jdbcType=CHAR}",
  230. "</when>",
  231. "<when test='beginTime!=null'>",
  232. " and price_time &gt;=#{beginTime,jdbcType=TIMESTAMP}",
  233. "</when>",
  234. "<when test='endTime!=null'>",
  235. " and price_time &lt;=#{endTime,jdbcType=TIMESTAMP}",
  236. "</when>",
  237. " group by patient_id,times,receipt_no,name,price_time,receipt_sn",
  238. "</script>"})
  239. List<MzChargeDetail> selectMzChargeDetail(MzChargeDetailPageDto mzChargeDetailPageDto);
  240. /**
  241. * 查询当前病人的就诊次数对应的最大的处方号
  242. *
  243. * @param patientId
  244. * @param times
  245. * @return
  246. */
  247. @Select("select max(order_no) from mz_charge_detail where patient_id =#{patientId,jdbcType=CHAR} and times =#{times,jdbcType=INTEGER}")
  248. Integer selectMaxOrderNo(@Param("patientId") String patientId, @Param("times") Integer times);
  249. /**
  250. * 查询当前病人的就诊次数对应的已经存在的收费记录(药品记录) 未缴费
  251. *
  252. * @param patientId
  253. * @param times
  254. * @return
  255. */
  256. @Select({"<script>",
  257. "select rtrim(patient_id) patient_id,times,receipt_no,order_no,item_no,rtrim(charge_item_code) charge_item_code,rtrim(bill_item_code) bill_item_code,",
  258. "quantity,unit_price,rtrim(pay_mark) pay_mark,rtrim(serial) serial,rtrim(charge_item_type) charge_item_type,rtrim(country_flag) country_flag,rtrim(drug_flag) drug_flag,",
  259. "serial_no,rtrim(name) name,charge_date,confirm_time,rtrim(group_no) group_no,rtrim(confirm_id) confirm_id,drug_win,rtrim(input_id) input_id,input_date,",
  260. "rtrim(cashier_id) cashier_id,rtrim(windows_no) windows_no,rtrim(price_id) price_id,price_time,rtrim(exec_dept) exec_dept,rtrim(audit_code) audit_code,",
  261. "rtrim(gongnks_flag) gongnks_flag,rtrim(print_flag) print_flag,confirm_flag,rtrim(warn_dept) warn_dept,rtrim(jz_flag) jz_flag,group_order,rtrim(cash_id) cash_id,",
  262. "rtrim(doctor_code) doctor_code,rtrim(supply_code) supply_code,rtrim(frequency) frequency,drug_quan,rtrim(drug_unit) drug_unit,rtrim(doctor_flag) doctor_flag,inject_res,inject_times,",
  263. "rtrim(confirm_zs) confirm_zs,real_no,windows_no_yf,ybbx_flag,tc_no,tc_name,rtrim(detail_flag) detail_flag,gl_percent,rtrim(order_type) order_type,supply_no,instruction_code,",
  264. "instruction_text,order_days,rtrim(pay_self) pay_self,rtrim(try_flag) try_flag,rtrim(req_yj) req_yj,req_no,rtrim(group_type) group_type,order_bill,charge_bill_code,",
  265. "rtrim(self_flag) self_flag,rtrim(responce_type) responce_type,dec_amount,back_serial,input_time,cy_mtjs,cy_jsl,cy_zql,cy_fj,cy_ffcs,cy_fysm,supply_amount,rtrim(cy_jssm) cy_jssm,",
  266. "dept_no,gl_percent_ft,rtrim(yb_zf_flag) yb_zf_flag,orig_price,rtrim(try_result) try_result,rtrim(supply_exec) supply_exec,rtrim(cy_dj) cy_dj,rtrim(receive_flag) receive_flag,",
  267. "rtrim(chequ_type) chequ_type,rtrim(print_flag_yj) print_flag_yj,rtrim(confirm_flag_qx) confirm_flag_qx ",
  268. "from dbo.mz_charge_detail where patient_id =#{patientId,jdbcType=CHAR} and times =#{times,jdbcType=INTEGER} and pay_mark=#{payMark,jdbcType=CHAR} order by order_no desc",
  269. "</script>"})
  270. List<MzChargeDetail> selectMzChargeDetailByPatientId(@Param("patientId") String patientId, @Param("times") Integer times, @Param("payMark") String payMark);
  271. /**
  272. * 根据当期那病人与就诊次数以及收费编码查询对应的药品数量与退药量
  273. *
  274. * @param patientId
  275. * @param times
  276. * @param chargeItemCode
  277. * @return
  278. */
  279. @Select("select * from mz_charge_detail where patient_id =#{patientId,jdbcType=CHAR} and times =#{times,jdbcType=INTEGER} and charge_item_code=#{chargeItemCode,jdbcType=CHAR} and order_no =#{orderNo} and quantity>0")
  280. List<MzChargeDetail> selectMzChargeDetailByChargeItemCode(@Param("patientId") String patientId, @Param("times") Integer times, @Param("chargeItemCode") String chargeItemCode, @Param("orderNo") Integer orderNo);
  281. /**
  282. * 新增收费明细记录
  283. *
  284. * @param mzChargeDetail
  285. * @return
  286. */
  287. @Insert("INSERT INTO mz_charge_detail(patient_id,times,receipt_no,order_no,item_no,charge_item_code,bill_item_code,quantity,unit_price,pay_mark,serial,charge_item_type," +
  288. "country_flag,drug_flag,serial_no,name,charge_date,confirm_time,group_no,confirm_id,drug_win,input_id,input_date,cashier_id,windows_no,price_id,price_time,exec_dept," +
  289. "audit_code,gongnks_flag,print_flag,confirm_flag,warn_dept,jz_flag,group_order,cash_id,doctor_code,supply_code,frequency,drug_quan,drug_unit,doctor_flag,inject_res,inject_times," +
  290. "confirm_zs,real_no,windows_no_yf,ybbx_flag,tc_no,tc_name,detail_flag,gl_percent,order_type,supply_no,instruction_code,instruction_text,order_days,pay_self,try_flag,req_yj," +
  291. "req_no,group_type,order_bill,charge_bill_code,self_flag,responce_type,dec_amount,back_serial,input_time,cy_mtjs,cy_jsl,cy_zql,cy_fj,cy_ffcs,cy_fysm,supply_amount,cy_jssm," +
  292. "dept_no,gl_percent_ft,yb_zf_flag,orig_price,try_result,supply_exec,cy_dj,receive_flag,chequ_type,print_flag_yj,confirm_flag_qx) " +
  293. " VALUES (#{patientId,jdbcType=CHAR},#{times,jdbcType=INTEGER},#{receiptNo,jdbcType=SMALLINT},#{orderNo,jdbcType=TINYINT},#{itemNo,jdbcType=TINYINT}," +
  294. "#{chargeItemCode,jdbcType=CHAR},#{billItemCode,jdbcType=CHAR},#{quantity,jdbcType=DOUBLE},#{unitPriceStr,jdbcType=DECIMAL},#{payMark,jdbcType=CHAR}," +
  295. "#{serial,jdbcType=CHAR},#{chargeItemType,jdbcType=CHAR},#{countryFlag,jdbcType=CHAR},#{drugFlag,jdbcType=CHAR},#{serialNo,jdbcType=INTEGER},#{name,jdbcType=CHAR}," +
  296. "#{chargeDate,jdbcType=TIMESTAMP},#{confirmTime,jdbcType=TIMESTAMP},#{groupNo,jdbcType=CHAR},#{confirmId,jdbcType=CHAR},#{drugWin,jdbcType=TINYINT},#{inputId,jdbcType=CHAR}," +
  297. "#{inputDate,jdbcType=TIMESTAMP},#{cashierId,jdbcType=CHAR},#{windowsNo,jdbcType=CHAR},#{priceId,jdbcType=CHAR},#{priceTime,jdbcType=TIMESTAMP},#{execDept,jdbcType=CHAR}," +
  298. "#{auditCode,jdbcType=CHAR},#{gongnksFlag,jdbcType=CHAR},#{printFlag,jdbcType=CHAR},#{confirmFlag,jdbcType=INTEGER},#{warnDept,jdbcType=CHAR},#{jzFlag,jdbcType=CHAR}," +
  299. "#{groupOrder,jdbcType=SMALLINT},#{cashId,jdbcType=CHAR},#{doctorCode,jdbcType=CHAR},#{supplyCode,jdbcType=CHAR},#{frequency,jdbcType=CHAR},#{drugQuan,jdbcType=DOUBLE}," +
  300. "#{drugUnit,jdbcType=CHAR},#{doctorFlag,jdbcType=CHAR},#{injectRes,jdbcType=DOUBLE},#{injectTimes,jdbcType=SMALLINT},#{confirmZs,jdbcType=CHAR},#{realNo,jdbcType=INTEGER}," +
  301. "#{windowsNoYf,jdbcType=VARCHAR},#{ybbxFlag,jdbcType=VARCHAR},#{tcNo,jdbcType=VARCHAR},#{tcName,jdbcType=VARCHAR},#{detailFlag,jdbcType=CHAR},#{glPercent,jdbcType=DECIMAL}," +
  302. "#{orderType,jdbcType=CHAR},#{supplyNo,jdbcType=VARCHAR},#{instructionCode,jdbcType=VARCHAR},#{instructionText,jdbcType=VARCHAR},#{orderDays,jdbcType=SMALLINT}," +
  303. "#{paySelf,jdbcType=CHAR},#{tryFlag,jdbcType=CHAR},#{reqYj,jdbcType=CHAR},#{reqNo,jdbcType=INTEGER},#{groupType,jdbcType=CHAR},#{orderBill,jdbcType=SMALLINT}," +
  304. "#{chargeBillCode,jdbcType=VARCHAR},#{selfFlag,jdbcType=CHAR},#{responceType,jdbcType=CHAR},#{decAmount,jdbcType=DECIMAL},#{backSerial,jdbcType=INTEGER},#{inputTime,jdbcType=TIMESTAMP}," +
  305. "#{cyMtjs,jdbcType=SMALLINT},#{cyJsl,jdbcType=SMALLINT},#{cyZql,jdbcType=SMALLINT},#{cyFj,jdbcType=SMALLINT},#{cyFfcs,jdbcType=SMALLINT},#{cyFysm,jdbcType=SMALLINT}," +
  306. "#{supplyAmount,jdbcType=SMALLINT},#{cyJssm,jdbcType=CHAR},#{deptNo,jdbcType=VARCHAR},#{glPercentFt,jdbcType=DECIMAL},#{ybZfFlag,jdbcType=CHAR},#{origPriceStr,jdbcType=DECIMAL}," +
  307. "#{tryResult,jdbcType=CHAR},#{supplyExec,jdbcType=CHAR},#{cyDj,jdbcType=CHAR},#{receiveFlag,jdbcType=CHAR},#{chequType,jdbcType=CHAR},#{printFlagYj,jdbcType=CHAR},#{confirmFlagQx,jdbcType=CHAR}) ")
  308. int insertMzChargeDetail(MzChargeDetail mzChargeDetail);
  309. /**
  310. * 批量保存门诊收费明细记录
  311. *
  312. * @param mzChargeDetails
  313. * @return
  314. */
  315. @Insert({
  316. "<script>",
  317. "INSERT INTO mz_charge_detail(patient_id,times,receipt_no,order_no,item_no,charge_item_code,bill_item_code,quantity,unit_price,pay_mark,serial,charge_item_type,",
  318. "country_flag,drug_flag,serial_no,name,charge_date,confirm_time,group_no,confirm_id,drug_win,input_id,input_date,cashier_id,windows_no,price_id,price_time,exec_dept,",
  319. "audit_code,gongnks_flag,print_flag,confirm_flag,warn_dept,jz_flag,group_order,cash_id,doctor_code,supply_code,frequency,drug_quan,drug_unit,doctor_flag,inject_res,inject_times,",
  320. "confirm_zs,real_no,windows_no_yf,ybbx_flag,tc_no,tc_name,detail_flag,gl_percent,order_type,supply_no,instruction_code,instruction_text,order_days,pay_self,try_flag,req_yj,",
  321. "req_no,group_type,order_bill,charge_bill_code,self_flag,responce_type,dec_amount,back_serial,input_time,cy_mtjs,cy_jsl,cy_zql,cy_fj,cy_ffcs,cy_fysm,supply_amount,cy_jssm,",
  322. "dept_no,gl_percent_ft,yb_zf_flag,orig_price,try_result,supply_exec,cy_dj,receive_flag,chequ_type,print_flag_yj,confirm_flag_qx) VALUES ",
  323. "<foreach collection='mzChargeDetails' item='item' index='index' separator=','>",
  324. " (#{item.patientId,jdbcType=CHAR},#{item.times,jdbcType=INTEGER},#{item.receiptNo,jdbcType=SMALLINT},#{item.orderNo,jdbcType=TINYINT},#{item.itemNo,jdbcType=TINYINT},",
  325. "#{item.chargeItemCode,jdbcType=CHAR},#{item.billItemCode,jdbcType=CHAR},#{item.quantity,jdbcType=DOUBLE},#{item.unitPriceStr,jdbcType=DECIMAL},#{item.payMark,jdbcType=CHAR},",
  326. "#{item.serial,jdbcType=CHAR},#{item.chargeItemType,jdbcType=CHAR},#{item.countryFlag,jdbcType=CHAR},#{item.drugFlag,jdbcType=CHAR},#{item.serialNo,jdbcType=INTEGER},#{item.name,jdbcType=CHAR},",
  327. "#{item.chargeDate,jdbcType=TIMESTAMP},#{item.confirmTime,jdbcType=TIMESTAMP},#{item.groupNo,jdbcType=CHAR},#{item.confirmId,jdbcType=CHAR},#{item.drugWin,jdbcType=TINYINT},#{item.inputId,jdbcType=CHAR},",
  328. "#{item.inputDate,jdbcType=TIMESTAMP},#{item.cashierId,jdbcType=CHAR},#{item.windowsNo,jdbcType=CHAR},#{item.priceId,jdbcType=CHAR},#{item.priceTime,jdbcType=TIMESTAMP},#{item.execDept,jdbcType=CHAR},",
  329. "#{item.auditCode,jdbcType=CHAR},#{item.gongnksFlag,jdbcType=CHAR},#{item.printFlag,jdbcType=CHAR},#{item.confirmFlag,jdbcType=INTEGER},#{item.warnDept,jdbcType=CHAR},#{item.jzFlag,jdbcType=CHAR},",
  330. "#{item.groupOrder,jdbcType=SMALLINT},#{item.cashId,jdbcType=CHAR},#{item.doctorCode,jdbcType=CHAR},#{item.supplyCode,jdbcType=CHAR},#{item.frequency,jdbcType=CHAR},#{item.drugQuan,jdbcType=DOUBLE},",
  331. "#{item.drugUnit,jdbcType=CHAR},#{item.doctorFlag,jdbcType=CHAR},#{item.injectRes,jdbcType=DOUBLE},#{item.injectTimes,jdbcType=SMALLINT},#{item.confirmZs,jdbcType=CHAR},#{item.realNo,jdbcType=INTEGER},",
  332. "#{item.windowsNoYf,jdbcType=VARCHAR},#{item.ybbxFlag,jdbcType=VARCHAR},#{item.tcNo,jdbcType=VARCHAR},#{item.tcName,jdbcType=VARCHAR},#{item.detailFlag,jdbcType=CHAR},#{item.glPercent,jdbcType=DECIMAL},",
  333. "#{item.orderType,jdbcType=CHAR},#{item.supplyNo,jdbcType=VARCHAR},#{item.instructionCode,jdbcType=VARCHAR},#{item.instructionText,jdbcType=VARCHAR},#{item.orderDays,jdbcType=SMALLINT},",
  334. "#{item.paySelf,jdbcType=CHAR},#{item.tryFlag,jdbcType=CHAR},#{item.reqYj,jdbcType=CHAR},#{item.reqNo,jdbcType=INTEGER},#{item.groupType,jdbcType=CHAR},#{item.orderBill,jdbcType=SMALLINT},",
  335. "#{item.chargeBillCode,jdbcType=VARCHAR},#{item.selfFlag,jdbcType=CHAR},#{item.responceType,jdbcType=CHAR},#{item.decAmount,jdbcType=DECIMAL},#{item.backSerial,jdbcType=INTEGER},#{item.inputTime,jdbcType=TIMESTAMP},",
  336. "#{item.cyMtjs,jdbcType=SMALLINT},#{item.cyJsl,jdbcType=SMALLINT},#{item.cyZql,jdbcType=SMALLINT},#{item.cyFj,jdbcType=SMALLINT},#{item.cyFfcs,jdbcType=SMALLINT},#{item.cyFysm,jdbcType=SMALLINT},",
  337. "#{item.supplyAmount,jdbcType=SMALLINT},#{item.cyJssm,jdbcType=CHAR},#{item.deptNo,jdbcType=VARCHAR},#{item.glPercentFt,jdbcType=DECIMAL},#{item.ybZfFlag,jdbcType=CHAR},#{item.origPriceStr,jdbcType=DECIMAL},",
  338. "#{item.tryResult,jdbcType=CHAR},#{item.supplyExec,jdbcType=CHAR},#{item.cyDj,jdbcType=CHAR},#{item.receiveFlag,jdbcType=CHAR},#{item.chequType,jdbcType=CHAR},#{item.printFlagYj,jdbcType=CHAR},#{item.confirmFlagQx,jdbcType=CHAR}) ",
  339. "</foreach>",
  340. "</script>"
  341. })
  342. int batchInsertMzChargeDetail(@Param(value = "mzChargeDetails") List<MzChargeDetail> mzChargeDetails);
  343. /**
  344. * 查询近三天内没有缴费的药品处方
  345. *
  346. * @param patientId
  347. * @return
  348. */
  349. @Select({"<script>",
  350. "select rtrim(patient_id) patient_id,times =times,doctor_code=min(doctor_code), cf_type='1', order_count=count(distinct order_no), receipt_no =min(receipt_no),visit_date =min(price_time)," +
  351. "name=min(name) from mz_charge_detail where 1=1",
  352. "<when test='patientId!=null'>",
  353. " and patient_id=#{patientId,jdbcType=CHAR}",
  354. "</when>",
  355. " and pay_mark='5' and (datediff(day,price_time,getdate()) <![CDATA[ <= ]]> 3) group by patient_id,times",
  356. "</script>"})
  357. List<Map<String, Object>> selectUnPaidChargeDetail(@Param(value = "patientId") String patientId);
  358. /**
  359. * 修改当前病人当前就诊次数下的所有记录的付款状态和打印标记以及确认标记
  360. *
  361. * @param mzChargeDetail
  362. * @return
  363. */
  364. @Update({"<script>",
  365. "update mz_charge_detail ",
  366. "<trim prefix='set' prefixOverrides=',' suffix=' where patient_id = #{patientId} and times=#{times}' >",
  367. "<when test='payMark!=null'>",
  368. ",pay_mark =#{payMark,jdbcType=CHAR}",
  369. "</when>",
  370. "<when test='printFlag!=null'>",
  371. ",print_flag =#{printFlag,jdbcType=CHAR}",
  372. "</when>",
  373. "<when test='receiptNo!=null'>",
  374. ",receipt_no =#{receiptNo,jdbcType=INTEGER}",
  375. "</when>",
  376. "<when test='confirmFlag!=null'>",
  377. ",confirm_flag =#{confirmFlag,jdbcType=CHAR}",
  378. "</when>",
  379. "</trim>",
  380. "</script>"})
  381. int updatePayMakAndPrintFlag(MzChargeDetail mzChargeDetail);
  382. /**
  383. * 修改缴费明细记录
  384. *
  385. * @param mzChargeDetail
  386. * @return
  387. */
  388. @Update({"<script>",
  389. "update mz_charge_detail ",
  390. "<trim prefix='set' prefixOverrides=',' suffix=' where patient_id = #{patientId} and times=#{times} and charge_item_code=#{chargeItemCode,jdbcType=CHAR}' >",
  391. "<when test='serialNo!=null'>",
  392. "serial_no =#{serialNo,jdbcType=INTEGER}",
  393. "</when>",
  394. "<when test='realNo!=null'>",
  395. ",real_no =#{realNo,jdbcType=INTEGER}",
  396. "</when>",
  397. "<when test='cashId!=null'>",
  398. ",cash_id =#{cashId,jdbcType=CHAR}",
  399. "</when>",
  400. "<when test='chargeDate!=null'>",
  401. ",charge_date =#{chargeDate,jdbcType=TIMESTAMP}",
  402. "</when>",
  403. "<when test='payMark!=null'>",
  404. ",pay_mark =#{payMark,jdbcType=CHAR}",
  405. "</when>",
  406. "<when test='printFlag!=null'>",
  407. ",print_flag =#{printFlag,jdbcType=CHAR}",
  408. "</when>",
  409. "<when test='windowsNoYf!=null'>",
  410. ",windows_no_yf =#{windowsNoYf,jdbcType=VARCHAR}",
  411. "</when>",
  412. "<when test='backSerial!=null'>",
  413. ",back_serial =#{backSerial,jdbcType=INTEGER}",
  414. "</when>",
  415. "</trim>",
  416. "</script>"})
  417. int updateMzChargeDetail(MzChargeDetail mzChargeDetail);
  418. /**
  419. * 查询所有的记账记录
  420. *
  421. * @param patientId
  422. * @param times
  423. * @return
  424. */
  425. @Select({"<script>",
  426. "select rtrim(patient_id) patient_id,times,receipt_no,order_no,item_no,rtrim(charge_item_code) charge_item_code,rtrim(bill_item_code) bill_item_code,",
  427. "quantity,unit_price,rtrim(pay_mark) pay_mark,rtrim(serial) serial,rtrim(charge_item_type) charge_item_type,rtrim(country_flag) country_flag,rtrim(drug_flag) drug_flag,",
  428. "serial_no,rtrim(name) name,charge_date,confirm_time,rtrim(group_no) group_no,rtrim(confirm_id) confirm_id,drug_win,rtrim(input_id) input_id,input_date,",
  429. "rtrim(cashier_id) cashier_id,rtrim(windows_no) windows_no,rtrim(price_id) price_id,price_time,rtrim(exec_dept) exec_dept,rtrim(audit_code) audit_code,",
  430. "rtrim(gongnks_flag) gongnks_flag,rtrim(print_flag) print_flag,confirm_flag,rtrim(warn_dept) warn_dept,rtrim(jz_flag) jz_flag,group_order,rtrim(cash_id) cash_id,",
  431. "rtrim(doctor_code) doctor_code,rtrim(supply_code) supply_code,rtrim(frequency) frequency,drug_quan,rtrim(drug_unit) drug_unit,rtrim(doctor_flag) doctor_flag,inject_res,inject_times,",
  432. "rtrim(confirm_zs) confirm_zs,real_no,windows_no_yf,ybbx_flag,tc_no,tc_name,rtrim(detail_flag) detail_flag,gl_percent,rtrim(order_type) order_type,supply_no,instruction_code,",
  433. "instruction_text,order_days,rtrim(pay_self) pay_self,rtrim(try_flag) try_flag,rtrim(req_yj) req_yj,req_no,rtrim(group_type) group_type,order_bill,charge_bill_code,",
  434. "rtrim(self_flag) self_flag,rtrim(responce_type) responce_type,dec_amount,back_serial,input_time,cy_mtjs,cy_jsl,cy_zql,cy_fj,cy_ffcs,cy_fysm,supply_amount,rtrim(cy_jssm) cy_jssm,",
  435. "dept_no,gl_percent_ft,rtrim(yb_zf_flag) yb_zf_flag,orig_price,rtrim(try_result) try_result,rtrim(supply_exec) supply_exec,rtrim(cy_dj) cy_dj,rtrim(receive_flag) receive_flag,",
  436. "rtrim(chequ_type) chequ_type,rtrim(print_flag_yj) print_flag_yj,rtrim(confirm_flag_qx) confirm_flag_qx ",
  437. "from dbo.mz_charge_detail where patient_id =#{patientId,jdbcType=CHAR} and pay_mark=0 and times =#{times} and receipt_no =#{receiptNo} ",
  438. "</script>"})
  439. List<MzChargeDetail> selectJiZhangDetails(@Param(value = "patientId") String patientId, @Param("times") Integer times, @Param("receiptNo") Integer receiptNo);
  440. /**
  441. * 查询当前就诊次数的所有取药号与药房信息
  442. *
  443. * @param patientId
  444. * @param times
  445. * @return
  446. */
  447. @Select("select back_serial,rtrim(group_no) group_no,windows_no_yf from mz_charge_detail where patient_id=#{patientId,jdbcType=CHAR} and times = #{times,jdbcType=INTEGER} and back_serial>0 group by back_serial,group_no,windows_no_yf")
  448. List<MzChargeDetail> selectFyJl(@Param("patientId") String patientId, @Param("times") Integer times);
  449. /**
  450. * 修改发票打印标记
  451. *
  452. * @param patientId
  453. * @param times
  454. * @return
  455. */
  456. @Update({"<script>",
  457. "update mz_charge_detail set print_flag =1 where patient_id = #{patientId} and times in ",
  458. "<foreach item='item' index='index' collection='times' open='(' separator=',' close=')'>",
  459. "#{item}",
  460. "</foreach>",
  461. "</script>"})
  462. int updatePrintFlag(@Param("patientId") String patientId, @Param("times") List<Integer> times);
  463. /**
  464. * 修改发票流水号与缴费次数 发票作废重打时调用
  465. *
  466. * @param receiptNo
  467. * @param serialNo
  468. * @param oriSerialNo
  469. * @return
  470. */
  471. @Update("update mz_charge_detail set receipt_no =#{receiptNo},serial_no=#{serialNo},real_no=#{serialNo} where serial_no = #{oriSerialNo}")
  472. int updateBySerialNo(@Param("receiptNo") Integer receiptNo, @Param("serialNo") Integer serialNo, @Param("oriSerialNo") Integer oriSerialNo);
  473. /**
  474. * 修改病人姓名 120病人缴费时调用
  475. *
  476. * @param name
  477. * @param patientId
  478. * @param times
  479. * @return
  480. */
  481. @Update("update mz_charge_detail set name =#{name} where patient_id = #{patientId} and times = #{times}")
  482. int updateNameByPatientIdAndTimes(@Param("name") String name, @Param("patientId") String patientId, @Param("times") Integer times);
  483. /**
  484. * 查询病人缴费记录
  485. *
  486. * @param patientId
  487. * @param name
  488. * @param serialNo
  489. * @param beginDate
  490. * @param endDate
  491. * @return
  492. */
  493. @Select({"<script>",
  494. "SELECT distinct rtrim(a.patient_id) patient_id,name,a.times,a.receipt_no,charge_date=convert(char(10),a.charge_date,111) ,a.serial_no,real_no ,a.responce_type," +
  495. " cheque_type=case when mz_receipt_serial.cheque_type='Y' and cash_id <![CDATA[<>]]> '99999' " +
  496. " and len(ltrim(rtrim(mz_receipt_serial.receipt_bill))) <![CDATA[>=]]> 10 then '本院记账' else '自费' end " +
  497. " FROM mz_charge_detail a,mz_receipt_serial " +
  498. " WHERE a.charge_date <![CDATA[>=]]> #{beginDate,jdbcType=TIMESTAMP} and a.charge_date <![CDATA[<=]]> #{endDate,jdbcType=TIMESTAMP} " +
  499. "<when test='patientId!=null'>",
  500. " and a.patient_id like #{patientId}",
  501. "</when>",
  502. "<when test='name!=null'>",
  503. " and a.name like #{name}",
  504. "</when>",
  505. "<when test='serialNo!=null'>",
  506. " and mz_receipt_serial.serial_no like #{serialNo}",
  507. "</when>",
  508. " and real_no=receipt_sn" +
  509. "</script>"})
  510. List<Map<String, Object>> selectChargeListByPatient(@Param("patientId") String patientId, @Param("name") String name, @Param("serialNo") String serialNo, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
  511. /**
  512. * 根据病人编码和收费流水号查询缴费明细
  513. *
  514. * @param patientId
  515. * @param serialNo
  516. * @return
  517. */
  518. @Select("SELECT patient_id=a.patient_id," +
  519. " times =a.times," +
  520. " receipt_no=a.receipt_no," +
  521. " order_no =a.order_no," +
  522. " quantity =a.quantity * drug_win," +
  523. " unit_price=a.unit_price," +
  524. " name =a.name," +
  525. " drugname =b.name," +
  526. " specification=b.specification," +
  527. " frequency =a.frequency," +
  528. " supply_code =a.supply_code," +
  529. " amount =a.drug_quan," +
  530. " drug_unit =a.drug_unit," +
  531. " item_no =a.item_no," +
  532. " doctor_code =a.doctor_code," +
  533. " op_id =a.cash_id," +
  534. " real_no =a.real_no," +
  535. " group_no=a.group_no," +
  536. " total_price=a.quantity * drug_win* a.unit_price," +
  537. " tybm=b.code ," +
  538. " unit=b.pack_unit," +
  539. " warn_dept=warn_dept," +
  540. " charge_date," +
  541. " print_flag = (select max(cheque_type) from mz_receipt_serial where mz_receipt_serial.receipt_sn = a.real_no) " +
  542. " FROM mz_charge_detail a,yp_zd_dict b " +
  543. " WHERE a.patient_id = #{patientId} AND " +
  544. " a.real_no=#{serialNo} and " +
  545. " a.charge_item_code=b.code and " +
  546. " a.serial=b.serial " +
  547. " union all " +
  548. "SELECT patient_id=a.patient_id," +
  549. " times =a.times," +
  550. " receipt_no=a.receipt_no," +
  551. " order_no =a.order_no," +
  552. " quantity =a.quantity * drug_win," +
  553. " unit_price=a.unit_price," +
  554. " name =a.name," +
  555. " drugname =b.name," +
  556. " specification=b.charge_unit," +
  557. " frequency =a.frequency," +
  558. " supply_code =a.supply_code," +
  559. " amount =a.drug_quan," +
  560. " drug_unit =a.drug_unit," +
  561. " item_no =a.item_no," +
  562. " doctor_code =a.doctor_code," +
  563. " op_id =a.cash_id," +
  564. " real_no =a.real_no," +
  565. " group_no=a.group_no," +
  566. " total_price=a.quantity * drug_win* a.unit_price," +
  567. " tybm=isnull(b.s_code,b.code)," +
  568. " unit=charge_unit," +
  569. " warn_dept=warn_dept," +
  570. " charge_date," +
  571. " print_flag = (select max(cheque_type) from mz_receipt_serial where mz_receipt_serial.receipt_sn = a.real_no) " +
  572. " FROM mz_charge_detail a,zd_charge_item b" +
  573. " WHERE a.patient_id = #{patientId} AND " +
  574. " a.real_no=#{serialNo} and " +
  575. " a.charge_item_code=b.code and " +
  576. " a.serial <>'01' and " +
  577. " a.serial <>'99'")
  578. List<Map<String, Object>> selectChargeDetailByPatient(@Param("patientId") String patientId, @Param("serialNo") String serialNo);
  579. /**
  580. * 查询病人缴费记录 (历史数据)
  581. *
  582. * @param patientId
  583. * @param name
  584. * @param serialNo
  585. * @param beginDate
  586. * @param endDate
  587. * @return
  588. */
  589. @Select({"<script>",
  590. "SELECT distinct rtrim(a.patient_id) patient_id,name,a.times,a.receipt_no,charge_date=convert(char(10),a.charge_date,111) ,a.serial_no,real_no ,a.responce_type," +
  591. " cheque_type=case when mz_receipt_serial_b.cheque_type='Y' " +
  592. " and len(ltrim(rtrim(mz_receipt_serial_b.receipt_bill))) <![CDATA[>=]]> 10 then '本院记账' else '自费' end " +
  593. " FROM mz_charge_detail_b a,mz_receipt_serial_b " +
  594. " WHERE a.charge_date <![CDATA[>=]]> #{beginDate,jdbcType=TIMESTAMP} and a.charge_date <![CDATA[<=]]> #{endDate,jdbcType=TIMESTAMP} " +
  595. "<when test='patientId!=null'>",
  596. " and a.patient_id =#{patientId}",
  597. "</when>",
  598. "<when test='name!=null'>",
  599. " and a.name like #{name}",
  600. "</when>",
  601. "<when test='serialNo!=null'>",
  602. " and mz_receipt_serial_b.serial_no =#{serialNo}",
  603. "</when>",
  604. " and real_no=receipt_sn" +
  605. "</script>"})
  606. List<Map<String, Object>> selectHisChargeListByPatient(@Param("patientId") String patientId, @Param("name") String name, @Param("serialNo") String serialNo, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
  607. /**
  608. * 根据病人编码和收费流水号查询缴费明细 (历史数据)
  609. *
  610. * @param patientId
  611. * @param serialNo
  612. * @return
  613. */
  614. @Select("SELECT patient_id=a.patient_id," +
  615. " times =a.times," +
  616. " receipt_no=a.receipt_no," +
  617. " order_no =a.order_no," +
  618. " quantity =a.quantity * drug_win," +
  619. " unit_price=a.unit_price," +
  620. " name =a.name," +
  621. " drugname =b.name," +
  622. " specification=b.specification," +
  623. " frequency =a.frequency," +
  624. " supply_code =a.supply_code," +
  625. " amount =a.drug_quan," +
  626. " drug_unit =a.drug_unit," +
  627. " item_no =a.item_no," +
  628. " doctor_code =a.doctor_code," +
  629. " op_id =a.cash_id," +
  630. " real_no =a.real_no," +
  631. " group_no=a.group_no," +
  632. " total_price=a.quantity * drug_win* a.unit_price," +
  633. " tybm=b.code ," +
  634. " unit=b.pack_unit," +
  635. " warn_dept=warn_dept," +
  636. " charge_date," +
  637. " FROM mz_charge_detail_b a,yp_zd_dict_b b " +
  638. " WHERE a.patient_id = #{patientId} AND " +
  639. " a.real_no=#{serialNo} and " +
  640. " a.charge_item_code=b.code and " +
  641. " a.serial=b.serial " +
  642. " union all " +
  643. "SELECT patient_id=a.patient_id," +
  644. " times =a.times," +
  645. " receipt_no=a.receipt_no," +
  646. " order_no =a.order_no," +
  647. " quantity =a.quantity * drug_win," +
  648. " unit_price=a.unit_price," +
  649. " name =a.name," +
  650. " drugname =b.name," +
  651. " specification=b.charge_unit," +
  652. " frequency =a.frequency," +
  653. " supply_code =a.supply_code," +
  654. " amount =a.drug_quan," +
  655. " drug_unit =a.drug_unit," +
  656. " item_no =a.item_no," +
  657. " doctor_code =a.doctor_code," +
  658. " op_id =a.cash_id," +
  659. " real_no =a.real_no," +
  660. " group_no=a.group_no," +
  661. " total_price=a.quantity * drug_win* a.unit_price," +
  662. " tybm=isnull(b.s_code,b.code)," +
  663. " unit=charge_unit," +
  664. " warn_dept=warn_dept," +
  665. " charge_date," +
  666. " FROM mz_charge_detail_b a,zd_charge_item_b b" +
  667. " WHERE a.patient_id = #{patientId} AND " +
  668. " a.real_no=#{serialNo} and " +
  669. " a.charge_item_code=b.code and " +
  670. " a.serial <>'01' and " +
  671. " a.serial <>'99'")
  672. List<Map<String, Object>> selectHisChargeDetailByPatient(@Param("patientId") String patientId, @Param("serialNo") String serialNo);
  673. /**
  674. * 根据病人就诊次数和门诊号查询有效的申请科室和医生编码
  675. *
  676. * @param patientId
  677. * @param times
  678. * @return
  679. */
  680. @Select("select top 1 rtrim(warn_dept) warn_dept,rtrim(doctor_code) doctor_code,rtrim(print_flag) print_flag from mz_charge_detail where patient_id = #{patientId} and times = #{times} and warn_dept is not null and doctor_code is not null and warn_dept<> '' and doctor_code<> '' ")
  681. MzChargeDetail selectWarnDeptAndDoctor(@Param("patientId") String patientId, @Param("times") Integer times);
  682. /**
  683. * 清洗老系统打印发票数据
  684. *
  685. * @return
  686. */
  687. @Update("update mz_charge_detail set confirm_flag=4 where real_no in (select abs(real_no) from mz_charge_detail where real_no <0 group by real_no)")
  688. int refshOldSystemReceiptData();
  689. /**
  690. * 查询120 病人姓名
  691. *
  692. * @param patientId
  693. * @param times
  694. * @return
  695. */
  696. @Select("select top 1 name from mz_charge_detail where patient_id = #{patientId} and times = #{times} and name is not null and name <> '' ")
  697. String selectJZName(@Param("patientId") String patientId, @Param("times") Integer times);
  698. /**
  699. *
  700. * @param thmzmxsrParamsVo caseType = 1 申请科室核算报表 0 执行科室核算报表
  701. * @return
  702. */
  703. @Select({"<script>",
  704. "SELECT " +
  705. " exec_dept= z.name," +
  706. " charge_bill_code= case a.charge_bill_code when 'BILL10' then 'BILL01' when 'BILL11' then 'BILL28' when 'BILL12' then 'BILL02' else a.charge_bill_code end," +
  707. " parent=max( d.parent_code )," +
  708. " total_charge= case when (b.pay_id ='99999' and b.charge_dcount_date <![CDATA[<=]]> '2021-12-01 23:59:59') then isnull(sum(round(convert(decimal(18,2),((convert(decimal(18,2),unit_price)) * (quantity * isnull(drug_win,1)))),2)),0) else isnull(sum(round(convert(decimal(18,3),((convert(decimal(18,3),unit_price)) * (quantity * isnull(drug_win,1)))),2)),0) end ," +
  709. " audit_code=case when isnull(a.group_no,'00')='71' then max(d.name)+'(门诊)' when isnull(a.group_no,'00')='72' then max(d.name)+'(急诊)' else max(d.name) end," +
  710. " charge_dcount_date=b.charge_dcount_date " +
  711. " FROM ${firstTableName} a(nolock), " +
  712. " (select distinct patient_id,times,receipt_no, serial_no,receipt_sn,charge_dcount_date,pay_id from ${secondTableName} " +
  713. " where (case 1 when '0' then charge_date " +
  714. " else charge_dcount_date end) <![CDATA[>=]]> #{beginDate} and " +
  715. " (case 1 when '0' then charge_date " +
  716. " else charge_dcount_date end) <![CDATA[<=]]> #{endDate} and " +
  717. " (case 1 when '0' then isnull(dcount_no,0) " +
  718. " else 1 end) = isnull(dcount_no,0) ) as b, " +
  719. " zd_charge_item c," +
  720. " zy_zd_audit_item d, zd_unit_code z " +
  721. " WHERE ( a.patient_id = b.patient_id ) and " +
  722. " a.times=b.times and " +
  723. " a.receipt_no=b.receipt_no and " +
  724. " case a.charge_bill_code when 'BILL10' then 'BILL01' when 'BILL11' then 'BILL28' when 'BILL12' then 'BILL02' else a.charge_bill_code end*=c.code and " +
  725. " isnull(c.audit_code,d.code)=d.code and " +
  726. " a.serial_no=b.serial_no and " +
  727. " a.real_no=b.receipt_sn and " +
  728. " a.bill_item_code <![CDATA[<>]]> 'TC' " +
  729. " and ( case 1 when #{caseType} then " +
  730. " case when isnull(a.warn_dept,'')='' then a.exec_dept else a.warn_dept end " +
  731. " else " +
  732. " case when isnull(a.exec_dept,'') ='' then a.warn_dept else a.exec_dept end " +
  733. " end )*=z.code " +
  734. // " and isnull(a.dept_no,'') like '%' " +
  735. "<when test='execDept!=null'>",
  736. " and ( case '1' when #{caseType} then " +
  737. " case when isnull(a.warn_dept,'')='' then a.exec_dept else a.warn_dept end " +
  738. " else " +
  739. " case when isnull(a.exec_dept,'') ='' then a.warn_dept else a.exec_dept end " +
  740. " end " +
  741. ") =#{execDept} " +
  742. "</when>" +
  743. "group by " +
  744. "z.name,c.audit_code,isnull(a.group_no,'00')," +
  745. " case a.charge_bill_code when 'BILL10' then 'BILL01' when 'BILL11' then 'BILL28' when 'BILL12' then 'BILL02' else a.charge_bill_code end" +
  746. ",b.charge_dcount_date,b.pay_id ",
  747. "</script>"})
  748. List<Map<String, Object>> selectDepetBusinessReport(ThmzmxsrParamsVo thmzmxsrParamsVo);
  749. }