pb_dcmtk.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_dcmtk_pb"
  14. )
  15. var DcmtkService *Dcmtk
  16. func init() {
  17. DcmtkService = new(Dcmtk)
  18. }
  19. type Dcmtk struct {
  20. basicClient pb.BasicClient
  21. dcmClient pb.DcmClient
  22. }
  23. func (s *Dcmtk) Setup() {
  24. conn, err := grpc.NewClient(common.ServerConfig.Dcmtk, grpc.WithTransportCredentials(insecure.NewCredentials()))
  25. if err != nil {
  26. slog.Error("NewClient failed:", err)
  27. panic(err)
  28. }
  29. slog.Info("dcmtk conn success", "conn", conn.GetState())
  30. s.basicClient = pb.NewBasicClient(conn)
  31. s.dcmClient = pb.NewDcmClient(conn)
  32. }
  33. func (s *Dcmtk) 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 *Dcmtk) GenerateUniqueIdentifier(ctx context.Context, flag string, number int32) (*pb.UidReply, error) {
  50. slog.Info("[rpc]GenerateUniqueIdentifier...")
  51. SiteUidRoot := "1.2.276.0.1000000.5"
  52. uidRoot := SiteUidRoot
  53. switch flag {
  54. case "study":
  55. uidRoot += ".1.2"
  56. case "series":
  57. uidRoot += ".1.3"
  58. case "sop":
  59. uidRoot += ".1.4"
  60. default:
  61. return nil, common.InvalidParam.Desc("invalid param 'flag'")
  62. }
  63. if number < 1 || number > 10 {
  64. return nil, common.InvalidParam.Desc("number must be between 1 and 10")
  65. }
  66. r, err := s.dcmClient.GenerateUniqueIdentifier(ctx, &pb.UidRootRequest{
  67. UidRoot: uidRoot,
  68. Number: number,
  69. })
  70. if err != nil {
  71. slog.Error("[rpc]GenerateUniqueIdentifier failed", "err", err)
  72. }
  73. return r, err
  74. }