pb_protocol_client.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package service
  2. import (
  3. "context"
  4. "log/slog"
  5. "time"
  6. )
  7. import (
  8. "google.golang.org/grpc"
  9. "google.golang.org/grpc/credentials/insecure"
  10. "google.golang.org/protobuf/types/known/emptypb"
  11. )
  12. import (
  13. "auth-server/common"
  14. "auth-server/logger"
  15. pb "auth-server/rpc_idl/dr_protocol_pb"
  16. )
  17. var ProtocolClient *Protocol
  18. func init() {
  19. ProtocolClient = new(Protocol)
  20. }
  21. type Protocol struct {
  22. basicClient pb.BasicClient
  23. protocolClient pb.ProtocolClient
  24. aprClient pb.AprClient
  25. }
  26. func (s *Protocol) Setup() {
  27. conn, err := grpc.NewClient(common.ServerConfig.Protocol,
  28. grpc.WithTransportCredentials(insecure.NewCredentials()),
  29. grpc.WithUnaryInterceptor(logger.GRPCLoggerClientInterceptor(logger.WithGroup("grpc_c[protocol]"))),
  30. )
  31. if err != nil {
  32. slog.Error("NewClient failed", "err", err)
  33. panic(err)
  34. }
  35. slog.Info("protocol conn success", "conn", conn.GetState())
  36. s.basicClient = pb.NewBasicClient(conn)
  37. s.protocolClient = pb.NewProtocolClient(conn)
  38. s.aprClient = pb.NewAprClient(conn)
  39. }
  40. func (s *Protocol) GetSoftwareInfo() *pb.SoftwareInfoReply {
  41. ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
  42. defer cancel()
  43. r, err := s.basicClient.SoftwareInfo(ctx, &emptypb.Empty{})
  44. if err != nil {
  45. return &pb.SoftwareInfoReply{
  46. Module: "",
  47. Desc: "",
  48. Build: "",
  49. Version: "",
  50. }
  51. }
  52. return r
  53. }
  54. func (s *Protocol) GetPatientTypeList(ctx context.Context, isEnabled *bool) (*pb.PatientTypeReply, error) {
  55. r, err := s.protocolClient.GetPatientTypeList(ctx, &pb.PatientTypeRequest{
  56. IsEnabled: isEnabled,
  57. })
  58. return r, err
  59. }
  60. func (s *Protocol) GetBodyPartList(ctx context.Context, patientType *string, modality *string, isEnabled *bool) (*pb.BodyPartReply, error) {
  61. r, err := s.protocolClient.GetBodyPartList(ctx, &pb.BodyPartRequest{
  62. PatientType: patientType,
  63. Modality: modality,
  64. IsEnabled: isEnabled,
  65. })
  66. return r, err
  67. }
  68. func (s *Protocol) GetProcedureList(ctx context.Context, patientType *string, bodyPart *string, isEnabled *bool) (*pb.ProcedureReply, error) {
  69. r, err := s.protocolClient.GetProcedureList(ctx, &pb.ProcedureRequest{
  70. PatientType: patientType,
  71. BodyPartId: bodyPart,
  72. IsEnabled: isEnabled,
  73. })
  74. return r, err
  75. }
  76. func (s *Protocol) GetViewList(ctx context.Context, patientType *string, bodyPart *string, procedureID *string, isEnabled *bool) (*pb.ViewReply, error) {
  77. r, err := s.protocolClient.GetViewList(ctx, &pb.ViewRequest{
  78. PatientType: patientType,
  79. BodyPartId: bodyPart,
  80. ProcedureId: procedureID,
  81. IsEnabled: isEnabled,
  82. })
  83. return r, err
  84. }
  85. func (s *Protocol) GetView(ctx context.Context, id *string) (*pb.View, error) {
  86. r, err := s.protocolClient.GetView(ctx, &pb.IDRequest{
  87. InstanceId: id,
  88. })
  89. return r, err
  90. }
  91. func (s *Protocol) GetApr(ctx context.Context, viewID *string, aprID *string, isEnabled *bool) (*pb.AprReply, error) {
  92. r, err := s.aprClient.GetApr(ctx, &pb.AprRequest{
  93. ViewId: viewID,
  94. AprId: aprID,
  95. IsEnabled: isEnabled,
  96. })
  97. return r, err
  98. }