his_hospital_api_controller.go 22KB

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