his_print_api_controller.go 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "github.com/astaxie/beego"
  7. "strings"
  8. "time"
  9. )
  10. type HisPrintApiController struct {
  11. BaseAuthAPIController
  12. }
  13. func HisPrintApiRegistRouters() {
  14. beego.Router("/api/his/prescription/print", &HisPrintApiController{}, "get:GetBatchHisPrescriptionData")
  15. beego.Router("/api/his/prescription/list", &HisPrintApiController{}, "get:GetUnChargePrescriptionList")
  16. beego.Router("/api/his/prescription/summary", &HisPrintApiController{}, "get:GetUnChargePrescriptionSummary")
  17. beego.Router("/api/his/label/create", &HisPrintApiController{}, "get:CreateLablePrint")
  18. beego.Router("/api/his/label/get", &HisPrintApiController{}, "get:GetLablePrint")
  19. }
  20. func (c *HisPrintApiController) GetLablePrint() {
  21. patient_id, _ := c.GetInt64("patient_id")
  22. ids := c.GetString("ids")
  23. record_date := c.GetString("record_date")
  24. labels, _ := service.GetLabelPrint(ids, c.GetAdminUserInfo().CurrentOrgId, record_date, patient_id)
  25. c.ServeSuccessJSON(map[string]interface{}{
  26. "labels": labels,
  27. })
  28. return
  29. }
  30. func (c *HisPrintApiController) CreateLablePrint() {
  31. patient_id, _ := c.GetInt64("patient_id")
  32. isCombinationPrint, _ := c.GetBool("is_combination_print")
  33. team_ids := c.GetString("team_ids")
  34. ids := c.GetString("ids")
  35. record_date := c.GetString("record_date")
  36. doctor_id, _ := c.GetInt64("doctor_id")
  37. project_ids := c.GetString("project_ids")
  38. is_team, _ := c.GetInt64("is_team")
  39. var hlpsi models.HisLabelPrintStatusInfo
  40. hlpsi.Status = 1
  41. hlpsi.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  42. hlpsi.PatientId = patient_id
  43. hlpsi.RecordDate = record_date
  44. hlpsi.Mtime = time.Now().Unix()
  45. hlpsi.Ctime = time.Now().Unix()
  46. hlpsi.ItemIds = team_ids
  47. hlpsi.ProjectIds = project_ids
  48. hlpsi.Ids = ids
  49. hlpsi.DoctorId = doctor_id
  50. hlpsi.IsTeam = is_team
  51. hlpsi.IsPrint = 1
  52. if isCombinationPrint == true {
  53. hlpsi.IsCombinationPrint = 1
  54. } else {
  55. hlpsi.IsCombinationPrint = 0
  56. }
  57. service.CreateLabelPrint(&hlpsi)
  58. c.ServeSuccessJSON(map[string]interface{}{
  59. "msg": "保存成功",
  60. "hlpsi": hlpsi,
  61. })
  62. return
  63. }
  64. func (c *HisPrintApiController) GetUnChargePrescriptionList() {
  65. patient_id, _ := c.GetInt64("patient_id")
  66. recordDateTime, _ := c.GetInt64("record_date")
  67. admin_user_id, _ := c.GetInt64("admin_user_id")
  68. p_type, _ := c.GetInt64("p_type", 0)
  69. admin := c.GetAdminUserInfo()
  70. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  71. record, _ := service.GetLastInHospitalRecord(patient_id, c.GetAdminUserInfo().CurrentOrgId)
  72. var prescriptions []*models.HisPrescription
  73. prescriptions, _ = service.GetUnChargeHisPrescriptionTen(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  74. admin_info, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
  75. //获取所有科室信息
  76. c.ServeSuccessJSON(map[string]interface{}{
  77. "xt_info": xt_patient_info,
  78. "prescription": prescriptions,
  79. "record": record,
  80. "admin_info": admin_info,
  81. })
  82. return
  83. }
  84. func (c *HisPrintApiController) GetUnChargePrescriptionSummary() {
  85. patient_id, _ := c.GetInt64("patient_id")
  86. record_date, _ := c.GetInt64("record_date")
  87. admin_user_id, _ := c.GetInt64("admin_user_id")
  88. p_type, _ := c.GetInt64("p_type", 0)
  89. //timeLayout := "2006-01-02"
  90. //loc, _ := time.LoadLocation("Local")
  91. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  92. //if err != nil {
  93. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. // return
  95. //}
  96. //recordDateTime := theTime.Unix()
  97. admin := c.GetAdminUserInfo()
  98. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  99. record, _ := service.GetLastInHospitalRecord(patient_id, c.GetAdminUserInfo().CurrentOrgId)
  100. var prescriptions []*models.HisPrescription
  101. prescriptions, _ = service.GetUnChargeHisPrescriptionTen(admin.CurrentOrgId, patient_id, record_date, p_type)
  102. //doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  103. service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
  104. //获取所有科室信息
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "xt_info": xt_patient_info,
  107. "prescription": prescriptions,
  108. "record": record,
  109. "admin_info": admin_user_id,
  110. })
  111. return
  112. }
  113. func (c *HisPrintApiController) GetBatchHisPrescriptionData() {
  114. record_date := c.GetString("record_date")
  115. patient_ids := c.GetString("patient_ids")
  116. print_type, _ := c.GetInt64("type")
  117. timeLayout := "2006-01-02"
  118. loc, _ := time.LoadLocation("Local")
  119. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  120. if err != nil {
  121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  122. return
  123. }
  124. recordDateTime := theTime.Unix()
  125. adminInfo := c.GetAdminUserInfo()
  126. ids := strings.Split(patient_ids, ",")
  127. switch print_type {
  128. case 1:
  129. patients, _ := service.GetBatchDrugHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
  130. c.ServeSuccessJSON(map[string]interface{}{
  131. "patients": patients,
  132. })
  133. break
  134. case 2:
  135. //var newPatients []*models.PrintPatient
  136. patients, _ := service.GetBatchProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
  137. //for _, item := range patients {
  138. // for _, subItem := range item.HisPrintPrescription {
  139. // for _, subItemTwo := range subItem.HisPrescriptionProject {
  140. // if subItemTwo.HisProject.CostClassify != 3 {
  141. //
  142. // }
  143. // }
  144. // }
  145. //}
  146. c.ServeSuccessJSON(map[string]interface{}{
  147. "patients": patients,
  148. })
  149. break
  150. case 3:
  151. var newPatients []*models.PrintPatient
  152. var newPatientsTwo []*models.PrintPatient
  153. patients, _ := service.GetBatchInspectionProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
  154. for _, item := range patients {
  155. var newPatient *models.PrintPatient
  156. newPatient = item
  157. for index, subItem := range item.HisPrintPrescription {
  158. if index > 0 {
  159. item.HisPrintPrescription[0].HisPrescriptionProject = append(item.HisPrintPrescription[0].HisPrescriptionProject, subItem.HisPrescriptionProject...)
  160. }
  161. }
  162. newPatients = append(newPatients, newPatient)
  163. }
  164. for _, item := range patients {
  165. var newPatient *models.PrintPatient
  166. newPatient = item
  167. if len(item.HisPrintPrescription) > 0 {
  168. newPatient.NewHisPrintPrescription = append(newPatient.NewHisPrintPrescription, item.HisPrintPrescription[0])
  169. newPatientsTwo = append(newPatientsTwo, newPatient)
  170. }
  171. }
  172. c.ServeSuccessJSON(map[string]interface{}{
  173. "patients": newPatientsTwo,
  174. })
  175. break
  176. }
  177. }