function bindPracticeEntityArray($practiceEntitys)
{
    $practiceDtos = new PracticeListDto();
    $practiceDtoArray = array();
    foreach ($practiceEntitys as $practiceEntity => $value) {
        array_push($practiceDtoArray, bindPracticeEntity($value));
    }
    $practiceDtos->setPractices($practiceDtoArray);
    return $practiceDtos;
}
function bindPracticeFieldEntity($practiceFieldEntity)
{
    if ($practiceFieldEntity != null) {
        $practiceFieldDto = new PracticeFieldDto();
        $practiceFieldDto->setPracticeFieldId($practiceFieldEntity->getPracticeFieldId());
        $practiceFieldDto->setField(bindFieldEntity($practiceFieldEntity->getField()));
        $practiceFieldDto->setPractice(bindPracticeEntity($practiceFieldEntity->getPractice()));
        return $practiceFieldDto;
    } else {
        return null;
    }
}
function bindDoctorPracticeEntity($doctorPracticeEntity)
{
    if ($doctorPracticeEntity != null) {
        $doctorPracticeDto = new DoctorPracticeDto();
        $doctorPracticeDto->setMedsDoctorPracticeId($doctorPracticeEntity->getMedsDoctorPracticeId());
        $doctorPracticeDto->setPractice(bindPracticeEntity($doctorPracticeEntity->getPractice()));
        $doctorPracticeDto->setDoctor(bindDoctorEntity($doctorPracticeEntity->getDoctor()));
        return $doctorPracticeDto;
    } else {
        return null;
    }
}
function bindAppointmentEntity($appointmentEntity)
{
    if ($appointmentEntity != null) {
        $appointmentDto = new AppointmentDto();
        $appointmentDto->setAppointmentId($appointmentEntity->getAppointmentId());
        $appointmentDto->setPractice(bindPracticeEntity($appointmentEntity->getPractice()));
        $appointmentDto->setUser(bindUserEntity($appointmentEntity->getUser()));
        $appointmentDto->setNote(bindDataContentEntity($appointmentEntity->getNote()));
        $appointmentDto->setExpectedFrm($appointmentEntity->getExpectedFrm());
        $appointmentDto->setExpectedTo($appointmentEntity->getExpectedTo());
        $appointmentDto->setActualFrm($appointmentEntity->getActualFrm());
        $appointmentDto->setActualTo($appointmentEntity->getActualTo());
        return $appointmentDto;
    } else {
        return null;
    }
}
    $practicesArray = array();
    foreach ($practiceListDto->getPractices() as $practiceDto) {
        $practiceEntity = bindPracticeDto($practiceDto);
        $entityManager->persist($practiceEntity);
        $entityManager->flush();
        array_push($practicesArray, bindPracticeEntity($practiceEntity));
    }
    $practiceListDto = new PracticeListDto();
    $practiceListDto->setPractices($practicesArray);
    $practiceListDto->printData($app);
});
$app->put('/practices/:id', function ($id) use($app) {
    global $entityManager;
    $practiceEntity = $entityManager->find("PracticeEntity", $id);
    $entityManager->flush();
    $practiceDto = bindPracticeEntity($practiceEntity);
    $practiceDto->printData($app);
});
$app->delete('/practices/:id', function ($id) use($app) {
    global $entityManager;
    $practiceEntity = $entityManager->find("PracticeEntity", $id);
    $entityManager->remove($practiceEntity);
    $entityManager->flush();
});
/*Referances*/
$app->get('/practices/:id/practicefields/practices', function ($id) use($app) {
    global $entityManager;
    $practiceFieldEntities = $entityManager->getRepository("PracticeFieldEntity")->findBy(array('practice' => $id));
    $practiceField = bindPracticeFieldEntityArray($practiceFieldEntities);
    $practiceField->printData($app);
});