pb_dcmtk.go 1.8 KB

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