protocol.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package service
  2. import (
  3. "context"
  4. "google.golang.org/grpc/codes"
  5. "google.golang.org/grpc/status"
  6. "protocol-server/common"
  7. "protocol-server/models"
  8. )
  9. import (
  10. pb "protocol-server/rpc_idl/dr_protocol_pb"
  11. )
  12. type ProtocolServer struct {
  13. pb.UnimplementedProtocolServer
  14. }
  15. func (s *ProtocolServer) GetPatientType(ctx context.Context, in *pb.PatientTypeRequest) (*pb.PatientTypeReply, error) {
  16. product, _, _ := common.GetHeader(ctx)
  17. res := pb.PatientTypeReply{}
  18. err := models.DB.Model(&models.PatientType{}).Scopes(
  19. models.String("product = ?", product.ToString()),
  20. models.Bool("is_enabled = ?", in.IsEnabled),
  21. ).Order("sort").Find(&res.PatientTypeList).Error
  22. if err != nil {
  23. return nil, status.Errorf(codes.Internal, "patient_type find err %v", err)
  24. }
  25. for _, pt := range res.GetPatientTypeList() {
  26. pt.PatientTypeLocal = pt.PatientTypeName
  27. }
  28. return &res, nil
  29. }
  30. func (s *ProtocolServer) GetBodyPart(ctx context.Context, in *pb.BodyPartRequest) (*pb.BodyPartReply, error) {
  31. product, _, _ := common.GetHeader(ctx)
  32. res := pb.BodyPartReply{}
  33. err := models.DB.Model(&models.BodyPart{}).Scopes(
  34. models.String("patient_type = ?", in.GetPatientType()),
  35. models.String("category = ?", in.GetCategory()),
  36. models.String("product = ?", product.ToString()),
  37. models.Bool("is_enabled = ?", in.IsEnabled),
  38. ).Order("sort").Find(&res.BodyPartList).Error
  39. if err != nil {
  40. return nil, status.Errorf(codes.Internal, "body_part find err %v", err)
  41. }
  42. for _, pt := range res.GetBodyPartList() {
  43. pt.BodyPartLocal = pt.BodyPartName
  44. }
  45. return &res, nil
  46. }