package service import ( "context" "log/slog" "time" ) import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/protobuf/types/known/emptypb" ) import ( "auth-server/common" "auth-server/logger" pb "auth-server/rpc_idl/dr_protocol_pb" ) var ProtocolClient *Protocol func init() { ProtocolClient = new(Protocol) } type Protocol struct { basicClient pb.BasicClient protocolClient pb.ProtocolClient aprClient pb.AprClient } func (s *Protocol) Setup() { conn, err := grpc.NewClient(common.ServerConfig.Protocol, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUnaryInterceptor(logger.GRPCLoggerClientInterceptor(logger.WithGroup("grpc_c[protocol]"))), ) if err != nil { slog.Error("NewClient failed", "err", err) panic(err) } slog.Info("protocol conn success", "conn", conn.GetState()) s.basicClient = pb.NewBasicClient(conn) s.protocolClient = pb.NewProtocolClient(conn) s.aprClient = pb.NewAprClient(conn) } func (s *Protocol) GetSoftwareInfo() *pb.SoftwareInfoReply { ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) defer cancel() r, err := s.basicClient.SoftwareInfo(ctx, &emptypb.Empty{}) if err != nil { return &pb.SoftwareInfoReply{ Module: "", Desc: "", Build: "", Version: "", } } return r } func (s *Protocol) GetPatientTypeList(ctx context.Context, isEnabled *bool) (*pb.PatientTypeReply, error) { r, err := s.protocolClient.GetPatientTypeList(ctx, &pb.PatientTypeRequest{ IsEnabled: isEnabled, }) return r, err } func (s *Protocol) GetBodyPartList(ctx context.Context, patientType *string, modality *string, isEnabled *bool) (*pb.BodyPartReply, error) { r, err := s.protocolClient.GetBodyPartList(ctx, &pb.BodyPartRequest{ PatientType: patientType, Modality: modality, IsEnabled: isEnabled, }) return r, err } func (s *Protocol) GetProcedureList(ctx context.Context, patientType *string, bodyPart *string, isEnabled *bool) (*pb.ProcedureReply, error) { r, err := s.protocolClient.GetProcedureList(ctx, &pb.ProcedureRequest{ PatientType: patientType, BodyPartId: bodyPart, IsEnabled: isEnabled, }) return r, err } func (s *Protocol) GetViewList(ctx context.Context, patientType *string, bodyPart *string, procedureID *string, isEnabled *bool) (*pb.ViewReply, error) { r, err := s.protocolClient.GetViewList(ctx, &pb.ViewRequest{ PatientType: patientType, BodyPartId: bodyPart, ProcedureId: procedureID, IsEnabled: isEnabled, }) return r, err } func (s *Protocol) GetView(ctx context.Context, id *string) (*pb.View, error) { r, err := s.protocolClient.GetView(ctx, &pb.IDRequest{ InstanceId: id, }) return r, err } func (s *Protocol) GetApr(ctx context.Context, viewID *string, aprID *string, isEnabled *bool) (*pb.AprReply, error) { r, err := s.aprClient.GetApr(ctx, &pb.AprRequest{ ViewId: viewID, AprId: aprID, IsEnabled: isEnabled, }) return r, err }