package service import ( "context" "log/slog" ) import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) import ( "auth-server/common" pb "auth-server/rpc_idl/dr_protocol_pb" ) var ProtocolService *Protocol func init() { ProtocolService = new(Protocol) } type Protocol struct { basicClient pb.BasicClient protocolClient pb.ProtocolClient } func (s *Protocol) Setup() { conn, err := grpc.NewClient(common.ServerConfig.Protocol, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { slog.Error("NewClient failed:", err) panic(err) } slog.Info("protocol conn success", "conn", conn.GetState()) s.basicClient = pb.NewBasicClient(conn) s.protocolClient = pb.NewProtocolClient(conn) } func (s *Protocol) GetSoftwareInfo() *pb.SoftwareInfoReply { slog.Info("[rpc]SoftwareInfo...") r, err := s.basicClient.SoftwareInfo(context.Background(), &pb.EmptyRequest{}) if err != nil { slog.Error("[rpc]SoftwareInfo failed:", err) return &pb.SoftwareInfoReply{ Module: "", Desc: "", Build: "", Version: "", } } return r } func (s *Protocol) GetPatientType(ctx context.Context, isEnabled *bool) (*pb.PatientTypeReply, error) { slog.Info("[rpc]GetPatientType...") r, err := s.protocolClient.GetPatientType(ctx, &pb.PatientTypeRequest{ IsEnabled: isEnabled, }) if err != nil { slog.Error("[rpc]GetPatientType failed:", err) } slog.Info("[rpc]GetPatientType result:", "rows", len(r.PatientTypeList)) return r, err } func (s *Protocol) GetBodyPart(ctx context.Context, patientType *string, modality *string, isEnabled *bool) (*pb.BodyPartReply, error) { slog.Info("[rpc]GetBodyPart...") r, err := s.protocolClient.GetBodyPart(ctx, &pb.BodyPartRequest{ PatientType: patientType, Modality: modality, IsEnabled: isEnabled, }) if err != nil { slog.Error("[rpc]GetPatientType failed:", err) } return r, err } func (s *Protocol) GetProcedure(ctx context.Context, patientType *string, bodyPart *string, isEnabled *bool) (*pb.ProcedureReply, error) { slog.Info("[rpc]GetProcedure...") r, err := s.protocolClient.GetProcedure(ctx, &pb.ProcedureRequest{ PatientType: patientType, BodyPartId: bodyPart, IsEnabled: isEnabled, }) if err != nil { slog.Error("[rpc]GetProcedure failed:", err) } return r, err } func (s *Protocol) GetView(ctx context.Context, patientType *string, bodyPart *string, procedureID *string, isEnabled *bool) (*pb.ViewReply, error) { slog.Info("[rpc]GetView...") r, err := s.protocolClient.GetView(ctx, &pb.ViewRequest{ PatientType: patientType, BodyPartId: bodyPart, ProcedureId: procedureID, IsEnabled: isEnabled, }) if err != nil { slog.Error("[rpc]GetView failed:", err) } return r, err }