HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/sarvodayahospital/app/AppointmentBook.php
<?php

// phpcs:disable

namespace app;

use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;

/**
 * Post for Booking an appointment.
 *
 * @author Subhendu Giri
 */
class AppointmentBook
{
    // phpcs:enable

    /**
     * Construct funtion.
     */
    public function __construct()
    {
        //pass
    }

    // private $_USERID = 'appointment@sarvodaya';
    // private $_USERKEY = 'a7a56cfe-d152-480b-aab3-d5923a8b5bb7';

    // For Noida Location
    private $_USERID_NOIDA = 'user@sarvodaya-noida';
    private $_USERKEY_NOIDA = 'ed5746b3-e532-43ce-b90d-c3caf9029751';
    private $_UNITNAME_NOIDA = 'SARVODAYA HOSPITAL - NOIDA';

    // For Sector-8 Location
    private $_USERID = 'appointment@sarvodaya';
    private $_USERKEY = 'a7a56cfe-d152-480b-aab3-d5923a8b5bb7';
    private $_UNITNAME= 'SARVODAYA HOSPITAL AND RESEARCH CENTRE';

    /**
     * Book slots for doctor.
     *
     * @param Booking $booking      Booking information
     * @param string  $facilityGUID Facility GUID or Hospital Global ID
     *
     * @return Response
     */
    public function bookAppointment(BookingData $booking, $facilityGUID, $hospital_name)
    {
        //Preparing post parameters
        $postData = [
            'appointmentDate' => $booking->appointmentDate,
            'appointmentID' => $booking->appointmentID,
            'appointmentType' => $booking->appointmentType,
            'dob' => $booking->dob,
            'gender' => $booking->gender ? 'M' : 'F',
            'mrn' => $booking->mrn ? $booking->mrn : '',
            'mobilePhone' => $booking->mobilePhone,
            'reasonForAppt' => $booking->reasonForAppt ? $booking->reasonForAppt : '', // phpcs:ignore
            'loginID' => $booking->loginID ? $booking->loginID : '',
            'patientName' => $booking->patientName,
            'prefix' => $booking->prefix,
            'slotTime' => $booking->slotTime,
            'checkAppointmentExists' => $booking->checkAppointmentExists ? true : false, // phpcs:ignore
            'address' => $booking->address,
            'country' => $booking->country,
            'state' => $booking->state,
            'city' => $booking->city,
            'region' => $booking->region,
            'pincode' => $booking->pincode,
            'consultationType' => $booking->consultationType,
            'countryCode' => $booking->countryCode,
        ];

        try {
            $url = 'https://live.mednetlabs.com/mxServer/ws/feature/mednetAppointment/bookAppointment'; // phpcs:ignore
            $response = Http::withHeaders(
                [
                    'source' => 'WebClient',
                    'facilityGUID' => $facilityGUID,
                    'unitName' => $this->apiUnitName($facilityGUID),
                    'userID' => $this->apiUserName($facilityGUID),
                    'userKey' => $this->apiUserKey($facilityGUID),
                ]
            )
            ->post($url, $postData);

            return $response;
        } catch (ConnectionException $exception) {
            return json_encode($exception);
        }
    }

    /**
     * Cancel slots for doctor.
     *
     * @param int    $appointmentID    Appointment Id
     * @param string $cancellationNote Special note
     *
     * @return Response
     */
    public function cancelBooking($appointmentID, $facilityGUID, $hospital_name, $cancellationNote = 'NA')
    {
        $postData = [
            'appointmentID' => $appointmentID,
            'cancellationNote' => $cancellationNote,
        ];

        $url = 'https://live.mednetlabs.com/mxServer/ws/feature/mednetAppointment/cancelAppointment'; // phpcs:ignore
        $response = Http::withHeaders(
            [
                'source' => 'WebClient',
                'facilityGUID' => $facilityGUID,
                'unitName' => $this->apiUnitName($facilityGUID),
                'userID' => $this->apiUserName($facilityGUID),
                'userKey' => $this->apiUserKey($facilityGUID),
            ]
        )
        ->post($url, $postData);

        return $response;
    }


    public function apiUserName($facilityGUID)
    {
        if ($facilityGUID == '3e77361c-d482-4816-afbb-5b87576da352') {
            return $this->_USERID;
        }

        if ($facilityGUID == '7c43de44-9724-4b6a-828b-73a3097d3653') {
            return $this->_USERID_NOIDA;
        }

        return '';
    }

    public function apiUserKey($facilityGUID)
    {
        if ($facilityGUID == '3e77361c-d482-4816-afbb-5b87576da352') {
            return $this->_USERKEY;
        }

        if ($facilityGUID == '7c43de44-9724-4b6a-828b-73a3097d3653') {
            return $this->_USERKEY_NOIDA;
        }

        return '';
    }

    public function apiUnitName($facilityGUID)
    {
        if ($facilityGUID == '3e77361c-d482-4816-afbb-5b87576da352') {
            return $this->_UNITNAME;
        }

        if ($facilityGUID == '7c43de44-9724-4b6a-828b-73a3097d3653') {
            return $this->_UNITNAME_NOIDA;
        }

        return '';
    }
}