|
@@ -4,7 +4,6 @@ import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
- "gorm.io/gorm"
|
|
|
"log/slog"
|
|
|
)
|
|
|
|
|
@@ -13,6 +12,7 @@ import (
|
|
|
"google.golang.org/grpc/status"
|
|
|
"google.golang.org/protobuf/types/known/structpb"
|
|
|
"gorm.io/datatypes"
|
|
|
+ "gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
import (
|
|
@@ -50,10 +50,13 @@ type ProtocolServer struct {
|
|
|
pb.UnimplementedProtocolServer
|
|
|
}
|
|
|
|
|
|
-func (s *ProtocolServer) GetPatientType(ctx context.Context, in *pb.PatientTypeRequest) (*pb.PatientTypeReply, error) {
|
|
|
- product, _, _ := common.GetHeader(ctx)
|
|
|
+func (s *ProtocolServer) GetPatientTypeList(ctx context.Context, in *pb.PatientTypeRequest) (*pb.PatientTypeReply, error) {
|
|
|
res := pb.PatientTypeReply{}
|
|
|
- err := models.DB.Model(&models.PatientType{}).Scopes(
|
|
|
+ product, _, _, err := common.GetHeader(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return &res, err
|
|
|
+ }
|
|
|
+ err = models.DB.Model(&models.PatientType{}).Scopes(
|
|
|
models.String("product = ?", product.ToString()),
|
|
|
models.Bool("is_enabled = ?", in.IsEnabled),
|
|
|
).Order("sort").Find(&res.PatientTypeList).Error
|
|
@@ -65,10 +68,13 @@ func (s *ProtocolServer) GetPatientType(ctx context.Context, in *pb.PatientTypeR
|
|
|
}
|
|
|
return &res, nil
|
|
|
}
|
|
|
-func (s *ProtocolServer) GetBodyPart(ctx context.Context, in *pb.BodyPartRequest) (*pb.BodyPartReply, error) {
|
|
|
- product, _, _ := common.GetHeader(ctx)
|
|
|
+func (s *ProtocolServer) GetBodyPartList(ctx context.Context, in *pb.BodyPartRequest) (*pb.BodyPartReply, error) {
|
|
|
res := pb.BodyPartReply{}
|
|
|
- err := models.DB.Model(&models.BodyPart{}).Scopes(
|
|
|
+ product, _, _, err := common.GetHeader(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return &res, err
|
|
|
+ }
|
|
|
+ err = models.DB.Model(&models.BodyPart{}).Scopes(
|
|
|
models.String("patient_type = ?", in.GetPatientType()),
|
|
|
models.String("modality = ?", in.GetModality()),
|
|
|
models.String("product = ?", product.ToString()),
|
|
@@ -83,10 +89,13 @@ func (s *ProtocolServer) GetBodyPart(ctx context.Context, in *pb.BodyPartRequest
|
|
|
return &res, nil
|
|
|
}
|
|
|
|
|
|
-func (s *ProtocolServer) GetProcedure(ctx context.Context, in *pb.ProcedureRequest) (*pb.ProcedureReply, error) {
|
|
|
- product, _, _ := common.GetHeader(ctx)
|
|
|
+func (s *ProtocolServer) GetProcedureList(ctx context.Context, in *pb.ProcedureRequest) (*pb.ProcedureReply, error) {
|
|
|
res := pb.ProcedureReply{}
|
|
|
- err := models.DB.Model(&models.Procedure{}).Scopes(
|
|
|
+ product, _, _, err := common.GetHeader(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return &res, err
|
|
|
+ }
|
|
|
+ err = models.DB.Model(&models.Procedure{}).Scopes(
|
|
|
models.String("patient_type = ?", in.GetPatientType()),
|
|
|
models.String("body_part_id = ?", in.GetBodyPartId()),
|
|
|
models.String("product = ?", product.ToString()),
|
|
@@ -103,6 +112,28 @@ func (s *ProtocolServer) GetProcedure(ctx context.Context, in *pb.ProcedureReque
|
|
|
return &res, nil
|
|
|
}
|
|
|
|
|
|
+func (s *ProtocolServer) GetProcedure(ctx context.Context, in *pb.IDRequest) (*pb.Procedure, error) {
|
|
|
+ slog.Info("[rpc]GetProcedure...", "instance_id", *in.InstanceId)
|
|
|
+ res := pb.Procedure{}
|
|
|
+ product, _, _, err := common.GetHeader(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return &res, err
|
|
|
+ }
|
|
|
+ err = models.DB.Model(&models.Procedure{}).Scopes(
|
|
|
+ models.String("internal_id = ?", in.GetInstanceId()),
|
|
|
+ models.String("product = ?", product.ToString()),
|
|
|
+ ).Order("sort").Find(&res).Error
|
|
|
+ if err != nil {
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ return nil, status.Errorf(codes.NotFound, "procedure %s not found", in.GetInstanceId())
|
|
|
+ }
|
|
|
+ return nil, status.Errorf(codes.Internal, "procedure find err %v", err)
|
|
|
+ }
|
|
|
+ res.ProcedureNameLocal = res.ProcedureName
|
|
|
+ res.ProcedureDescriptionLocal = res.ProcedureDescription
|
|
|
+ return &res, nil
|
|
|
+}
|
|
|
+
|
|
|
func view2pb(view models.View) *pb.View {
|
|
|
return &pb.View{
|
|
|
InternalId: view.InternalID,
|
|
@@ -123,17 +154,20 @@ func view2pb(view models.View) *pb.View {
|
|
|
ConfigObject: Json2Struct(&view.ConfigObject),
|
|
|
TechTemplate: view.TechTemplate,
|
|
|
ImgProcTemplate: view.ImgProcTemplate,
|
|
|
- Sort: view.Sort,
|
|
|
+ Sort: int32(view.Sort),
|
|
|
IsEnabled: view.IsEnabled,
|
|
|
Product: view.Product,
|
|
|
IsPreInstall: view.IsPreInstall,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (s *ProtocolServer) GetView(ctx context.Context, in *pb.ViewRequest) (*pb.ViewReply, error) {
|
|
|
- product, _, _ := common.GetHeader(ctx)
|
|
|
+func (s *ProtocolServer) GetViewList(ctx context.Context, in *pb.ViewRequest) (*pb.ViewReply, error) {
|
|
|
procedure := models.Procedure{}
|
|
|
res := pb.ViewReply{}
|
|
|
+ product, _, _, err := common.GetHeader(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return &res, err
|
|
|
+ }
|
|
|
if in.GetProcedureId() == "" {
|
|
|
err := models.DB.Model(&models.View{}).Scopes(
|
|
|
models.String("patient_type = ?", in.GetPatientType()),
|
|
@@ -164,3 +198,24 @@ func (s *ProtocolServer) GetView(ctx context.Context, in *pb.ViewRequest) (*pb.V
|
|
|
}
|
|
|
return &res, nil
|
|
|
}
|
|
|
+
|
|
|
+func (s *ProtocolServer) GetView(ctx context.Context, in *pb.IDRequest) (*pb.View, error) {
|
|
|
+ slog.Info("[rpc]GetView...", "instance_id", *in.InstanceId)
|
|
|
+ product, _, _, err := common.GetHeader(ctx)
|
|
|
+ if err != nil {
|
|
|
+ slog.Info("[rpc]GetView err:", err)
|
|
|
+ return &pb.View{}, err
|
|
|
+ }
|
|
|
+ var view models.View
|
|
|
+ err = models.DB.Scopes(
|
|
|
+ models.String("internal_id = ?", in.GetInstanceId()),
|
|
|
+ models.String("product = ?", product.ToString()),
|
|
|
+ ).Order("sort").First(&view).Error
|
|
|
+ if err != nil {
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ return nil, status.Errorf(codes.NotFound, "procedure %s not found", in.GetInstanceId())
|
|
|
+ }
|
|
|
+ return nil, status.Errorf(codes.Internal, "view find err %v", err)
|
|
|
+ }
|
|
|
+ return view2pb(view), nil
|
|
|
+}
|