|
@@ -3,6 +3,8 @@ package service
|
|
|
import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
+ "gorm.io/gorm"
|
|
|
"log/slog"
|
|
|
)
|
|
|
|
|
@@ -129,23 +131,31 @@ func view2pb(view models.View) *pb.View {
|
|
|
}
|
|
|
|
|
|
func (s *ProtocolServer) GetView(ctx context.Context, in *pb.ViewRequest) (*pb.ViewReply, error) {
|
|
|
+ product, _, _ := common.GetHeader(ctx)
|
|
|
procedure := models.Procedure{}
|
|
|
res := pb.ViewReply{}
|
|
|
if in.GetProcedureId() == "" {
|
|
|
err := models.DB.Model(&models.View{}).Scopes(
|
|
|
models.String("patient_type = ?", in.GetPatientType()),
|
|
|
models.String("body_part_id = ?", in.GetBodyPartId()),
|
|
|
+ models.String("product = ?", product.ToString()),
|
|
|
models.Bool("is_enabled = ?", in.IsEnabled),
|
|
|
models.Bool("is_pre_install = ?", in.IsPreInstall),
|
|
|
- ).Order("sort, id").Find(&procedure.Views).Error
|
|
|
+ ).Order("sort").Find(&procedure.Views).Error
|
|
|
if err != nil {
|
|
|
return nil, status.Errorf(codes.Internal, "procedure find err %v", err)
|
|
|
}
|
|
|
} else {
|
|
|
err := models.DB.Model(&models.Procedure{}).Preload("Views").Scopes(
|
|
|
models.String("procedure_id = ?", in.GetProcedureId()),
|
|
|
- ).Order("sort, id").First(&procedure).Error
|
|
|
+ models.String("product = ?", product.ToString()),
|
|
|
+ models.Bool("is_enabled = ?", in.IsEnabled),
|
|
|
+ models.Bool("is_pre_install = ?", in.IsPreInstall),
|
|
|
+ ).Order("sort").First(&procedure).Error
|
|
|
if err != nil {
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ return nil, status.Errorf(codes.NotFound, "procedure %s not found", in.GetProcedureId())
|
|
|
+ }
|
|
|
return nil, status.Errorf(codes.Internal, "procedure find err %v", err)
|
|
|
}
|
|
|
}
|