feat: enhance DoctorAddress entity to support clinic addresses and types
- Added `clinic_id` and `type` fields to `DoctorAddress` entity to differentiate between personal and clinic addresses. - Updated constructor to support creation of addresses for both doctors and clinics. - Modified repository methods to handle new address types and added methods for counting and finding addresses by clinic. - Implemented migration to update the database schema accordingly. - Removed deprecated endpoint for creating addresses from clinics and updated related controller methods. - Added new endpoints for managing clinic addresses, including CRUD operations. - Updated frontend components to handle new address types and display accordingly.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Doctor\Repository;
|
||||
|
||||
use App\Doctor\Entity\Doctor;
|
||||
use App\Doctor\Entity\DoctorAddress;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
@@ -28,4 +29,48 @@ class DoctorAddressRepository extends ServiceEntityRepository
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function findByUuidAndClinic(string $uuid, int $clinicId): ?DoctorAddress
|
||||
{
|
||||
return $this->createQueryBuilder('a')
|
||||
->where('a.uuid = :uuid')
|
||||
->andWhere('a.clinicId = :clinicId')
|
||||
->setParameter('uuid', $uuid)
|
||||
->setParameter('clinicId', $clinicId)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
public function countByClinic(int $clinicId): int
|
||||
{
|
||||
return (int) $this->createQueryBuilder('a')
|
||||
->select('COUNT(a.id)')
|
||||
->where('a.clinicId = :clinicId')
|
||||
->setParameter('clinicId', $clinicId)
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function findAvailableForDoctor(Doctor $doctor, array $clinicIds): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('a');
|
||||
$qb->where(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->eq('a.doctor', ':doctor'),
|
||||
$qb->expr()->eq('a.type', ':personal')
|
||||
),
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->in('a.clinicId', ':clinicIds'),
|
||||
$qb->expr()->eq('a.type', ':clinic')
|
||||
)
|
||||
)
|
||||
)
|
||||
->setParameter('doctor', $doctor)
|
||||
->setParameter('personal', DoctorAddress::TYPE_PERSONAL)
|
||||
->setParameter('clinicIds', empty($clinicIds) ? [0] : $clinicIds)
|
||||
->setParameter('clinic', DoctorAddress::TYPE_CLINIC);
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user