shao 6 days ago
parent
commit
e8ec3defc5
2 changed files with 30 additions and 1 deletions
  1. 11 0
      models/scope.go
  2. 19 1
      service/protocol.go

+ 11 - 0
models/scope.go

@@ -21,3 +21,14 @@ func String(query string, arg string) func(db *gorm.DB) *gorm.DB {
 		return db
 	}
 }
+
+func Bool(query string, arg *bool) func(db *gorm.DB) *gorm.DB {
+	if arg != nil {
+		return func(db *gorm.DB) *gorm.DB {
+			return db.Where(query, *arg)
+		}
+	}
+	return func(db *gorm.DB) *gorm.DB {
+		return db
+	}
+}

+ 19 - 1
service/protocol.go

@@ -21,12 +21,30 @@ func (s *ProtocolServer) GetPatientType(ctx context.Context, in *pb.PatientTypeR
 	res := pb.PatientTypeReply{}
 	err := models.DB.Model(&models.PatientType{}).Scopes(
 		models.String("product = ?", product.ToString()),
+		models.Bool("is_enabled = ?", in.IsEnabled),
 	).Order("sort").Find(&res.PatientTypeList).Error
 	if err != nil {
 		return nil, status.Errorf(codes.Internal, "patient_type find err %v", err)
 	}
+	for _, pt := range res.GetPatientTypeList() {
+		pt.PatientTypeLocal = pt.PatientTypeName
+	}
 	return &res, nil
 }
 func (s *ProtocolServer) GetBodyPart(ctx context.Context, in *pb.BodyPartRequest) (*pb.BodyPartReply, error) {
-	return nil, status.Errorf(codes.Unimplemented, "method GetBodyPart not implemented")
+	product, _, _ := common.GetHeader(ctx)
+	res := pb.BodyPartReply{}
+	err := models.DB.Model(&models.BodyPart{}).Scopes(
+		models.String("patient_type = ?", in.GetPatientType()),
+		models.String("category = ?", in.GetCategory()),
+		models.String("product = ?", product.ToString()),
+		models.Bool("is_enabled = ?", in.IsEnabled),
+	).Order("sort").Find(&res.BodyPartList).Error
+	if err != nil {
+		return nil, status.Errorf(codes.Internal, "body_part find err %v", err)
+	}
+	for _, pt := range res.GetBodyPartList() {
+		pt.BodyPartLocal = pt.BodyPartName
+	}
+	return &res, nil
 }