Exemplo n.º 1
0
        public static Domain.PhysicianCollection GetPhysiciansByClientId(int clientId)
        {
            Domain.PhysicianCollection result = new Domain.PhysicianCollection();
            YellowstonePathology.Business.Mongo.Server server = new Business.Mongo.TestServer(YellowstonePathology.Business.Mongo.MongoTestServer.LISDatabaseName);
            MongoCollection physicianClientCollection         = server.Database.GetCollection <BsonDocument>("PhysicianClient");
            MongoCursor     physicianClientCursor             = physicianClientCollection.FindAs <BsonDocument>(Query.EQ("ClientId", BsonValue.Create(clientId)));

            List <BsonValue> physicianIdList = new List <BsonValue>();

            foreach (BsonDocument bsonDocument in physicianClientCursor)
            {
                physicianIdList.Add(bsonDocument.GetValue("PhysicianId"));
            }

            MongoCollection physicianCollection = server.Database.GetCollection <BsonDocument>("Physician");
            MongoCursor     physicianCursor     = physicianCollection.FindAs <BsonDocument>(Query.In("PhysicianId", physicianIdList));

            foreach (BsonDocument bsonDocument in physicianCursor)
            {
                Domain.Physician physician = new Domain.Physician();
                YellowstonePathology.Business.Mongo.BSONPropertyWriter.Write(bsonDocument, physician);
                result.Add(physician);
            }

            return(result);
        }
        public static Domain.PhysicianCollection GetPhysiciansByClientId(int clientId)
        {
            Domain.PhysicianCollection result = new Domain.PhysicianCollection();
            YellowstonePathology.Business.Mongo.Server server = new Business.Mongo.TestServer(YellowstonePathology.Business.Mongo.MongoTestServer.LISDatabaseName);
            MongoCollection physicianClientCollection = server.Database.GetCollection<BsonDocument>("PhysicianClient");
            MongoCursor physicianClientCursor = physicianClientCollection.FindAs<BsonDocument>(Query.EQ("ClientId", BsonValue.Create(clientId)));

            List<BsonValue> physicianIdList = new List<BsonValue>();
            foreach (BsonDocument bsonDocument in physicianClientCursor)
            {
                physicianIdList.Add(bsonDocument.GetValue("PhysicianId"));
            }

            MongoCollection physicianCollection = server.Database.GetCollection<BsonDocument>("Physician");
            MongoCursor physicianCursor = physicianCollection.FindAs<BsonDocument>(Query.In("PhysicianId", physicianIdList));
            foreach (BsonDocument bsonDocument in physicianCursor)
            {
                Domain.Physician physician = new Domain.Physician();
                YellowstonePathology.Business.Mongo.BSONPropertyWriter.Write(bsonDocument, physician);
                result.Add(physician);
            }

            return result;
        }
        /*        public static Domain.PhysicianCollection GetPhysiciansByClientId(int clientId)
        {
        #if MONGO
            return PhysicianClientGatewayMongo.GetPhysiciansByClientId(clientId);
        #else
            Domain.PhysicianCollection result = new Domain.PhysicianCollection();

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select ph.* " +
               "from tblPhysician ph " +
               "join tblPhysicianClient pc on ph.PhysicianId = pc.PhysicianId " +
               "where pc.ClientId = @ClientId order by ph.LastName";
            cmd.Parameters.Add("@ClientId", SqlDbType.Int).Value = clientId;
            cmd.CommandType = CommandType.Text;
            result = PhysicianClientGateway.GetPhysicianCollectionFromCommand(cmd);
            return result;
        #endif
        }*/
        private static Domain.PhysicianCollection GetPhysicianCollectionFromCommand(SqlCommand cmd)
        {
            Domain.PhysicianCollection result = new Domain.PhysicianCollection();
            using (SqlConnection cn = new SqlConnection(YellowstonePathology.Business.BaseData.SqlConnectionString))
            {
                cn.Open();
                cmd.Connection = cn;
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        YellowstonePathology.Business.Domain.Physician physician = new Domain.Physician();
                        YellowstonePathology.Business.Persistence.SqlDataReaderPropertyWriter sqlDataReaderPropertyWriter = new Persistence.SqlDataReaderPropertyWriter(physician, dr);
                        sqlDataReaderPropertyWriter.WriteProperties();
                        result.Add(physician);
                    }
                }
            }
            return result;
        }
        public static Domain.PhysicianCollection GetPhysiciansByClientIdV2(int clientId)
        {
            Domain.PhysicianCollection result = new Domain.PhysicianCollection();

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select ph.* " +
               "from tblPhysician ph " +
               "join tblPhysicianClient pc on ph.ObjectId = pc.ProviderId " +
               "where pc.ClientId = @ClientId order by ph.LastName";
            cmd.Parameters.Add("@ClientId", SqlDbType.Int).Value = clientId;
            cmd.CommandType = CommandType.Text;
            result = PhysicianClientGateway.GetPhysicianCollectionFromCommand(cmd);
            return result;
        }