config.go 6.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package service
  2. import (
  3. "context"
  4. "resource-server/common"
  5. )
  6. import (
  7. "google.golang.org/grpc/codes"
  8. "google.golang.org/grpc/status"
  9. )
  10. import (
  11. pb "resource-server/rpc_idl/dr_resource_pb"
  12. )
  13. type ConfigServer struct {
  14. pb.UnimplementedConfigServer
  15. }
  16. func (s *ConfigServer) ConfigOptionList(ctx context.Context, in *pb.ConfigOptionListRequest) (*pb.ConfigOptionListReply, error) {
  17. product, _, _ := common.GetHeader(ctx)
  18. res := pb.ConfigOptionListReply{}
  19. switch in.GetFlag() {
  20. case "TimeFormat":
  21. //res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{})
  22. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HH:mm:ss", Value: "HH:mm:ss", Order: 1, IsEnabled: true})
  23. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HH:mm", Value: "HH:mm", Order: 2, IsEnabled: true})
  24. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HH-mm-ss", Value: "HH-mm-ss", Order: 3, IsEnabled: true})
  25. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HHmmss", Value: "HHmmss", Order: 4, IsEnabled: true})
  26. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "hh:mm:ss tt", Value: "hh:mm:ss tt", Order: 5, IsEnabled: true})
  27. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "h:mm:ss tt", Value: "h:mm:ss tt", Order: 6, IsEnabled: true})
  28. case "DateFormat":
  29. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy.MM.dd", Value: "yyyy.MM.dd", Order: 1, IsEnabled: true})
  30. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy/M/d", Value: "yyyy/M/d", Order: 2, IsEnabled: true})
  31. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "M-d-yyyy", Value: "M-d-yyyy", Order: 3, IsEnabled: true})
  32. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy/M/dd", Value: "yyyy/M/dd", Order: 4, IsEnabled: true})
  33. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy-MM-dd", Value: "yyyy-MM-dd", Order: 5, IsEnabled: true})
  34. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "M-dd-yyyy", Value: "M-dd-yyyy", Order: 6, IsEnabled: true})
  35. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy.M.dd", Value: "yyyy.M.dd", Order: 7, IsEnabled: true})
  36. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy/MM/dd", Value: "yyyy/MM/dd", Order: 8, IsEnabled: true})
  37. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "MMM-dd-yyyy", Value: "MMM-dd-yyyy", Order: 9, IsEnabled: true})
  38. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy-MMM-dd", Value: "yyyy-MMM-dd", Order: 10, IsEnabled: true})
  39. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "dd-MMM-yyyy", Value: "dd-MMM-yyyy", Order: 11, IsEnabled: true})
  40. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "dd.MM.yyyy", Value: "dd.MM.yyyy", Order: 12, IsEnabled: true})
  41. case "DoseUnit":
  42. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DoseUnit", Text: "rad", Value: "rad", Order: 1, IsEnabled: true})
  43. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DoseUnit", Text: "mGy", Value: "mGy", Order: 2, IsEnabled: true})
  44. case "WeightUnit":
  45. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "WeightUnit", Text: "kg", Value: "kg", Order: 1, IsEnabled: true})
  46. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "WeightUnit", Text: "pound", Value: "pound", Order: 2, IsEnabled: true})
  47. case "LengthUnit":
  48. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "LengthUnit", Text: "cm", Value: "cm", Order: 1, IsEnabled: true})
  49. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "LengthUnit", Text: "inch", Value: "inch", Order: 2, IsEnabled: true})
  50. case "FontFamily":
  51. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "FontFamily", Text: "Arial Unicode MS", Value: "Arial Unicode MS", Order: 1, IsEnabled: true})
  52. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "FontFamily", Text: "Arial", Value: "Arial", Order: 2, IsEnabled: true})
  53. case "MWL_Modality":
  54. if product == common.PRODUCT_VET {
  55. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "RF", Value: "RF", Order: 1, IsEnabled: true})
  56. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "DX", Value: "DX", Order: 2, IsEnabled: true})
  57. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "XA", Value: "XA", Order: 3, IsEnabled: true})
  58. } else if product == common.PRODUCT_DROC {
  59. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "DX", Value: "DX", Order: 1, IsEnabled: true})
  60. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "CR", Value: "CR", Order: 2, IsEnabled: true})
  61. }
  62. default:
  63. return &res, status.Errorf(codes.NotFound, "flag %s not found", in.GetFlag())
  64. }
  65. return &res, nil
  66. }
  67. func (s *ConfigServer) ConfigList(ctx context.Context, in *pb.ConfigListRequest) (*pb.ConfigListResponse, error) {
  68. return nil, status.Errorf(codes.Unimplemented, "method ConfigList not implemented")
  69. }
  70. //func GetConfigList() ([]*dto.ConfigResp, error) {
  71. // res := []*dto.ConfigResp{}
  72. // var items []*models.ConfigItem
  73. // query := models.DB.Model(&models.ConfigItem{})
  74. // err := query.Order("id").Find(&items).Error
  75. // if err != nil {
  76. // return res, err
  77. // }
  78. // for _, c := range items {
  79. // res = append(res, &dto.ConfigResp{
  80. // Key: c.Key,
  81. // Value: c.Value,
  82. // OptionKey: c.OptionKey,
  83. // ValueType: c.ValueType,
  84. // Description: c.Description,
  85. // Order: c.Order,
  86. // IsEnabled: c.IsEnabled,
  87. // Uri: c.Uri,
  88. // })
  89. // }
  90. // return res, nil
  91. //}