his_hospital_api_controller.go 22KB

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