pb_protocol.go 2.7 KB

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