his_print_api_controller.go 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. }
  16. func (c *HisPrintApiController) GetBatchHisPrescriptionData() {
  17. record_date := c.GetString("record_date")
  18. patient_ids := c.GetString("patient_ids")
  19. print_type, _ := c.GetInt64("type")
  20. timeLayout := "2006-01-02"
  21. loc, _ := time.LoadLocation("Local")
  22. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  23. if err != nil {
  24. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  25. return
  26. }
  27. recordDateTime := theTime.Unix()
  28. adminInfo := c.GetAdminUserInfo()
  29. ids := strings.Split(patient_ids, ",")
  30. switch print_type {
  31. case 1:
  32. patients, _ := service.GetBatchDrugHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
  33. c.ServeSuccessJSON(map[string]interface{}{
  34. "patients": patients,
  35. })
  36. break
  37. case 2:
  38. //var newPatients []*models.PrintPatient
  39. patients, _ := service.GetBatchProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
  40. //for _, item := range patients {
  41. // for _, subItem := range item.HisPrintPrescription {
  42. // for _, subItemTwo := range subItem.HisPrescriptionProject {
  43. // if subItemTwo.HisProject.CostClassify != 3 {
  44. //
  45. // }
  46. // }
  47. // }
  48. //}
  49. c.ServeSuccessJSON(map[string]interface{}{
  50. "patients": patients,
  51. })
  52. break
  53. case 3:
  54. var newPatients []*models.PrintPatient
  55. var newPatientsTwo []*models.PrintPatient
  56. patients, _ := service.GetBatchInspectionProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
  57. for _, item := range patients {
  58. var newPatient *models.PrintPatient
  59. newPatient = item
  60. for index, subItem := range item.HisPrintPrescription {
  61. if index > 0 {
  62. item.HisPrintPrescription[0].HisPrescriptionProject = append(item.HisPrintPrescription[0].HisPrescriptionProject, subItem.HisPrescriptionProject...)
  63. }
  64. }
  65. newPatients = append(newPatients, newPatient)
  66. }
  67. for _, item := range patients {
  68. var newPatient *models.PrintPatient
  69. newPatient = item
  70. if len(item.HisPrintPrescription) > 0 {
  71. newPatient.NewHisPrintPrescription = append(newPatient.NewHisPrintPrescription, item.HisPrintPrescription[0])
  72. newPatientsTwo = append(newPatientsTwo, newPatient)
  73. }
  74. }
  75. c.ServeSuccessJSON(map[string]interface{}{
  76. "patients": newPatientsTwo,
  77. })
  78. break
  79. }
  80. }