1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package service
- import (
- "context"
- "google.golang.org/grpc/codes"
- "google.golang.org/grpc/status"
- "protocol-server/common"
- "protocol-server/models"
- )
- import (
- pb "protocol-server/rpc_idl/dr_protocol_pb"
- )
- type ProtocolServer struct {
- pb.UnimplementedProtocolServer
- }
- func (s *ProtocolServer) GetPatientType(ctx context.Context, in *pb.PatientTypeRequest) (*pb.PatientTypeReply, error) {
- product, _, _ := common.GetHeader(ctx)
- 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) {
- 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
- }
|