his_hospital_api_controller.go 26KB

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