pb_protocol.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. )
  11. import (
  12. "auth-server/common"
  13. pb "auth-server/rpc_idl/dr_protocol_pb"
  14. )
  15. var ProtocolService *Protocol
  16. func init() {
  17. ProtocolService = new(Protocol)
  18. }
  19. type Protocol struct {
  20. basicClient pb.BasicClient
  21. protocolClient pb.ProtocolClient
  22. }
  23. func (s *Protocol) Setup() {
  24. conn, err := grpc.NewClient(common.ServerConfig.Protocol, grpc.WithTransportCredentials(insecure.NewCredentials()))
  25. if err != nil {
  26. slog.Error("NewClient failed:", err)
  27. panic(err)
  28. }
  29. slog.Info("protocol conn success", "conn", conn.GetState())
  30. s.basicClient = pb.NewBasicClient(conn)
  31. s.protocolClient = pb.NewProtocolClient(conn)
  32. }
  33. func (s *Protocol) GetSoftwareInfo() *pb.SoftwareInfoReply {
  34. slog.Info("[rpc]SoftwareInfo...")
  35. ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
  36. defer cancel()
  37. r, err := s.basicClient.SoftwareInfo(ctx, &pb.EmptyRequest{})
  38. if err != nil {
  39. slog.Error("[rpc]SoftwareInfo failed", "err", err)
  40. return &pb.SoftwareInfoReply{
  41. Module: "",
  42. Desc: "",
  43. Build: "",
  44. Version: "",
  45. }
  46. }
  47. return r
  48. }
  49. func (s *Protocol) GetPatientType(ctx context.Context, isEnabled *bool) (*pb.PatientTypeReply, error) {
  50. slog.Info("[rpc]GetPatientType...")
  51. r, err := s.protocolClient.GetPatientType(ctx, &pb.PatientTypeRequest{
  52. IsEnabled: isEnabled,
  53. })
  54. if err != nil {
  55. slog.Error("[rpc]GetPatientType failed", "err", err)
  56. }
  57. slog.Info("[rpc]GetPatientType result:", "rows", len(r.PatientTypeList))
  58. return r, err
  59. }
  60. func (s *Protocol) GetBodyPart(ctx context.Context, patientType *string, modality *string, isEnabled *bool) (*pb.BodyPartReply, error) {
  61. slog.Info("[rpc]GetBodyPart...")
  62. r, err := s.protocolClient.GetBodyPart(ctx, &pb.BodyPartRequest{
  63. PatientType: patientType,
  64. Modality: modality,
  65. IsEnabled: isEnabled,
  66. })
  67. if err != nil {
  68. slog.Error("[rpc]GetBodyPart failed", "err", err)
  69. }
  70. return r, err
  71. }
  72. func (s *Protocol) GetProcedure(ctx context.Context, patientType *string, bodyPart *string, isEnabled *bool) (*pb.ProcedureReply, error) {
  73. slog.Info("[rpc]GetProcedure...")
  74. r, err := s.protocolClient.GetProcedure(ctx, &pb.ProcedureRequest{
  75. PatientType: patientType,
  76. BodyPartId: bodyPart,
  77. IsEnabled: isEnabled,
  78. })
  79. if err != nil {
  80. slog.Error("[rpc]GetProcedure failed", "err", err)
  81. }
  82. return r, err
  83. }
  84. func (s *Protocol) GetView(ctx context.Context, patientType *string, bodyPart *string, procedureID *string, isEnabled *bool) (*pb.ViewReply, error) {
  85. slog.Info("[rpc]GetView...")
  86. r, err := s.protocolClient.GetView(ctx, &pb.ViewRequest{
  87. PatientType: patientType,
  88. BodyPartId: bodyPart,
  89. ProcedureId: procedureID,
  90. IsEnabled: isEnabled,
  91. })
  92. if err != nil {
  93. slog.Error("[rpc]GetView failed", "err", err)
  94. }
  95. return r, err
  96. }