his_hospital_api_controller.go 27KB

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