<?phpnamespace App\Mobile;use App\Entity\Branch;use App\Entity\Patient;use App\Entity\User;use Doctrine\ORM\NonUniqueResultException;use Doctrine\Persistence\ManagerRegistry;use Doctrine\Persistence\ObjectManager;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Serializer\Encoder\JsonDecode;use Symfony\Contracts\HttpClient\HttpClientInterface;class NewPatientController extends AbstractController { private ObjectManager $em; public function __construct(ManagerRegistry $managerRegistry) { $this->em = $managerRegistry->getManager(); } /** * @Route("/patients", methods={"POST"}, name="newPatient") * @param Request $request * @return Response */ public function newPatient(Request $request): Response { $em = $this->em; $phone = $request->query->get('phone'); $user = $em->getRepository(User::class)->findOneBy([ 'phone' => $phone ]); $patientJSON = $request->getContent(); $patientArray = json_decode($patientJSON);// $date = date($patientArray->appointment_date);// $date = new \DateTime($patientArray->appointment_date); $date = new \DateTime(); $date->modify('+2 day');// $checkPatient = $em->getRepository('App:Patient')->findOneBy([// 'uniqueId' =>// ])// $date = new \DateTime();// try {// $checkPatient = $em->getRepository("App:Patient")->findByDateAndPhoneNumber($patientArray->phone);////// if($checkPatient){// return new Response('ALREADY AVAILABLE', Response::HTTP_OK, [// 'Content-Type' => 'application/json'// ]);// }//// $checkPatient = null;//// $checkPatient = $em->getRepository("App:Patient")->findByDate3MonthsAndPhoneNumber($patientArray->phone);//// if($checkPatient){// return new Response('ALREADY AVAILABLE', Response::HTTP_OK, [// 'Content-Type' => 'application/json'// ]);// }//// } catch (NonUniqueResultException $e) {//// } $patient = new Patient(); // $patient->setPatientId(rand(10,100)); $patient->setPatientName($patientArray->patient_name); $patient->setPhone($patientArray->phone); $patient->setLocation($patientArray->location); $patient->setReason($patientArray->reason);// $patient->setAppointmentDate(new \DateTime()); $patient->setAppointmentDate($date); // $patient->setCreatedAt(new \DateTime()); $patient->setUser($user); $patient->setIsSeen(false);// $user = $em->getRepository("App:User")->findOneBy([// 'id' => 1// ]); $branch = $em->getRepository(Branch::class)->findOneBy([ 'id' => $patientArray->branch ]);// $branch = $user->getBranch(); $patient->setBranch($branch); $patient->setUser($user); // dump($patient); $em->persist($patient); $em->flush();// dump($patient); return new Response($patientJSON, Response::HTTP_OK, [ 'Content-Type' => 'application/json' ]); }}