index.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import router from "@/router";
  2. import * as api from "@/api/inpatient/xiang-mu-lu-ru";
  3. import XEUtils from "xe-utils";
  4. import { BizException, ExceptionEnum } from "@/utils/BizException";
  5. import useCompRef from "@/utils/useCompRef";
  6. import { ElTable } from "element-plus";
  7. import { refund } from "@/api/hospitalization-costs/hospitalization-costs-api";
  8. import { isDev } from "@/utils/public";
  9. import cyRefList from "@/utils/cyRefList";
  10. import { useDialog, UseDialogType } from "@/components/cy/CyDialog/index";
  11. import { useUserStore } from "@/pinia/user-store";
  12. import { getServerDateApi } from "@/api/public-api";
  13. import PrintPrescriptionSign from "@/components/xmlr/components/PrintPrescriptionSign.vue";
  14. import {
  15. getFrequency,
  16. getSupplyType,
  17. } from "@/api/zhu-yuan-yi-sheng/yi-zhu-lu-ru";
  18. import dayjs from "dayjs";
  19. type PatInfo = {
  20. name?: string;
  21. inpatientNo?: string;
  22. admissTimes?: number;
  23. zySerialNo?: string;
  24. ledgerSn?: number;
  25. zkWard?: string;
  26. admissDept?: string;
  27. referPhysician?: string;
  28. ward?: string;
  29. };
  30. type ChargeCodeType = {
  31. chargeCodeMx: string;
  32. serial: string;
  33. chargeName: string;
  34. deptCode: string;
  35. chargeAmount: number;
  36. amount: number;
  37. doctorCode: string;
  38. };
  39. export type XmlrProps = {
  40. patNo?: string;
  41. medicalTechnology?: boolean;
  42. };
  43. export const useXmlr = (props: XmlrProps, emits: UseDialogType.Emits) => {
  44. const userInfo = useUserStore().userInfo;
  45. const store = reactive({
  46. // 住院号
  47. searchPatNo: isDev ? "0434450" : "",
  48. // 患者信息
  49. patInfo: {} as PatInfo,
  50. searchFeeParams: {
  51. orderNo: "",
  52. chargeCode: "",
  53. startTime: "",
  54. endTime: "",
  55. orderBy: true,
  56. chargeType: 0,
  57. feeSources: 2,
  58. refundSymbol: 3,
  59. execDept: props.medicalTechnology ? (isDev ? "" : userInfo.deptCode) : "",
  60. },
  61. tabsVal: isDev ? "费用" : "费用",
  62. feeTotal: 0,
  63. feeData: [],
  64. feeCurrentPage: 1,
  65. feePageSize: 10,
  66. queryWard: "",
  67. queryDept: "",
  68. chargeDate: "",
  69. });
  70. const [saveData, saveProxy] = cyRefList<ChargeCodeType>(
  71. item => {
  72. return item.chargeCodeMx.trim() + "_" + item.serial.trim();
  73. },
  74. item => {
  75. return `项目【${item.chargeName}】请勿重复添加`;
  76. }
  77. );
  78. const feeTableRef = useCompRef(ElTable);
  79. const muBanRef = shallowRef();
  80. const mutation = {
  81. async getPatInfo(times: number = null) {
  82. await api
  83. .getPatientInfo(store.searchPatNo, times)
  84. .then(res => {
  85. store.patInfo = res;
  86. mutation.getFee();
  87. store.queryWard = res?.admissDept;
  88. store.queryDept = res?.zkWard;
  89. getServerDateApi()
  90. .then(res => {
  91. //@ts-ignore
  92. store.chargeDate = res;
  93. })
  94. .catch(() => {
  95. //@ts-ignore
  96. store.chargeDate = dayjs(new Date()).format(
  97. "YYYY-MM-DD hh:mm:ss"
  98. );
  99. });
  100. return res;
  101. })
  102. .catch(() => {
  103. mutation.clearData();
  104. return {};
  105. });
  106. },
  107. getFee() {
  108. if (XEUtils.isEmpty(store.patInfo)) {
  109. BizException(ExceptionEnum.MESSAGE_ERROR, "请先查询患者");
  110. }
  111. feeTableRef.value.clearSelection();
  112. api
  113. .getFee({
  114. inpatientNo: store.patInfo.inpatientNo,
  115. admissTimes: store.patInfo.admissTimes,
  116. medicalTechnology: props.medicalTechnology,
  117. ...store.searchFeeParams,
  118. })
  119. .then(res => {
  120. store.feeData = res.data;
  121. store.feeTotal = res.feeTotal;
  122. });
  123. },
  124. clearData() {
  125. store.patInfo = {};
  126. store.feeData = [];
  127. store.feeTotal = 0;
  128. store.feeCurrentPage = 1;
  129. saveProxy.clear();
  130. },
  131. refund(value) {
  132. refund({
  133. inpatientNo: store.patInfo.inpatientNo,
  134. admissTimes: store.patInfo.admissTimes,
  135. groupNo: value.groupNo,
  136. list: value.data,
  137. }).then(res => {
  138. mutation.getFee();
  139. });
  140. },
  141. async setPatNo(patNo: string) {
  142. if (patNo) {
  143. store.searchPatNo = patNo as string;
  144. await mutation.getPatInfo();
  145. }
  146. },
  147. closeDialog() {
  148. emits("cyDialogConfirm");
  149. },
  150. feeTableSummaryMethod() {
  151. const tmp = [];
  152. tmp[9] = `${store.feeTotal} 元`;
  153. return tmp;
  154. },
  155. async handlePrintPrescriptionSign() {
  156. const data = feeTableRef.value.getSelectionRows();
  157. if (data.length === 0) {
  158. return;
  159. }
  160. const filter = XEUtils.filter(data, item => {
  161. return item.orderNo === 6 && item.serial !== "00";
  162. });
  163. if (filter.length === 0) {
  164. return;
  165. }
  166. const frequency = await mutation.getExecutionFrequency();
  167. const supplyType = await mutation.getSupplyType();
  168. useDialog(PrintPrescriptionSign, {
  169. dialogProps: {
  170. title: "打印处方签",
  171. fullscreen: true,
  172. },
  173. confirmText: "打印",
  174. params: {
  175. data: XEUtils.cloneDeep(filter),
  176. frequency,
  177. supplyType,
  178. patientInfo: store.patInfo,
  179. },
  180. });
  181. },
  182. getExecutionFrequency: XEUtils.once(async () => {
  183. return await getFrequency();
  184. }),
  185. getSupplyType: XEUtils.once(async () => {
  186. return await getSupplyType();
  187. }),
  188. };
  189. onActivated(() => {
  190. const patNo = router.currentRoute.value.query.patNo;
  191. mutation.setPatNo(patNo as string);
  192. });
  193. onMounted(async () => {
  194. await mutation.setPatNo(props.patNo);
  195. });
  196. return {
  197. mutation,
  198. store,
  199. feeTableRef,
  200. medicalTechnology: props.medicalTechnology,
  201. saveData,
  202. saveProxy,
  203. muBanRef,
  204. };
  205. };
  206. export const key = "projectInput";
  207. export type ProjectInput = ReturnType<typeof useXmlr>;