<?php echo $__env->make('header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php
$UserId = Session::get('UserId');
$UserId = Session::get('UserId');
$json_data = ['JsonData' => ['TreatType' => [], 'TreatDose' => [], 'TreatFreq' => [], 'TreatEye' => []]];
$json_data2 = [];
$results = array();
$results2 = array();

if(file_exists('json_files/json-file.json')){
$json = file_get_contents('json_files/json-file.json');
//Decode JSON
$decoded = json_decode($json,true);
if($decoded && is_array($decoded)){
    $json_data = $decoded;
}
}

if(file_exists('json_files/timetables_date.json')){
$json2 = file_get_contents('json_files/timetables_date.json');
//Decode JSON
$decoded2 = json_decode($json2,true);
if($decoded2 && is_array($decoded2)){
    $json_data2 = $decoded2;
}
}
?>
<style type="text/css">
fieldset legend {
    background: inherit;
    font-family: "Lato", sans-serif;
    color: #650812;
    font-size: 15px;
    left: 10px;
    padding: 0 10px;
    position: absolute;
    top: -12px;
    font-weight: 400;
    width: auto !important;
    border: none !important;
}

fieldset {
    background: #ffffff;
    border: 1px solid #C43853;
    border-radius: 5px;
    margin: 10px 0 8px 0;
    padding: 10px;
    position: relative;
}

.form-control {
    min-height: 1px;
    height: 25px;
}

.container,
.container-fluid {
    padding-right: 15px;
    padding-left: 15px;
}

.table th,
.table td {
    padding: 1px;
    padding-left: 7px;
}

.col-md-12 {
    margin-bottom: 5px;
}

.col-lg-6 .col-md-12 {
    margin-bottom: 8px;
}

/* Treatment section spacing */
#showTreatments {
    margin-bottom: 10px;
}

fieldset legend {
    margin-bottom: 5px;
    font-size: 14px;
}

textarea.form-control {
    resize: vertical;
    min-height: 50px;
}
</style>
<div class="container-fluid flex-grow-1 container-p-y" style="padding-top: 10px !important;">
    <!-- <h4 class="font-weight-bold py-3 mb-0">Discharge Card</h4> -->
    <form id="validation-form" novalidate="novalidate" method="POST" enctype="multipart/form-data" autocomplete="off"
        action="">
        <input type="hidden" name="actionvalue" id="actionvalue" value="Save">
        <input type="hidden" name="saveid" id="saveid" value="">
        <input type="hidden" name="IpdNo" id="IpdNo" value="">
        
        <?php echo csrf_field(); ?>

        <div class="card mb-12 mb-1">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3">
                    <label>Discharge Patient Lists</label>
                        <input class="form-control" list="DataList2" name="PatientId" id="PatientId"
                            style="height: 31px;">
                        <datalist id="DataList2">
                            <?php $__currentLoopData = $patientList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $result): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if($result->Phone == ''): ?>
                            <?php $PatientName = $result->id." / ".$result->MrdNo." / ".$result->PatientName;?>
                            <?php else: ?>
                            <?php $PatientName = $result->id." / ".$result->MrdNo." / ".$result->PatientName."/".$result->Phone;?>
                            <?php endif; ?>
                            <option value="<?php echo e($PatientName); ?>">
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </datalist>
                    </div>

                    <div class="col-md-9">
                        <table class="table table-bordered table-striped mb-0">
                            <thead>
                                <tr>
                                    <th width="10" align="center" valign="top">Discharge Id</th>
                                    <th width="10" align="center" valign="top">IPD.</th>
                                    <th width="10" align="center" valign="top">UHID NO.</th>
                                    <!-- <th width="10" align="center" valign="top">Mrd.No</th> -->
                                    <th width="30" align="center" valign="top">Patient Name</th>
                                    <th width="15" align="center" valign="top">Age</th>
                                    <th width="15" align="center" valign="top">Gender</th>
                                    <th width="30" align="center" valign="top">Mobile</th>
                                    <th width="30" align="center" valign="top">Address</th>
                                </tr>
                                <tr>
                                    <th width="50" align="center" valign="top">
                                        <input type="text" class="form-control" placeholder="" id="DischargeId" name="DischargeId" readonly value="">
                                    </th>
                                    <th width="50" align="center" valign="top">
                                        <input type="text" class="form-control" placeholder="" id="IpdNoDisplay" name="IpdNoDisplay" readonly value="">
                                    </th>
                                    <th width="50" align="center" valign="top">
                                        <input type="text" class="form-control" placeholder="" id="UhidNo" name="UhidNo" value="">
                                    </th>
                                    <!-- <th width="50" align="center" valign="top">
                                        <input type="text" class="form-control" placeholder="" id="MrdNo" name="MrdNo" required value="">
                                    </th> -->
                                    <th width="100" align="center" valign="top">
                                        <input type="text" class="form-control" placeholder="" name="PatientName" id="PatientName" value="">
                                    </th>
                                    <th width="50" align="center" valign="top">
                                        <input type="text" class="form-control" placeholder="" id="Age" name="Age" value="">
                                    </th>
                                    <th width="50" align="center" valign="top">
                                        <select class="form-control" id="Gender" name="Gender" style="height: 31px;">
                                            <option value="">Select</option>
                                            <option value="Male">Male</option>
                                            <option value="Female">Female</option>
                                        </select>
                                    </th>
                                    <th width="100" align="center" valign="top">
                                        <input type="text" class="form-control" placeholder="" id="Phone" name="Mobile" value="">
                                    </th>
                                    <th width="100" align="center" valign="top">
                                        <input type="text" class="form-control" placeholder="" id="Address" name="Address" value="">
                                    </th>
                                </tr>
                            </thead>
                        </table>
                    </div>

                    <div class="col-md-12" style="padding-top: 7px;">
                        <table class="table table-bordered table-striped mb-0">
                            <thead>
                                <!-- Row 1: Wt. On Adm, DOA, TOA, Birth Date -->
                                <tr>
                                    <th width="15%" align="left" valign="middle">Wt. On Adm</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" id="WtOnAdm" name="WtOnAdm" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">DOA</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="date" name="AdmissionDate" class="form-control" id="AdmissionDate" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">TOA</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="time" name="AdmissionTime" class="form-control" id="AdmissionTime" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">Birth Date</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="date" name="BirthDate" class="form-control" id="BirthDate" value="" style="height: 31px;">
                                    </th>
                                </tr>
                                <!-- Row 2: Birth Wt., DOD, TOD, (empty) -->
                                <tr>
                                    <th width="15%" align="left" valign="middle">Birth Wt.</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" id="BirthWt" name="BirthWt" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">DOD</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="date" name="DischargeDate" class="form-control" id="DischargeDate" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">TOD</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="time" name="DischargeTime" class="form-control" id="DischargeTime" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle"></th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" value="" style="height: 31px;" readonly>
                                    </th>
                                </tr>
                                <!-- Row 3: Consultant Name, Parent Occupation, Ventilation, Oxygen -->
                                <tr>
                                    <th width="15%" align="left" valign="middle">Consultant Name</th>
                                    <th width="10%" align="center" valign="middle">
                                        <select class="form-control" id="ConsultantName" name="ConsultantName" style="height: 31px;">
                                            <option value="">Select Consultant</option>
                                            <?php $__currentLoopData = $consultantList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $consultant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($consultant->id); ?>"><?php echo e($consultant->Name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </th>
                                    <th width="15%" align="left" valign="middle">Parent Occupation</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" id="ParentOccupation" name="ParentOccupation" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">Ventilation</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" id="Ventilation" name="Ventilation" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">Oxygen</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" id="Oxygen" name="Oxygen" value="" style="height: 31px;">
                                    </th>
                                </tr>
                                <!-- Row 4: Head Circumference, Height, Blood Group, (empty) -->
                                <tr>
                                    <th width="15%" align="left" valign="middle">Head Circumference</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" id="HeadCircumference" name="HeadCircumference" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">Height</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" id="Height" name="Height" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">Blood Group</th>
                                    <th width="10%" align="center" valign="middle">
                                        <select class="form-control" id="BloodGroup" name="BloodGroup" style="height: 31px;">
                                            <option value="">Select</option>
                                            <option value="A+">A+</option>
                                            <option value="A-">A-</option>
                                            <option value="B+">B+</option>
                                            <option value="B-">B-</option>
                                            <option value="AB+">AB+</option>
                                            <option value="AB-">AB-</option>
                                            <option value="O+">O+</option>
                                            <option value="O-">O-</option>
                                        </select>
                                    </th>
                                    <th width="15%" align="left" valign="middle"></th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" value="" style="height: 31px;" readonly>
                                    </th>
                                </tr>
                                <!-- Row 5: Wt. On Discharge, Mother Blood Group, Contact to Doctor, Mode Of Delivery -->
                                <tr>
                                    <th width="15%" align="left" valign="middle">Wt. On Discharge</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" class="form-control" placeholder="" id="WtOnDischarge" name="WtOnDischarge" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">Mother Blood Group</th>
                                    <th width="10%" align="center" valign="middle">
                                        <select class="form-control" id="MotherBloodGroup" name="MotherBloodGroup" style="height: 31px;">
                                            <option value="">Select</option>
                                            <option value="A+">A+</option>
                                            <option value="A-">A-</option>
                                            <option value="B+">B+</option>
                                            <option value="B-">B-</option>
                                            <option value="AB+">AB+</option>
                                            <option value="AB-">AB-</option>
                                            <option value="O+">O+</option>
                                            <option value="O-">O-</option>
                                        </select>
                                    </th>
                                    <th width="15%" align="left" valign="middle">Contact to Doctor</th>
                                    <th width="10%" align="center" valign="middle">
                                        <select class="form-control" id="ContactToDoctor" name="ContactToDoctor" style="height: 31px;">
                                            <option value="">Select Doctor</option>
                                            <?php $__currentLoopData = $consultantList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $consultant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($consultant->id); ?>"><?php echo e($consultant->Name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </th>
                                    <th width="15%" align="left" valign="middle">Mode Of Delivery</th>
                                    <th width="10%" align="center" valign="middle">
                                        <select class="form-control" id="ModeOfDelivery" name="ModeOfDelivery" style="height: 31px;">
                                            <option value="">Select</option>
                                            <option value="Normal">Normal</option>
                                            <option value="C-Section">C-Section</option>
                                            <option value="Forceps">Forceps</option>
                                            <option value="Vacuum">Vacuum</option>
                                        </select>
                                    </th>
                                </tr>
                                <!-- Row 6: Maternal Risk Factor, Date of Operation, Follow up Date, Time -->
                                <tr>
                                    <th width="15%" align="left" valign="middle">Maternal Risk Factor</th>
                                    <th width="10%" align="center" valign="middle">
                                        <select class="form-control" id="MaternalRiskFactor" name="MaternalRiskFactor" style="height: 31px;">
                                            <option value="">Select</option>
                                            <option value="Diabetes">Diabetes</option>
                                            <option value="Hypertension">Hypertension</option>
                                            <option value="Pre-eclampsia">Pre-eclampsia</option>
                                            <option value="None">None</option>
                                        </select>
                                    </th>
                                    <th width="15%" align="left" valign="middle">Date of Operation</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="date" name="OperationDate" id="OperationDate" class="form-control" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">Follow up Date</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="date" name="FollowUpDate1" class="form-control" id="FollowUpDate1" value="" style="height: 31px;">
                                    </th>
                                    <th width="15%" align="left" valign="middle">Time</th>
                                    <th width="10%" align="center" valign="middle">
                                        <input type="text" name="CreatedTime" class="form-control" id="CreatedTime" value="" style="height: 31px;">
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="row">
                    <div class="col-lg-6">
                        <div class="row">
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Chief Complaints</legend>
                                    <div class="row">
                                        <div class="col-lg-10">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="ChiefComplaints" id="ChiefComplaints" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-2">
                                            <span class="input-group-append">
                                                <button class="btn btn-secondary" type="button" data-toggle="modal"
                                                    data-target="#modal-report" id="add_button"
                                                    onclick="getValue('ChiefComplaints','ChiefComplaints')">...</button>
                                                
                                            </span>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Birth History</legend>
                                    <div class="row">
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="BirthHistory" id="BirthHistory" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <label>Past History</label>
                                                <textarea class="form-control" placeholder="" name="PastHistory" id="PastHistory" rows="2"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Family History</legend>
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="FamilyHistory" id="FamilyHistory" rows="2"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Reason of Adm.</legend>
                                    <div class="row">
                                        <div class="col-lg-10">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="ReasonOfAdm" id="ReasonOfAdm" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-2">
                                            <span class="input-group-append">
                                                <button class="btn btn-secondary" type="button" data-toggle="modal"
                                                    data-target="#modal-report" id="add_button"
                                                    onclick="getValue('ReasonOfAdm','ReasonOfAdm')">...</button>
                                                
                                            </span>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Immunization History</legend>
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="ImmunizationHistory" id="ImmunizationHistory" rows="2"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Dev. History</legend>
                                    <div class="row">
                                        <div class="col-lg-10">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="DevHistory" id="DevHistory" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-2">
                                            <span class="input-group-append">
                                                <button class="btn btn-secondary" type="button" data-toggle="modal"
                                                    data-target="#modal-report" id="add_button"
                                                    onclick="getValue('DevHistory','DevHistory')">...</button>
                                                
                                            </span>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Course During Admission</legend>
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="CourseDuringAdmission" id="CourseDuringAdmission" rows="2"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Condition on Adm.</legend>
                                    <div class="row">
                                        <div class="col-lg-10">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="ConditionOnAdm" id="ConditionOnAdm" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-2">
                                            <span class="input-group-append">
                                                <button class="btn btn-secondary" type="button" data-toggle="modal"
                                                    data-target="#modal-report" id="add_button"
                                                    onclick="getValue('ConditionOnAdm','ConditionOnAdm')">...</button>
                                                
                                            </span>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Procedure Done</legend>
                                    <div class="row">
                                        <div class="col-lg-10">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="ProcedureDone" id="ProcedureDone" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-2">
                                            <span class="input-group-append">
                                                <button class="btn btn-secondary" type="button" data-toggle="modal"
                                                    data-target="#modal-report" id="add_button"
                                                    onclick="getValue('ProcedureDone','ProcedureDone')">...</button>
                                                
                                            </span>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Treatment Given</legend>
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="TreatmentGiven" id="TreatmentGiven" rows="2"></textarea>
                                            </div>
                                        </div>
                                        
                                    </div>
                                </fieldset>
                            </div>





                        </div>
                    </div>


                    <div class="col-lg-6">
                        <div class="row">
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Diagnosis</legend>
                                    <div class="row">
                                        <div class="col-lg-10">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="Search for..."
                                                    name="Diagnosis" id="Diagnosis" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-2">
                                            <span class="input-group-append">
                                                <button class="btn btn-secondary" type="button" data-toggle="modal"
                                                    data-target="#modal-report" id="add_button"
                                                    onclick="getValue('Diagnosis','Diagnosis')">...</button>
                                                
                                            </span>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Condition On Discharge</legend>
                                    <div class="row">
                                        <div class="col-lg-10">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="CondDischarge" id="CondDischarge" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-2">
                                            <span class="input-group-append">
                                                <button class="btn btn-secondary" type="button" data-toggle="modal"
                                                    data-target="#modal-report" id="add_button"
                                                    onclick="getValue('CondDischarge','CondDischarge')">...</button>
                                                
                                            </span>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Investigation Done</legend>
                                    <div class="row">
                                        <div class="col-lg-10">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="InvestigationDone" id="InvestigationDone" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-2">
                                            <span class="input-group-append">
                                                <button class="btn btn-secondary" type="button" data-toggle="modal"
                                                    data-target="#modal-report" id="add_button"
                                                    onclick="getValue('InvestigationDone','InvestigationDone')">...</button>
                                                
                                            </span>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset style="padding-bottom: 0px;">
                                    <legend>Special Advice</legend>
                                    <div class="row">
                                        <div class="col-lg-10">
                                            <div class="form-group">
                                                <textarea class="form-control" placeholder="" name="SpecialAdvice" id="SpecialAdvice" rows="2"></textarea>
                                            </div>
                                        </div>
                                        <div class="col-lg-2">
                                            <span class="input-group-append">
                                                <button class="btn btn-secondary" type="button" data-toggle="modal"
                                                    data-target="#modal-report" id="add_button"
                                                    onclick="getValue('SpecialAdvice','SpecialAdvice')">...</button>
                                                
                                            </span>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset>
                                    <legend>Investigation</legend>
                                    <div class="row">
                                        <table class="table table-bordered table-striped mb-0">
                                            <thead>

                                                <tr>
                                                    <th width="50" align="center" valign="top">B.S</th>

                                                    <th width="113" align="center" valign="top"><input type="text"
                                                            name="txtbsfasting" id="txtbsfasting" class="form-control"
                                                            placeholder="" value="">
                                                        <div class="clearfix"></div>
                                                        </td>
                                                    </th>
                                                    <th width="50" align="center" valign="top">U.S </th>

                                                    <th width="105" align="center" valign="top"><input type="text"
                                                            name="txtusfasting" id="txtusfasting" class="form-control"
                                                            placeholder="" value="">
                                                        <div class="clearfix"></div>
                                                        </td>
                                                    </th>

                                                    <th width="50" align="center" valign="top">B.P </th>
                                                    <th width="129" align="center" valign="top"><input type="text"
                                                            name="txtbp" id="txtbp" class="form-control" placeholder=""
                                                            value="">
                                                        <div class="clearfix"></div>
                                                        </td>
                                                    </th>
                                                </tr>

                                            </thead>
                                            <thead>

                                                <tr>
                                                    <th width="50" align="center" valign="top">IOP</th>

                                                    <th width="113" align="center" valign="top"><input type="text"
                                                            name="IopRe" id="IopRe" class="form-control" placeholder=""
                                                            value="">
                                                        <div class="clearfix"></div>
                                                        </td>
                                                    </th>
                                                    <th width="113" align="center" valign="top"><input type="text"
                                                            name="IopLe" id="IopLe" class="form-control" placeholder=""
                                                            value="">
                                                        <div class="clearfix"></div>
                                                        </td>
                                                    </th>
                                                    <th width="50" align="center" valign="top">IOL Power</th>

                                                    <th width="105" align="center" valign="top"><input type="text"
                                                            name="IolPowerRe" id="IolPowerRe" class="form-control"
                                                            placeholder="" value="">
                                                        <div class="clearfix"></div>
                                                        </td>
                                                    </th>


                                                    <th width="129" align="center" valign="top"><input type="text"
                                                            name="IolPowerLe" id="IolPowerLe" class="form-control"
                                                            placeholder="" value="">
                                                        <div class="clearfix"></div>
                                                        </td>
                                                    </th>
                                                </tr>

                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                    </div>


                                </fieldset>
                            </div>

                            <div class="col-md-12" style="margin-bottom: 8px;">
                                <fieldset>
                                    <legend>TREATMENT</legend>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <label>Discharge Card Type</label>
                                            <input type="text" class="form-control" id="DischargeCardType" name="DischargeCardType" value="">
                                        </div>
                                        <div class="col-md-6">
                                            <label>Language</label>
                                            <select class="form-control" id="Language" name="Language" style="height: 31px;">
                                                <option value="Marathi" selected>MARATHI</option>
                                                <option value="English">ENGLISH</option>
                                                <option value="Hindi">HINDI</option>
                                            </select>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>

                            <div class="col-md-12" style="margin-bottom: 10px;">
                                <?php echo $__env->make('ipd/inctreatments', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                            </div>

                        </div>

                    </div>
                </div>
            </div>



            <input type="hidden" id="CurrDate" value="<?php echo e(date('Y-m-d')); ?>">

            <div class="row" style="margin-top: 15px; margin-bottom: 15px;">
                <div class="col-md-12">
                    <div style="text-align: center; padding: 10px;">
                        <button class="btn btn-primary" type="submit" name="submit" id="submit">Save</button>
                        <button class="btn btn-success" onclick="printOt()" id="printbtn" type="button" disabled>Print</button>
                        <button class="btn btn-info" type="button" onclick="location.reload()">Refresh</button>
                        <button class="btn btn-warning" type="button" id="deletebtn" disabled>Delete</button>
                        <button class="btn btn-secondary" type="button" id="copybtn">Copy</button>
                        <button class="btn btn-secondary" type="button" id="pastebtn">Paste</button>
                        <button class="btn btn-dark" type="button" onclick="window.close()">Exit</button>
                    </div>
                </div>
            </div>

    </form>
</div>
</div>
</div>
<!-- [ Layout content ] Start -->

</div>
<!-- [ Layout container ] End -->

</div>
<!-- Overlay -->

<div class="layout-overlay layout-sidenav-toggle"></div>
</div>
<script src="<?php echo e(url('assets/js/jquery-3.6.0.min.js')); ?>"></script>
<?php echo $__env->make('masters/inccommonmodal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('footerscript', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<script>
   function checkTap(previd,id){
    var PrevTreatDate = $('#TreatDate'+previd).val();
        var TreatDate = $('#TreatDate'+id).val();
            var TreatDur = $('#TreatDur'+id).val();
            //console.log(TreatDate,TreatDur);
        if($('#Tapchk'+id).prop('checked') == true) {
            $.ajax({
        url: "<?php echo e(url('getTapDate')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            TreatDate: TreatDate,
            TreatDur:TreatDur,
            PrevTreatDate:PrevTreatDate
        },
        success: function(data) {
            $('#TreatDate'+id).val(data);
            console.log(data);
        }
    });
        }
        else{
            $.ajax({
        url: "<?php echo e(url('getUnchkTapDate')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            TreatDate: TreatDate,
            TreatDur:TreatDur
        },
        success: function(data) {
            $('#TreatDate'+id).val(data);
            console.log(data);
        }
    });
            }
        }
       
    function getTreatDate(id,val){
        //alert(id);alert(val);
        $.ajax({
        url: "<?php echo e(url('getTreatDate')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            val: val
        },
        success: function(data) {
            //console.log(data);
            $('#TreatDate'+id).val(data);
        }
    });
    }
function printOt() {
    var id = $('#saveid').val();
    setTimeout(function() {
        window.open(
            '/<?php echo e(projectUrl()); ?>printDischargeCard/' + id, 'popUpWindow2',
            'height=1000,width=750,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
        );
    }, 1);
}


function ipdBill() {
    var dcid = $('#saveid').val();
    var otid = $('#IpdNo').val();
    var mrdno = $('#MrdNo').val();
    setTimeout(function() {
        window.open(
            '/<?php echo e(projectUrl()); ?>addIpdBill2/' + mrdno + '/' + otid + '/' + dcid, 'popUpWindow4',
            'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
        );
    }, 1);
}

function ipdReceipt() {
    var otid = $('#IpdNo').val();
    var mrdno = $('#MrdNo').val();
    setTimeout(function() {
        window.open(
            '/<?php echo e(projectUrl()); ?>addIpdReceipt/' + mrdno + '/' + otid, 'popUpWindow5',
            'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
        );
    }, 1);
}
function getValue(val, idval) {
    $('#ModalValue').val(val);
    $('#ValueId').val(idval);
    $('#OldValue').val('');
    $('#search_text77').val('');
    $('#Ref_By').focus();
    desc_lists(val);
}


function getRecords(val) {
    $.ajax({
        url: "<?php echo e(url('getTreatments2')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            Treatment: val
        },
        success: function(data) {
            console.log(data);
            $('#showTreatments').html(data);
        }
    });
}

function getPatientTreatment(val) {
    $.ajax({
        url: "<?php echo e(url('getPatientTreatment')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            id: val
        },
        success: function(data) {
            console.log(data);
            var res = JSON.parse(data);
            var result = res.data;
            var Diagnosis = res.Diagnosis;
            $('#Diagnosis').val(Diagnosis);
            $('#Treatment').val(result.Treatment);
            if (result.TreatChk1 == 1) {
                $('#TreatChk1').prop("checked", true);
            } else {
                $('#TreatChk1').prop("checked", false);
            }
            $('#TreatType1').val(result.TreatType1);
            $('#TreatName1').val(result.TreatName1);
            $('#TreatDose1').val(result.TreatDose1);
            $('#TreatFreq1').val(result.TreatFreq1);
            $('#TreatDur1').val(result.TreatDur1);
            $('#TreatEye1').val(result.TreatEye1);
            $('#TreatDate1').val(result.TreatDate1);
            if (result.Tapchk1 == 1) {
                $('#Tapchk1').prop("checked", true);
            } else {
                $('#Tapchk1').prop("checked", false);
            }


            if (result.TreatChk2 == 1) {
                $('#TreatChk2').prop("checked", true);
            } else {
                $('#TreatChk2').prop("checked", false);
            }
            $('#TreatType2').val(result.TreatType2);
            $('#TreatName2').val(result.TreatName2);
            $('#TreatDose2').val(result.TreatDose2);
            $('#TreatFreq2').val(result.TreatFreq2);
            $('#TreatDur2').val(result.TreatDur2);
            $('#TreatEye2').val(result.TreatEye2);
            $('#TreatDate2').val(result.TreatDate2);
            if (result.Tapchk2 == 1) {
                $('#Tapchk2').prop("checked", true);
            } else {
                $('#Tapchk2').prop("checked", false);
            }

            if (result.TreatChk3 == 1) {
                $('#TreatChk3').prop("checked", true);
            } else {
                $('#TreatChk3').prop("checked", false);
            }
            $('#TreatType3').val(result.TreatType3);
            $('#TreatName3').val(result.TreatName3);
            $('#TreatDose3').val(result.TreatDose3);
            $('#TreatFreq3').val(result.TreatFreq3);
            $('#TreatDur3').val(result.TreatDur3);
            $('#TreatEye3').val(result.TreatEye3);
            $('#TreatDate3').val(result.TreatDate3);
            if (result.Tapchk3 == 1) {
                $('#Tapchk3').prop("checked", true);
            } else {
                $('#Tapchk3').prop("checked", false);
            }

            if (result.TreatChk4 == 1) {
                $('#TreatChk4').prop("checked", true);
            } else {
                $('#TreatChk4').prop("checked", false);
            }
            $('#TreatType4').val(result.TreatType4);
            $('#TreatName4').val(result.TreatName4);
            $('#TreatDose4').val(result.TreatDose4);
            $('#TreatFreq4').val(result.TreatFreq4);
            $('#TreatDur4').val(result.TreatDur4);
            $('#TreatEye4').val(result.TreatEye4);
            $('#TreatDate4').val(result.TreatDate4);
            if (result.Tapchk4 == 1) {
                $('#Tapchk4').prop("checked", true);
            } else {
                $('#Tapchk4').prop("checked", false);
            }

            if (result.TreatChk5 == 1) {
                $('#TreatChk5').prop("checked", true);
            } else {
                $('#TreatChk5').prop("checked", false);
            }
            $('#TreatType5').val(result.TreatType5);
            $('#TreatName5').val(result.TreatName5);
            $('#TreatDose5').val(result.TreatDose5);
            $('#TreatFreq5').val(result.TreatFreq5);
            $('#TreatDur5').val(result.TreatDur5);
            $('#TreatEye5').val(result.TreatEye5);
            $('#TreatDate5').val(result.TreatDate5);
            if (result.Tapchk5 == 1) {
                $('#Tapchk5').prop("checked", true);
            } else {
                $('#Tapchk5').prop("checked", false);
            }

            if (result.TreatChk6 == 1) {
                $('#TreatChk6').prop("checked", true);
            } else {
                $('#TreatChk6').prop("checked", false);
            }
            $('#TreatType6').val(result.TreatType6);
            $('#TreatName6').val(result.TreatName6);
            $('#TreatDose6').val(result.TreatDose6);
            $('#TreatFreq6').val(result.TreatFreq6);
            $('#TreatDur6').val(result.TreatDur6);
            $('#TreatEye6').val(result.TreatEye6);
            $('#TreatDate6').val(result.TreatDate6);
            if (result.Tapchk6 == 1) {
                $('#Tapchk6').prop("checked", true);
            } else {
                $('#Tapchk6').prop("checked", false);
            }

            if (result.TreatChk7 == 1) {
                $('#TreatChk7').prop("checked", true);
            } else {
                $('#TreatChk7').prop("checked", false);
            }
            $('#TreatType7').val(result.TreatType7);
            $('#TreatName7').val(result.TreatName7);
            $('#TreatDose7').val(result.TreatDose7);
            $('#TreatFreq7').val(result.TreatFreq7);
            $('#TreatDur7').val(result.TreatDur7);
            $('#TreatEye7').val(result.TreatEye7);
            $('#TreatDate7').val(result.TreatDate7);
            if (result.Tapchk7 == 1) {
                $('#Tapchk7').prop("checked", true);
            } else {
                $('#Tapchk7').prop("checked", false);
            }

            if (result.TreatChk8 == 1) {
                $('#TreatChk8').prop("checked", true);
            } else {
                $('#TreatChk8').prop("checked", false);
            }
            $('#TreatType8').val(result.TreatType8);
            $('#TreatName8').val(result.TreatName8);
            $('#TreatDose8').val(result.TreatDose8);
            $('#TreatFreq8').val(result.TreatFreq8);
            $('#TreatDur8').val(result.TreatDur8);
            $('#TreatEye8').val(result.TreatEye8);
            $('#TreatDate8').val(result.TreatDate8);
            if (result.Tapchk8 == 1) {
                $('#Tapchk8').prop("checked", true);
            } else {
                $('#Tapchk8').prop("checked", false);
            }

            if (result.TreatChk9 == 1) {
                $('#TreatChk9').prop("checked", true);
            } else {
                $('#TreatChk9').prop("checked", false);
            }
            $('#TreatType9').val(result.TreatType9);
            $('#TreatName9').val(result.TreatName9);
            $('#TreatDose9').val(result.TreatDose9);
            $('#TreatFreq9').val(result.TreatFreq9);
            $('#TreatDur9').val(result.TreatDur9);
            $('#TreatEye9').val(result.TreatEye9);
            $('#TreatDate9').val(result.TreatDate9);
            if (result.Tapchk9 == 1) {
                $('#Tapchk9').prop("checked", true);
            } else {
                $('#Tapchk9').prop("checked", false);
            }

            if (result.TreatChk10 == 1) {
                $('#TreatChk10').prop("checked", true);
            } else {
                $('#TreatChk10').prop("checked", false);
            }
            $('#TreatType10').val(result.TreatType10);
            $('#TreatName10').val(result.TreatName10);
            $('#TreatDose10').val(result.TreatDose10);
            $('#TreatFreq10').val(result.TreatFreq10);
            $('#TreatDur10').val(result.TreatDur10);
            $('#TreatEye10').val(result.TreatEye10);
            $('#TreatDate10').val(result.TreatDate10);
            if (result.Tapchk10 == 1) {
                $('#Tapchk10').prop("checked", true);
            } else {
                $('#Tapchk10').prop("checked", false);
            }
        }
    });
}


function getPatientTreatment2(val) {
    $.ajax({
        url: "<?php echo e(url('getPatientTreatment2')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            id: val
        },
        success: function(data) {
            //console.log(data);
            var res = JSON.parse(data);
            var result = res.data;
            //var Diagnosis = res.Diagnosis;
            //$('#Diagnosis').val(Diagnosis);
            $('#Treatment').val(result.Treatment);
            if (result.TreatChk1 == 1) {
                $('#TreatChk1').prop("checked", true);
            } else {
                $('#TreatChk1').prop("checked", false);
            }
            $('#TreatType1').val(result.TreatType1);
            $('#TreatName1').val(result.TreatName1);
            $('#TreatDose1').val(result.TreatDose1);
            $('#TreatFreq1').val(result.TreatFreq1);
            $('#TreatDur1').val(result.TreatDur1);
            $('#TreatEye1').val(result.TreatEye1);
            $('#TreatDate1').val(result.TreatDate1);
            if (result.Tapchk1 == 1) {
                $('#Tapchk1').prop("checked", true);
            } else {
                $('#Tapchk1').prop("checked", false);
            }


            if (result.TreatChk2 == 1) {
                $('#TreatChk2').prop("checked", true);
            } else {
                $('#TreatChk2').prop("checked", false);
            }
            $('#TreatType2').val(result.TreatType2);
            $('#TreatName2').val(result.TreatName2);
            $('#TreatDose2').val(result.TreatDose2);
            $('#TreatFreq2').val(result.TreatFreq2);
            $('#TreatDur2').val(result.TreatDur2);
            $('#TreatEye2').val(result.TreatEye2);
            $('#TreatDate2').val(result.TreatDate2);
            if (result.Tapchk2 == 1) {
                $('#Tapchk2').prop("checked", true);
            } else {
                $('#Tapchk2').prop("checked", false);
            }

            if (result.TreatChk3 == 1) {
                $('#TreatChk3').prop("checked", true);
            } else {
                $('#TreatChk3').prop("checked", false);
            }
            $('#TreatType3').val(result.TreatType3);
            $('#TreatName3').val(result.TreatName3);
            $('#TreatDose3').val(result.TreatDose3);
            $('#TreatFreq3').val(result.TreatFreq3);
            $('#TreatDur3').val(result.TreatDur3);
            $('#TreatEye3').val(result.TreatEye3);
            $('#TreatDate3').val(result.TreatDate3);
            if (result.Tapchk3 == 1) {
                $('#Tapchk3').prop("checked", true);
            } else {
                $('#Tapchk3').prop("checked", false);
            }

            if (result.TreatChk4 == 1) {
                $('#TreatChk4').prop("checked", true);
            } else {
                $('#TreatChk4').prop("checked", false);
            }
            $('#TreatType4').val(result.TreatType4);
            $('#TreatName4').val(result.TreatName4);
            $('#TreatDose4').val(result.TreatDose4);
            $('#TreatFreq4').val(result.TreatFreq4);
            $('#TreatDur4').val(result.TreatDur4);
            $('#TreatEye4').val(result.TreatEye4);
            $('#TreatDate4').val(result.TreatDate4);
            if (result.Tapchk4 == 1) {
                $('#Tapchk4').prop("checked", true);
            } else {
                $('#Tapchk4').prop("checked", false);
            }

            if (result.TreatChk5 == 1) {
                $('#TreatChk5').prop("checked", true);
            } else {
                $('#TreatChk5').prop("checked", false);
            }
            $('#TreatType5').val(result.TreatType5);
            $('#TreatName5').val(result.TreatName5);
            $('#TreatDose5').val(result.TreatDose5);
            $('#TreatFreq5').val(result.TreatFreq5);
            $('#TreatDur5').val(result.TreatDur5);
            $('#TreatEye5').val(result.TreatEye5);
            $('#TreatDate5').val(result.TreatDate5);
            if (result.Tapchk5 == 1) {
                $('#Tapchk5').prop("checked", true);
            } else {
                $('#Tapchk5').prop("checked", false);
            }

            if (result.TreatChk6 == 1) {
                $('#TreatChk6').prop("checked", true);
            } else {
                $('#TreatChk6').prop("checked", false);
            }
            $('#TreatType6').val(result.TreatType6);
            $('#TreatName6').val(result.TreatName6);
            $('#TreatDose6').val(result.TreatDose6);
            $('#TreatFreq6').val(result.TreatFreq6);
            $('#TreatDur6').val(result.TreatDur6);
            $('#TreatEye6').val(result.TreatEye6);
            $('#TreatDate6').val(result.TreatDate6);
            if (result.Tapchk6 == 1) {
                $('#Tapchk6').prop("checked", true);
            } else {
                $('#Tapchk6').prop("checked", false);
            }

            if (result.TreatChk7 == 1) {
                $('#TreatChk7').prop("checked", true);
            } else {
                $('#TreatChk7').prop("checked", false);
            }
            $('#TreatType7').val(result.TreatType7);
            $('#TreatName7').val(result.TreatName7);
            $('#TreatDose7').val(result.TreatDose7);
            $('#TreatFreq7').val(result.TreatFreq7);
            $('#TreatDur7').val(result.TreatDur7);
            $('#TreatEye7').val(result.TreatEye7);
            $('#TreatDate7').val(result.TreatDate7);
            if (result.Tapchk7 == 1) {
                $('#Tapchk7').prop("checked", true);
            } else {
                $('#Tapchk7').prop("checked", false);
            }

            if (result.TreatChk8 == 1) {
                $('#TreatChk8').prop("checked", true);
            } else {
                $('#TreatChk8').prop("checked", false);
            }
            $('#TreatType8').val(result.TreatType8);
            $('#TreatName8').val(result.TreatName8);
            $('#TreatDose8').val(result.TreatDose8);
            $('#TreatFreq8').val(result.TreatFreq8);
            $('#TreatDur8').val(result.TreatDur8);
            $('#TreatEye8').val(result.TreatEye8);
            $('#TreatDate8').val(result.TreatDate8);
            if (result.Tapchk8 == 1) {
                $('#Tapchk8').prop("checked", true);
            } else {
                $('#Tapchk8').prop("checked", false);
            }

            if (result.TreatChk9 == 1) {
                $('#TreatChk9').prop("checked", true);
            } else {
                $('#TreatChk9').prop("checked", false);
            }
            $('#TreatType9').val(result.TreatType9);
            $('#TreatName9').val(result.TreatName9);
            $('#TreatDose9').val(result.TreatDose9);
            $('#TreatFreq9').val(result.TreatFreq9);
            $('#TreatDur9').val(result.TreatDur9);
            $('#TreatEye9').val(result.TreatEye9);
            $('#TreatDate9').val(result.TreatDate9);
            if (result.Tapchk9 == 1) {
                $('#Tapchk9').prop("checked", true);
            } else {
                $('#Tapchk9').prop("checked", false);
            }

            if (result.TreatChk10 == 1) {
                $('#TreatChk10').prop("checked", true);
            } else {
                $('#TreatChk10').prop("checked", false);
            }
            $('#TreatType10').val(result.TreatType10);
            $('#TreatName10').val(result.TreatName10);
            $('#TreatDose10').val(result.TreatDose10);
            $('#TreatFreq10').val(result.TreatFreq10);
            $('#TreatDur10').val(result.TreatDur10);
            $('#TreatEye10').val(result.TreatEye10);
            $('#TreatDate10').val(result.TreatDate10);
            if (result.Tapchk10 == 1) {
                $('#Tapchk10').prop("checked", true);
            } else {
                $('#Tapchk10').prop("checked", false);
            }
        }
    });
}

function getPatientDetails(val) {
    $.ajax({
        url: "<?php echo e(url('getPatientDetails')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            id: val
        },
        dataType: "json",
        success: function(data) {
            var AgeGender = data.Age + "/" + data.Gender;
            $('#MrdNo').val(data.MrdNo);
            $('#PatientName').val(data.PatientName);
            $('#Age').val(data.Age);
            $('#Gender').val(data.Gender);
            $('#AgeGender').val(AgeGender);
            $('#Phone').val(data.Phone);
            $('#Address').val(data.Address);
            if(data.UhidNo) $('#UhidNo').val(data.UhidNo);
            if(data.Weight) $('#WtOnAdm').val(data.Weight);
            if(data.Height) $('#Height').val(data.Height);
            if(data.BloodGroup) $('#BloodGroup').val(data.BloodGroup);
            if(data.BirthDate) $('#BirthDate').val(data.BirthDate);
            getPatientTreatment(data.MrdNo);
        }
    });
}

function checkDcPatient(val) {
    var CurrDate = $('#CurrDate').val();
    $.ajax({
        url: "<?php echo e(url('checkDcPatient2')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            id: val
        },
        success: function(data) {
            var res = JSON.parse(data);
            var Status = res.Status;
            var result = res.result;
            console.log('Discharge Card Data:', result);
            console.log('ChiefComplaints:', result ? result.ChiefComplaints : 'N/A');
            if (Status == 0) {
                getPatientDetails(val);
                $('#actionvalue').val('Save');
                $('#saveid').val('');
                $('#printbtn').attr("disabled", true);
                $('#billbtn').attr("disabled", true);
                $('#receiptbtn').attr("disabled", true);
                $('#deletebtn').attr("disabled", true);
                //$('#cmbtreateye').val('').attr("selected",true);
                $('#IpdNo').val('');
                $('#IpdNoDisplay').val('');
                $('#DischargeId').val('');
                $('#MrdNo').val('');
                $('#UhidNo').val('');
                $('#PatientName').val('');
                $('#Age').val('');
                $('#Gender').val('');
                $('#AgeGender').val('');
                $('#Mobile').val('');
                $('#Address').val('');
                $('#WtOnAdm').val('');
                $('#AdmissionDate').val(CurrDate);
                $('#AdmissionTime').val('');
                $('#OperationDate').val(CurrDate);
                $('#OperationTime').val('');
                $('#DischargeDate').val(CurrDate);
                $('#DischargeTime').val('');
                $('#BirthDate').val('');
                $('#BirthWt').val('');
                $('#FollowUpDate1').val('');
                $('#ConsultantName').val('');
                $('#ParentOccupation').val('');
                $('#Ventilation').val('');
                $('#Oxygen').val('');
                $('#HeadCircumference').val('');
                $('#Height').val('');
                $('#BloodGroup').val('');
                $('#WtOnDischarge').val('');
                $('#MotherBloodGroup').val('');
                $('#ContactToDoctor').val('');
                $('#ModeOfDelivery').val('');
                $('#MaternalRiskFactor').val('');
                $('#ChiefComplaints').val('');
                $('#BirthHistory').val('');
                $('#PastHistory').val('');
                $('#FamilyHistory').val('');
                $('#ImmunizationHistory').val('');
                $('#CourseDuringAdmission').val('');
                $('#ConditionOnAdm').val('');
                $('#ProcedureDone').val('');
                $('#TreatmentGiven').val('');
                $('#Diagnosis').val('');
                $('#CondDischarge').val('');
                $('#ReasonOfAdm').val('');
                $('#DevHistory').val('');
                $('#InvestigationDone').val('');
                $('#SpecialAdvice').val('');
                $('#SurgeryPerformed').val('');
                $('#cmbbsrandom').val('');
                $('#txtbsfasting').val('');
                $('#cmbusrandom').val('');
                $('#txtusfasting').val('');
                $('#cmbhbsag').val('');
                $('#txtbp').val('');
                $('#cmbbspostmeal').val('');
                $('#txtbspostmeal').val('');
                $('#cmbuspostmeal').val('');
                $('#txtuspostmeal').val('');
                $('#cmbecg').val('');
                $('#cmbhiv').val('');
                $('#txtfitnessby').val('');
                $('#txtother').val('');
                $('#IolPower').val('');
                $('#CylToric').val('');
                $('#Axis').val('');
                $('#Multifocal').val('');
                $('#Constant').val('');
                $('#IopRe').val('');
                $('#IopLe').val('');
                $('#OperationNotes').val('');
                $('#SlitLamp').val('');
                $('#txtremark').val('');
                $('#IolPowerRe').val('');
                $('#IolPowerLe').val('');
                $('#CreatedTime').val('');
                $('#DischargeStatus').val('');
                $('#PlaceOfDelivery').val('');
                $('#DischargeCardType').val('');
                $('#Language').val('Marathi');
                $('#StickerPrint').attr('checked',false);
            } else {
                $('#actionvalue').val('Edit');
                $('#printbtn').attr("disabled", false);
                $('#billbtn').attr("disabled", false);
                $('#receiptbtn').attr("disabled", false);
                $('#deletebtn').attr("disabled", false);
                $('#saveid').val(result.id);
                $('#DischargeId').val(result.id);
                $('#IpdNo').val(result.IpdNo);
                $('#IpdNoDisplay').val(result.IpdNo);
                $('#MrdNo').val(result.MrdNo);
                $('#UhidNo').val(result.UhidNo || '');
                $('#PatientName').val(result.PatientName);
                if(result.AgeGender) {
                    var ageGenderParts = result.AgeGender.split('/');
                    if(ageGenderParts.length >= 2) {
                        $('#Age').val(ageGenderParts[0].trim());
                        $('#Gender').val(ageGenderParts[1].trim());
                    }
                }
                $('#AgeGender').val(result.AgeGender);
                $('#Phone').val(result.Mobile);
                $('#Address').val(result.Address);
                $('#WtOnAdm').val(result.WtOnAdm || '');
                $('#OptEye').val(result.OptEye).attr("selected", true);
                $('#AdmissionDate').val(result.AdmissionDate);
                $('#AdmissionTime').val(result.AdmissionTime);
                $('#OperationDate').val(result.OperationDate);
                $('#OperationTime').val(result.OperationTime);
                $('#DischargeDate').val(result.DischargeDate);
                $('#DischargeTime').val(result.DischargeTime);
                $('#BirthDate').val(result.BirthDate || '');
                $('#BirthWt').val(result.BirthWt || '');
                $('#FollowUpDate1').val(result.FollowUpDate1 || '');
                $('#FollowUpDate2').val(result.FollowUpDate2 || '');
                $('#ConsultantName').val(result.ConsultantName || '');
                $('#ParentOccupation').val(result.ParentOccupation || '');
                $('#Ventilation').val(result.Ventilation || '');
                $('#Oxygen').val(result.Oxygen || '');
                $('#HeadCircumference').val(result.HeadCircumference || '');
                $('#Height').val(result.Height || '');
                $('#BloodGroup').val(result.BloodGroup || '');
                $('#WtOnDischarge').val(result.WtOnDischarge || '');
                $('#MotherBloodGroup').val(result.MotherBloodGroup || '');
                $('#ContactToDoctor').val(result.ContactToDoctor || '');
                $('#ModeOfDelivery').val(result.ModeOfDelivery || '');
                $('#MaternalRiskFactor').val(result.MaternalRiskFactor || '');
                $('#ChiefComplaints').val(result.ChiefComplaints || '');
                $('#BirthHistory').val(result.BirthHistory || '');
                $('#PastHistory').val(result.PastHistory || '');
                $('#FamilyHistory').val(result.FamilyHistory || '');
                $('#ImmunizationHistory').val(result.ImmunizationHistory || '');
                $('#CourseDuringAdmission').val(result.CourseDuringAdmission || '');
                $('#ConditionOnAdm').val(result.ConditionOnAdm || '');
                $('#ProcedureDone').val(result.ProcedureDone || '');
                $('#TreatmentGiven').val(result.TreatmentGiven || '');
                $('#Diagnosis').val(result.Diagnosis);
                $('#CondDischarge').val(result.CondDischarge);
                $('#ReasonOfAdm').val(result.ReasonOfAdm || '');
                $('#DevHistory').val(result.DevHistory || '');
                $('#InvestigationDone').val(result.InvestigationDone || '');
                $('#SpecialAdvice').val(result.SpecialAdvice || '');
                $('#OtNotes').val(result.OtNotes).attr("selected", true);
                $('#SurgeryPerformed').val(result.SurgeryPerformed);
                $('#cmbbsrandom').val(result.cmbbsrandom);
                $('#txtbsfasting').val(result.txtbsfasting);
                $('#cmbusrandom').val(result.cmbusrandom);
                $('#txtusfasting').val(result.txtusfasting);
                $('#cmbhbsag').val(result.cmbhbsag);
                $('#txtbp').val(result.txtbp);
                $('#cmbbspostmeal').val(result.cmbbspostmeal);
                $('#txtbspostmeal').val(result.txtbspostmeal);
                $('#cmbuspostmeal').val(result.cmbuspostmeal);
                $('#txtuspostmeal').val(result.txtuspostmeal);
                $('#cmbecg').val(result.cmbecg);
                $('#cmbhiv').val(result.cmbhiv);
                $('#txtfitnessby').val(result.txtfitnessby);
                $('#txtother').val(result.txtother);
                $('#IolPower').val(result.IolPower);
                $('#CylToric').val(result.CylToric);
                $('#Axis').val(result.Axis);
                $('#Multifocal').val(result.Multifocal);
                $('#Constant').val(result.Constant);
                $('#IopRe').val(result.IopRe);
                $('#IopLe').val(result.IopLe);
                $('#OperationNotes').val(result.OperationNotes);
                $('#SlitLamp').val(result.SlitLamp);
                $('#txtremark').val(result.txtremark);
                $('#IolPowerRe').val(result.IolPowerRe);
                $('#IolPowerLe').val(result.IolPowerLe);
                $('#CreatedTime').val(result.CreatedTime);
                $('#DischargeStatus').val(result.DischargeStatus || '');
                $('#PlaceOfDelivery').val(result.PlaceOfDelivery || '');
                $('#DischargeCardType').val(result.DischargeCardType || '');
                $('#Language').val(result.Language || 'Marathi');
                if(result.StickerPrint == 1){
                    $('#StickerPrint').attr('checked',true);
                }
                else{
                    $('#StickerPrint').attr('checked',false);
                }
                getPatientTreatment2(result.id);

            }
        }
    });
}

// UHID Input Timer
let uhidTimer;

// Clear patient fields function
function clearPatientFields() {
    $('#MrdNo').val('');
    $('#PatientName').val('');
    $('#Age').val('');
    $('#Gender').val('');
    $('#AgeGender').val('');
    $('#Phone').val('');
    $('#Address').val('');
    $('#UhidNo').val('');
    $('#WtOnAdm').val('');
    $('#Height').val('');
    $('#BloodGroup').val('');
    $('#BirthDate').val('');
}

// Fetch patient details by UHID
function fetchPatientDetailsByUhid(uhid) {
    $.ajax({
        url: "<?php echo e(url('getPatientDetails')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            id: uhid
        },
        dataType: "json",
        success: function(data) {
            if(data && data.MrdNo) {
                var AgeGender = data.Age + "/" + data.Gender;
                $('#MrdNo').val(data.MrdNo);
                $('#PatientName').val(data.PatientName);
                $('#Age').val(data.Age);
                $('#Gender').val(data.Gender);
                $('#AgeGender').val(AgeGender);
                $('#Phone').val(data.Phone);
                $('#Address').val(data.Address);
                if(data.UhidNo) $('#UhidNo').val(data.UhidNo);
                if(data.Weight) $('#WtOnAdm').val(data.Weight);
                if(data.Height) $('#Height').val(data.Height);
                if(data.BloodGroup) $('#BloodGroup').val(data.BloodGroup);
                if(data.BirthDate) $('#BirthDate').val(data.BirthDate);
                if(data.Dob) {
                    var birthDate = new Date(data.Dob);
                    var formattedDate = birthDate.getFullYear() + '-' + 
                        String(birthDate.getMonth() + 1).padStart(2, '0') + '-' + 
                        String(birthDate.getDate()).padStart(2, '0');
                    $('#BirthDate').val(formattedDate);
                }
                getPatientTreatment(data.MrdNo);
            } else {
                clearPatientFields();
            }
        },
        error: function() {
            clearPatientFields();
        }
    });
}

$(document).ready(function() {
    // UHID INPUT (DEBOUNCED)
    $(document).on("input", "#UhidNo", function () {
        clearTimeout(uhidTimer);
        let val = this.value.trim();

        uhidTimer = setTimeout(() => {
            if (!val) {
                clearPatientFields();
                return;
            }
            fetchPatientDetailsByUhid(val);
        }, 400);
    });

    $(document).on("input", "#Treatment", function(event) {
        var val = $(this).val();
        getRecords(val);
    });

    $(document).on("change", "#OptEye", function(event) {
        var eye = this.value;
        var val = $('#PatientId').val();
        checkDcPatient(val);
    });
    $(document).on("change", "#PatientId", function(event) {
        var val = this.value;
        //var eye = $('#OptEye').val();
        checkDcPatient(val);

    });

    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "<?php echo e(url('saveDischargeCard')); ?>",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit').attr('disabled', 'disabled');
                    $('#submit').text('Please Wait...');
                },
                success: function(data) {
                    if(typeof data === 'object' && data.error) {
                        alert('Error: ' + data.error);
                        $('#submit').attr('disabled', false);
                        $('#submit').text('Save');
                        return;
                    }
                    $('#actionvalue').val('Edit');
                    $('#saveid').val(data);
                    $('#printbtn').attr("disabled", false);
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Submit');
                    $('#billbtn').attr("disabled", false);
                    $('#receiptbtn').attr("disabled", false);
                    alert('Discharge card saved successfully!');
                },
                error: function(xhr, status, error) {
                    console.error('Error:', error);
                    console.error('Response:', xhr.responseText);
                    alert('Error saving discharge card: ' + (xhr.responseJSON?.error || error));
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Save');
                }
            });
        }

    });


    // $(document).on("change", "#PatientId", function(event) {
    //     var val = this.value;
    //     $.ajax({
    //         url: "<?php echo e(url('getPatientDetails')); ?>",
    //         method: "POST",
    //         data: {
    //             _token: '<?php echo e(csrf_token()); ?>',
    //             id: val
    //         },
    //         dataType: "json",
    //         success: function(data) {
    //             var AgeGender = data.Age + "/" + data.Gender;
    //             $('#MrdNo').val(data.MrdNo);
    //             $('#PatientName').val(data.PatientName);
    //             $('#AgeGender').val(AgeGender);
    //             $('#Phone').val(data.Phone);
    //             $('#Address').val(data.Address);
    //             getPatientTreatment(data.MrdNo);
    //         }
    //     });

    // });



});
</script><?php /**PATH C:\laragon\www\parijathosp\resources\views//ipd/add-dischargecard.blade.php ENDPATH**/ ?>