his_hospital_api_controller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "math/rand"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type HisHospitalApiController struct {
  14. BaseAuthAPIController
  15. }
  16. func HisHospitalManagerApiRegistRouters() {
  17. beego.Router("/api/hishospitalpatient/list", &HisHospitalApiController{}, "get:GetHisHospitalPatientList")
  18. beego.Router("/api/hospitalcharge/list", &HisHospitalApiController{}, "get:GetHisHospitalChargePatientList")
  19. beego.Router("/api/hospotalcharge/info", &HisHospitalApiController{}, "get:GetHisHospitalChargePatientInfo")
  20. beego.Router("/api/hospitalprescription/list", &HisHospitalApiController{}, "get:GetHisHospitalPrescriptionList")
  21. beego.Router("/api/hospital/inhopitalcheck/get", &HisHospitalApiController{}, "get:GetZHInHospitalCheck")
  22. beego.Router("/api/hospital/outhopitalcheck/get", &HisHospitalApiController{}, "get:GetZHOutHospitalCheck")
  23. beego.Router("/api/hospital/settle/get", &HisHospitalApiController{}, "get:GetSettleInfo")
  24. beego.Router("/api/hospital/inthopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHInHospitalUnCheck")
  25. beego.Router("/api/hospital/outhopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHOutHospitalUnCheck")
  26. beego.Router("/api/hospital/refund", &HisHospitalApiController{}, "get:ZHRefund")
  27. }
  28. func (c *HisHospitalApiController) GetHisHospitalPatientList() {
  29. record_date := c.GetString("record_date")
  30. types, _ := c.GetInt64("type", 0)
  31. sch_type, _ := c.GetInt64("sch_type", 0)
  32. timeLayout := "2006-01-02"
  33. loc, _ := time.LoadLocation("Local")
  34. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  35. if err != nil {
  36. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  37. return
  38. }
  39. recordDateTime := theTime.Unix()
  40. adminInfo := c.GetAdminUserInfo()
  41. //var patients []*service.HospitalPatient
  42. tempPatients, _ := service.GetHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime)
  43. tempPatients_two, _ := service.GetHisHospitalSchPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  44. //当天有登记住院的和排班同时存在的话,删除掉排班的记录
  45. for _, item := range tempPatients {
  46. for index, subItem := range tempPatients_two {
  47. if item.ID == subItem.ID {
  48. tempPatients_two = append(tempPatients_two[:index], tempPatients_two[index+1:]...)
  49. }
  50. }
  51. }
  52. tempPatients = append(tempPatients, tempPatients_two...)
  53. var total_one int64
  54. var total_two int64
  55. for _, item := range tempPatients {
  56. if item.VMHisPrescriptionInfo.ID == 0 {
  57. total_one = total_one + 1
  58. }
  59. if item.VMHisPrescriptionInfo.ID > 0 {
  60. total_two = total_two + 1
  61. }
  62. }
  63. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  64. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  65. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  66. if types == 0 {
  67. c.ServeSuccessJSON(map[string]interface{}{
  68. "list": tempPatients,
  69. "total_one": total_one,
  70. "total_two": total_two,
  71. "info": adminUserInfo,
  72. "doctors": doctors,
  73. "department": department,
  74. })
  75. } else if types == 1 { //未就诊
  76. var patientsOne []*service.HospitalPatient
  77. for _, item := range tempPatients {
  78. if item.VMHisPrescriptionInfo.ID == 0 {
  79. patientsOne = append(patientsOne, item)
  80. }
  81. }
  82. c.ServeSuccessJSON(map[string]interface{}{
  83. "list": patientsOne,
  84. "total_one": total_one,
  85. "total_two": total_two,
  86. "info": adminUserInfo,
  87. "doctors": doctors,
  88. "department": department,
  89. })
  90. } else if types == 2 { //已就诊
  91. var patientsTwo []*service.HospitalPatient
  92. for _, item := range tempPatients {
  93. if item.VMHisPrescriptionInfo.ID > 0 {
  94. patientsTwo = append(patientsTwo, item)
  95. }
  96. }
  97. c.ServeSuccessJSON(map[string]interface{}{
  98. "list": patientsTwo,
  99. "total_one": total_one,
  100. "total_two": total_two,
  101. "info": adminUserInfo,
  102. "doctors": doctors,
  103. "department": department,
  104. })
  105. }
  106. }
  107. func (c *HisHospitalApiController) GetHisHospitalChargePatientList() {
  108. record_date := c.GetString("record_date")
  109. timeLayout := "2006-01-02"
  110. loc, _ := time.LoadLocation("Local")
  111. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  112. if err != nil {
  113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  114. return
  115. }
  116. recordDateTime := theTime.Unix()
  117. adminInfo := c.GetAdminUserInfo()
  118. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  119. orders, _ := service.GetNewAllChargeHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime)
  120. tempPatients, _ := service.GetNewAllUnChargeHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime)
  121. var patients []*service.HospitalPatient
  122. for _, item := range tempPatients {
  123. fmt.Println(item.ID)
  124. if item.HisHospitalCheckRecord.ID > 0 && item.HisHospitalCheckRecord.InHospitalStatus == 1 &&
  125. item.HisHospitalCheckRecord.HisHospitalOrder.ID == 0 {
  126. patients = append(patients, item)
  127. }
  128. }
  129. c.ServeSuccessJSON(map[string]interface{}{
  130. "list": patients,
  131. "list_two": patients,
  132. "charge_list": orders,
  133. })
  134. }
  135. func (c *HisHospitalApiController) GetHisHospitalChargePatientInfo() {
  136. patient_id, _ := c.GetInt64("patient_id")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. record_date := c.GetString("record_date")
  139. start_time := c.GetString("start_time")
  140. end_time := c.GetString("end_time")
  141. order_status, _ := c.GetInt64("type", 0)
  142. p_type, _ := c.GetInt64("p_type", 0)
  143. timeLayout := "2006-01-02"
  144. loc, _ := time.LoadLocation("Local")
  145. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  146. if err != nil {
  147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  148. return
  149. }
  150. recordDateTime := theTime.Unix()
  151. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  152. if err != nil {
  153. }
  154. startRecordDateTime := startTime.Unix()
  155. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  156. if err != nil {
  157. }
  158. endRecordDateTime := endTime.Unix()
  159. admin := c.GetAdminUserInfo()
  160. his_patient_info, _ := service.GetNewHisHospitalPatientInfo(his_patient_id)
  161. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  162. var prescriptions []*models.HisPrescription
  163. if order_status == 1 || order_status == 0 {
  164. prescriptions, _ = service.GetUnChargeHisHospitalPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  165. } else if order_status == 2 {
  166. prescriptions, _ = service.GetChargeHisHospitalPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  167. }
  168. var monthPrescriptions []*models.HisPrescription
  169. if order_status == 1 || order_status == 0 {
  170. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  171. } else if order_status == 2 {
  172. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  173. }
  174. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  175. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  176. order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)
  177. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  178. //获取所有科室信息
  179. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  180. c.ServeSuccessJSON(map[string]interface{}{
  181. "his_info": his_patient_info,
  182. "xt_info": xt_patient_info,
  183. "prescription": prescriptions,
  184. "case_history": case_history,
  185. "info": patientPrescriptionInfo,
  186. "month_prescriptions": monthPrescriptions,
  187. "order": order,
  188. "doctors": doctors,
  189. "department": department,
  190. })
  191. return
  192. }
  193. func (c *HisHospitalApiController) GetHisHospitalrescriptionList() {
  194. record_date := c.GetString("record_date")
  195. keywords := c.GetString("keywords")
  196. page, _ := c.GetInt64("page")
  197. limit, _ := c.GetInt64("limit")
  198. timeLayout := "2006-01-02"
  199. loc, _ := time.LoadLocation("Local")
  200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  201. if err != nil {
  202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  203. return
  204. }
  205. recordDateTime := theTime.Unix()
  206. adminInfo := c.GetAdminUserInfo()
  207. prescriptionOrder, err, total := service.GetHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  208. //adminInfo := c.GetAdminUserInfo()
  209. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  210. //fmt.Println(prescriptionOrder)
  211. if err == nil {
  212. c.ServeSuccessJSON(map[string]interface{}{
  213. "order": prescriptionOrder,
  214. "total": total,
  215. })
  216. } else {
  217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  218. return
  219. }
  220. }
  221. func (c *HisHospitalApiController) GetHisHospitalPrescriptionList() {
  222. record_date := c.GetString("record_date")
  223. keywords := c.GetString("keywords")
  224. page, _ := c.GetInt64("page")
  225. limit, _ := c.GetInt64("limit")
  226. timeLayout := "2006-01-02"
  227. loc, _ := time.LoadLocation("Local")
  228. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  229. if err != nil {
  230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. recordDateTime := theTime.Unix()
  234. adminInfo := c.GetAdminUserInfo()
  235. prescriptionOrder, err, total := service.GetHisHospitalPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  236. if err == nil {
  237. c.ServeSuccessJSON(map[string]interface{}{
  238. "order": prescriptionOrder,
  239. "total": total,
  240. })
  241. } else {
  242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  243. return
  244. }
  245. }
  246. func (c *HisHospitalApiController) GetZHInHospitalCheck() {
  247. id, _ := c.GetInt64("id")
  248. record_time := c.GetString("record_time")
  249. name := c.GetString("name")
  250. phone := c.GetString("phone")
  251. id_card_type, _ := c.GetInt64("id_card_type")
  252. certificates, _ := c.GetInt64("certificates")
  253. id_card_no := c.GetString("id_card_no")
  254. doctor, _ := c.GetInt64("doctor")
  255. admin_user_id, _ := c.GetInt64("admin_user_id")
  256. department, _ := c.GetInt64("department")
  257. adm_bed, _ := c.GetInt64("adm_bed")
  258. diagnosis_ids := c.GetString("diagnosis")
  259. sick_type, _ := c.GetInt64("sick_type")
  260. start_time := c.GetString("start_time")
  261. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  262. med_type, _ := c.GetInt64("med_type")
  263. timeLayout := "2006-01-02"
  264. loc, _ := time.LoadLocation("Local")
  265. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  266. if err != nil {
  267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  268. return
  269. }
  270. recordDateTime := theTime.Unix()
  271. adminInfo := c.GetAdminUserInfo()
  272. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  273. if record.ID != 0 {
  274. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  276. return
  277. }
  278. }
  279. timestamp := time.Now().Unix()
  280. tempTime := time.Unix(timestamp, 0)
  281. timeFormat := tempTime.Format("20060102150405")
  282. chrgBchno := rand.Intn(100000) + 10000
  283. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  284. timeStr := time.Now().Format("2006-01-02 15:04:05")
  285. fmt.Println(timeStr)
  286. timeArr := strings.Split(timeStr, " ")
  287. fmt.Println(timeArr)
  288. timeArrTwo := strings.Split(timeArr[0], "-")
  289. timeArrThree := strings.Split(timeArr[1], ":")
  290. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(id, 10)
  291. inHospital := &models.HisHospitalCheckRecord{
  292. PatientId: id,
  293. Name: name,
  294. MedicalTreatmentType: med_type,
  295. RecordDate: recordDateTime,
  296. IdCardNo: id_card_no,
  297. AdminUserId: admin_user_id,
  298. Departments: department,
  299. UserOrgId: adminInfo.CurrentOrgId,
  300. Status: 1,
  301. Ctime: time.Now().Unix(),
  302. Mtime: time.Now().Unix(),
  303. Number: str,
  304. Doctor: doctor,
  305. Certno: id_card_no,
  306. MedType: med_type,
  307. IptOtpNo: ipt_otp_no,
  308. AdmBed: adm_bed,
  309. IdCardType: id_card_type,
  310. Diagnosis: diagnosis_ids,
  311. SickType: sick_type,
  312. MdtrtCertType: "02",
  313. InHosptialTime: start_time,
  314. OutHosptialTime: "",
  315. InHospitalStatus: 1,
  316. Certificates: certificates,
  317. Phone: phone,
  318. BalanceAccountsType: balance_accounts_type,
  319. }
  320. service.CreateHospitalRecord(inHospital)
  321. c.ServeSuccessJSON(map[string]interface{}{
  322. "msg": "办理入院成功",
  323. "info": inHospital,
  324. })
  325. }
  326. func (this *HisHospitalApiController) GetZHOutHospitalCheck() {
  327. id, _ := this.GetInt64("id")
  328. record, _ := service.GetInHospitalRecord(id)
  329. if record.ID == 0 {
  330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  331. return
  332. }
  333. timestamp := time.Now().Unix()
  334. tempTime := time.Unix(timestamp, 0)
  335. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  336. record.OutHospitalStatus = 1
  337. record.OutHosptialTime = timeFormatOne
  338. record.OutWay = 1
  339. service.CreateHospitalRecord(&record)
  340. this.ServeSuccessJSON(map[string]interface{}{
  341. "msg": "出院成功",
  342. })
  343. }
  344. func (c *HisHospitalApiController) GetSettleInfo() {
  345. id, _ := c.GetInt64("id")
  346. record_time := c.GetString("record_time")
  347. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  348. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  349. patient_id, _ := c.GetInt64("patient_id")
  350. pay_way, _ := c.GetInt64("pay_way")
  351. pay_price, _ := c.GetFloat("pay_price")
  352. pay_card_no := c.GetString("pay_card_no")
  353. discount_price, _ := c.GetFloat("discount_price")
  354. preferential_price, _ := c.GetFloat("preferential_price")
  355. reality_price, _ := c.GetFloat("reality_price")
  356. found_price, _ := c.GetFloat("found_price")
  357. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  358. private_price, _ := c.GetFloat("private_price")
  359. fapiao_code := c.GetString("fapiao_code")
  360. fapiao_number := c.GetString("fapiao_number")
  361. timeLayout := "2006-01-02"
  362. loc, _ := time.LoadLocation("Local")
  363. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  364. if err != nil {
  365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  366. return
  367. }
  368. recordDateTime := theTime.Unix()
  369. adminUser := c.GetAdminUserInfo()
  370. var prescriptions []*models.HisPrescription
  371. var start_time int64
  372. var end_time int64
  373. if settle_accounts_type == 1 { //日结
  374. //prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  375. } else { //月结
  376. start_time_str := c.GetString("start_time")
  377. end_time_str := c.GetString("end_time")
  378. timeLayout := "2006-01-02"
  379. loc, _ := time.LoadLocation("Local")
  380. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  381. if err != nil {
  382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  383. return
  384. }
  385. recordStartTime := theStartTime.Unix()
  386. start_time = recordStartTime
  387. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  388. if err != nil {
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  390. return
  391. }
  392. recordEndTime := theEndTime.Unix()
  393. end_time = recordEndTime
  394. prescriptions, _ = service.GetHospitalMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  395. }
  396. record, _ := service.GetInHospitalRecord(in_hospital_id)
  397. if record.ID == 0 {
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  399. return
  400. }
  401. timestamp := time.Now().Unix()
  402. tempTime := time.Unix(timestamp, 0)
  403. timeFormat := tempTime.Format("20060102150405")
  404. chrgBchno := rand.Intn(100000) + 10000
  405. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  406. var ids []int64
  407. fmt.Println(prescriptions)
  408. for _, item := range prescriptions {
  409. ids = append(ids, item.ID)
  410. }
  411. var total float64
  412. fmt.Println(prescriptions)
  413. for _, item := range prescriptions {
  414. fmt.Println(item)
  415. if item.Type == 1 { //药品
  416. for _, subItem := range item.HisDoctorAdviceInfo {
  417. total = total + (subItem.Price * subItem.PrescribingNumber)
  418. }
  419. }
  420. if item.Type == 2 { //项目
  421. for _, subItem := range item.HisPrescriptionProject {
  422. total = total + (subItem.Price * float64(subItem.Count))
  423. }
  424. }
  425. for _, subItem := range item.HisAdditionalCharge {
  426. total = total + (subItem.Price * float64(subItem.Count))
  427. }
  428. }
  429. allTotal := fmt.Sprintf("%.2f", total)
  430. totals, _ := strconv.ParseFloat(allTotal, 64)
  431. order := &models.HisOrder{
  432. UserOrgId: adminUser.CurrentOrgId,
  433. HisPatientId: record.ID,
  434. PatientId: patient_id,
  435. SettleAccountsDate: recordDateTime,
  436. Ctime: time.Now().Unix(),
  437. Mtime: time.Now().Unix(),
  438. Status: 1,
  439. OrderStatus: 2,
  440. MdtrtId: record.Number,
  441. Number: chrg_bchno,
  442. MedfeeSumamt: totals,
  443. SettleEndTime: end_time,
  444. SettleStartTime: start_time,
  445. SettleType: settle_accounts_type,
  446. PType: 1,
  447. Creator: c.GetAdminUserInfo().AdminUser.Id,
  448. }
  449. order.DiscountPrice = discount_price
  450. order.MedicalInsurancePrice = medical_insurance_price
  451. order.FaPiaoNumber = fapiao_number
  452. order.FaPiaoCode = fapiao_code
  453. order.PayWay = pay_way
  454. order.PayPrice = pay_price
  455. order.PayCardNo = pay_card_no
  456. order.PreferentialPrice = preferential_price
  457. order.RealityPrice = reality_price
  458. order.FoundPrice = found_price
  459. order.PrivatePrice = private_price
  460. err = service.CreateOrder(order)
  461. if err != nil {
  462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  463. return
  464. }
  465. var customs []*Custom
  466. for _, item := range prescriptions {
  467. if item.Type == 1 { //药品
  468. for _, subItem := range item.HisDoctorAdviceInfo {
  469. cus := &Custom{
  470. AdviceId: subItem.ID,
  471. ProjectId: 0,
  472. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  473. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  474. FeedetlSn: subItem.FeedetlSn,
  475. Price: fmt.Sprintf("%.2f", subItem.Price),
  476. MedListCodg: subItem.MedListCodg,
  477. Type: 1,
  478. }
  479. customs = append(customs, cus)
  480. }
  481. }
  482. if item.Type == 2 { //项目
  483. for _, subItem := range item.HisPrescriptionProject {
  484. cus := &Custom{
  485. AdviceId: 0,
  486. ProjectId: subItem.ID,
  487. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  488. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  489. FeedetlSn: subItem.FeedetlSn,
  490. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  491. MedListCodg: subItem.MedListCodg,
  492. Type: 2,
  493. }
  494. customs = append(customs, cus)
  495. }
  496. }
  497. for _, item := range item.HisAdditionalCharge {
  498. cus := &Custom{
  499. ItemId: item.ID,
  500. AdviceId: 0,
  501. ProjectId: 0,
  502. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  503. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  504. FeedetlSn: item.FeedetlSn,
  505. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  506. MedListCodg: item.XtHisAddtionConfig.Code,
  507. Type: 3,
  508. }
  509. customs = append(customs, cus)
  510. }
  511. }
  512. for _, item := range customs {
  513. var advice_id int64 = 0
  514. var project_id int64 = 0
  515. var item_id int64 = 0
  516. var types int64 = 0
  517. if item.Type == 1 {
  518. advice_id = item.AdviceId
  519. project_id = 0
  520. item_id = 0
  521. } else if item.Type == 2 {
  522. advice_id = 0
  523. item_id = 0
  524. project_id = item.ProjectId
  525. } else if item.Type == 3 {
  526. advice_id = 0
  527. item_id = item.ItemId
  528. project_id = 0
  529. }
  530. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  531. cut, _ := strconv.ParseFloat(item.Cut, 32)
  532. pric, _ := strconv.ParseFloat(item.Price, 32)
  533. info := &models.HisOrderInfo{
  534. OrderNumber: order.Number,
  535. UploadDate: time.Now().Unix(),
  536. AdviceId: advice_id,
  537. DetItemFeeSumamt: detItemFeeSumamt,
  538. Cnt: cut,
  539. Pric: pric,
  540. PatientId: id,
  541. Status: 1,
  542. Mtime: time.Now().Unix(),
  543. Ctime: time.Now().Unix(),
  544. UserOrgId: adminUser.CurrentOrgId,
  545. HisPatientId: record.ID,
  546. OrderId: order.ID,
  547. ProjectId: project_id,
  548. Type: types,
  549. ItemId: item_id,
  550. }
  551. service.CreateOrderInfo(info)
  552. }
  553. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  554. err = service.UpDateHospitalHisPrescriptionInfoNumber(adminUser.CurrentOrgId, chrg_bchno, start_time, end_time)
  555. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  556. if err == nil {
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "msg": "结算成功",
  559. })
  560. }
  561. }
  562. func (c *HisHospitalApiController) ZHRefund() {
  563. order_id, _ := c.GetInt64("order_id")
  564. adminUser := c.GetAdminUserInfo()
  565. var order models.HisOrder
  566. order, _ = service.GetHisOrderByID(order_id)
  567. err := service.UpdataHospitalOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  568. if err == nil {
  569. c.ServeSuccessJSON(map[string]interface{}{
  570. "msg": "退费成功",
  571. })
  572. } else {
  573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  574. return
  575. }
  576. }
  577. func (this *HisHospitalApiController) GetZHOutHospitalUnCheck() {
  578. id, _ := this.GetInt64("id")
  579. record, _ := service.GetInHospitalRecord(id)
  580. if record.ID == 0 {
  581. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  582. return
  583. }
  584. record.OutHospitalStatus = 0
  585. service.CreateHospitalRecord(&record)
  586. this.ServeSuccessJSON(map[string]interface{}{
  587. "msg": "撤销出院成功",
  588. })
  589. }
  590. func (this *HisHospitalApiController) GetZHInHospitalUnCheck() {
  591. id, _ := this.GetInt64("id")
  592. record, _ := service.GetInHospitalRecord(id)
  593. if record.ID == 0 {
  594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  595. return
  596. }
  597. record.Status = 0
  598. service.CreateHospitalRecord(&record)
  599. this.ServeSuccessJSON(map[string]interface{}{
  600. "msg": "撤销入院成功",
  601. })
  602. }