his_hospital_api_controller.go 28KB

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