prescription.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package model
  2. import (
  3. "strconv"
  4. "strings"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type Prescription struct {
  8. Id int32 `json:"id"`
  9. Name string `json:"name"`
  10. ApplicableDisease string `json:"applicable_disease"`
  11. UseDays int32 `json:"use_days"`
  12. UseCount int32 `json:"use_count"`
  13. MeatExpiredDays int32 `json:"meat_expired_days"`
  14. MilkExpiredDays int32 `json:"milk_expired_days"`
  15. IsShow pasturePb.IsShow_Kind `json:"is_show"`
  16. Remarks string `json:"remarks"`
  17. OperationId int64 `json:"operation_id"`
  18. OperationName string `json:"operation_name"`
  19. CreatedAt int64 `json:"created_at"`
  20. UpdatedAt int64 `json:"updated_at"`
  21. }
  22. func (p *Prescription) TableName() string {
  23. return "prescription"
  24. }
  25. func NewPrescription(req *pasturePb.PrescriptionRequest, applicableDisease string, useDays,
  26. meatExpiredDays, milkExpiredDays int32, systemUser *SystemUser) *Prescription {
  27. return &Prescription{
  28. Name: req.Name,
  29. ApplicableDisease: applicableDisease,
  30. UseDays: useDays,
  31. UseCount: 0,
  32. MeatExpiredDays: meatExpiredDays,
  33. MilkExpiredDays: milkExpiredDays,
  34. IsShow: req.IsShow,
  35. Remarks: req.Remarks,
  36. OperationId: systemUser.Id,
  37. OperationName: systemUser.Name,
  38. }
  39. }
  40. type PrescriptionSlice []*Prescription
  41. func (p PrescriptionSlice) ToPB(prescriptionDrugsList []*PrescriptionDrugs, diseaseMap map[int64]*Disease) []*pasturePb.SearchPrescriptionList {
  42. res := make([]*pasturePb.SearchPrescriptionList, len(p))
  43. for i, v := range p {
  44. drugsList := make([]*pasturePb.PrescriptionDrugsList, 0)
  45. for _, pl := range prescriptionDrugsList {
  46. if pl.PrescriptionId != v.Id {
  47. continue
  48. }
  49. drugsList = append(drugsList, &pasturePb.PrescriptionDrugsList{
  50. Id: pl.Id,
  51. DrugsId: int32(pl.DrugsId),
  52. DrugsName: pl.DrugsName,
  53. Unit: pl.Unit,
  54. UnitName: pl.UnitName,
  55. Dosages: pl.Dosages,
  56. UseDays: pl.UseDays,
  57. Specs: pl.Specs,
  58. })
  59. }
  60. applicableDiseaseList := strings.Split(v.ApplicableDisease, ",")
  61. applicableDiseaseNames := make([]string, 0)
  62. applicableDiseaseIds := make([]int32, 0)
  63. for _, ad := range applicableDiseaseList {
  64. diseaseId, _ := strconv.ParseInt(ad, 10, 64)
  65. applicableDiseaseIds = append(applicableDiseaseIds, int32(diseaseId))
  66. if dis, ok := diseaseMap[diseaseId]; ok {
  67. applicableDiseaseNames = append(applicableDiseaseNames, dis.Name)
  68. }
  69. }
  70. res[i] = &pasturePb.SearchPrescriptionList{
  71. Id: int32(v.Id),
  72. Name: v.Name,
  73. ApplicableDisease: v.ApplicableDisease,
  74. ApplicableDiseaseIds: applicableDiseaseIds,
  75. ApplicableDiseaseNames: applicableDiseaseNames,
  76. UseDays: v.UseDays,
  77. UseCount: v.UseCount,
  78. MeatExpiredDays: v.MeatExpiredDays,
  79. MilkExpiredDays: v.MilkExpiredDays,
  80. IsShow: v.IsShow,
  81. Remarks: v.Remarks,
  82. OperationId: int32(v.OperationId),
  83. OperationName: v.OperationName,
  84. CreatedAt: int32(v.CreatedAt),
  85. UpdatedAt: int32(v.UpdatedAt),
  86. DrugsList: drugsList,
  87. }
  88. }
  89. return res
  90. }
  91. func (p PrescriptionSlice) ToPB2() []*pasturePb.ConfigOptionsList {
  92. res := make([]*pasturePb.ConfigOptionsList, len(p))
  93. for i, d := range p {
  94. res[i] = &pasturePb.ConfigOptionsList{
  95. Value: int32(d.Id),
  96. Label: d.Name,
  97. Disabled: true,
  98. }
  99. }
  100. return res
  101. }