helper.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package service
  2. import (
  3. "encoding/json"
  4. "log/slog"
  5. )
  6. import (
  7. "google.golang.org/protobuf/types/known/structpb"
  8. "gorm.io/datatypes"
  9. )
  10. import (
  11. "protocol-server/models"
  12. pb "protocol-server/rpc_idl/dr_protocol_pb"
  13. )
  14. func json2Struct(o *datatypes.JSON) *structpb.Struct {
  15. var tempMap map[string]interface{}
  16. err := json.Unmarshal(*o, &tempMap)
  17. if err != nil {
  18. slog.Error("Error unmarshalling datatypes.JSON to map", "err", err)
  19. return nilStruct
  20. }
  21. protoStruct, err := structpb.NewStruct(tempMap)
  22. if err != nil {
  23. slog.Error("Error creating proto struct", "err", err)
  24. return nilStruct
  25. }
  26. return protoStruct
  27. }
  28. func view2pb(view *models.View) *pb.View {
  29. return &pb.View{
  30. InternalId: view.InternalID,
  31. ViewId: view.ViewID,
  32. ViewName: view.ViewName,
  33. ViewNameLocal: view.ViewNameLocal,
  34. ViewOtherName: view.ViewOtherName,
  35. ViewDescription: view.ViewDescription,
  36. ViewPosition: view.ViewPosition,
  37. Application: view.Application,
  38. AnatomicRegion: view.AnatomicRegion,
  39. PatientType: view.PatientType,
  40. BodyPartId: view.BodyPartID,
  41. ViewIconName: view.ViewIconName,
  42. ViewBigIconName: view.ViewBigIconName,
  43. ViewCoachName: view.ViewCoachName,
  44. Modality: view.Modality,
  45. WorkStationId: int32(view.WorkStationId),
  46. AprId: view.AprId,
  47. ImgProcId: view.ImgProcId,
  48. ConfigObject: json2Struct(&view.ConfigObject),
  49. Sort: int32(view.Sort),
  50. IsEnabled: view.IsEnabled,
  51. Product: view.Product,
  52. IsPreInstall: view.IsPreInstall,
  53. }
  54. }
  55. func apr2pb(apr *models.Apr) *pb.AprReply {
  56. return &pb.AprReply{
  57. AprId: apr.AprID,
  58. AprName: apr.AprName,
  59. AprDescription: apr.AprDescription,
  60. PatientType: apr.PatientType,
  61. BodyPartId: apr.BodyPartID,
  62. ViewPosition: apr.ViewPosition,
  63. Category: apr.Category,
  64. Modality: apr.Modality,
  65. Sub: []*pb.AprSub{},
  66. Sort: int32(apr.Sort),
  67. IsEnabled: apr.IsEnabled,
  68. Product: apr.Product,
  69. IsPreInstall: apr.IsPreInstall,
  70. }
  71. }
  72. func aprSub2pb(apr *models.AprSub) *pb.AprSub {
  73. return &pb.AprSub{
  74. WorkStationId: int32(apr.WorkStationID),
  75. PatientSize: apr.PatientSize,
  76. ConfigObject: json2Struct(&apr.ConfigObject),
  77. }
  78. }