{if $type == "and_examination"}
<tr>
    <td>
        <input type="text" class="form-control datepicker updateElement" readonly="" placeholder="Date" data-colName="date" data-id="{$element->id}"  data-tableName="andexamination" value="{$element->date}"/>
    </td>
    <td>
        <table class="table table-striped table-hover table-bordered">
            <tr>
                <th style="width: 13%;">  </th>
                <th> Right </th>
                <th> Left </th>
            </tr>
            <tr>
                <th> Tests </th>
                <td>
                    <input type="text" class="form-control updateElement" placeholder="testes" data-colName="testesr" data-id="{$element->id}"  data-tableName="andexamination" value="{$element->testesr}">
                </td>
                <td>
                    <input type="text" class="form-control updateElement" placeholder="testes" data-colName="testesl" data-id="{$element->id}"  data-tableName="andexamination" value="{$element->testesl}">
                </td>
            </tr>
            <tr>
                <th> epid </th>
                <td>
                    <input type="text" class="form-control updateElement" placeholder="epid" data-colName="epidr" data-id="{$element->id}"  data-tableName="andexamination" value="{$element->epidr}">
                </td>
                <td>
                    <input type="text" class="form-control updateElement" placeholder="epid" data-colName="epidl" data-id="{$element->id}"  data-tableName="andexamination" value="{$element->epidl}">
                </td>
            </tr>
            <tr>
                <th> vas </th>
                <td>
                    <input type="text" class="form-control updateElement" placeholder="vas" data-colName="vasr" data-id="{$element->id}"  data-tableName="andexamination" value="{$element->vasr}">
                </td>
                <td>
                    <input type="text" class="form-control updateElement" placeholder="vas" data-colName="vasl" data-id="{$element->id}"  data-tableName="andexamination" value="{$element->vasl}">
                </td>
            </tr>
            <tr>
                <th> cord </th>
                <td>
                    <input type="text" class="form-control updateElement" placeholder="cord" data-colName="cordr" data-id="{$element->id}"  data-tableName="andexamination" value="{$element->cordr}">
                </td>
                <td>
                    <input type="text" class="form-control updateElement" placeholder="cord" data-colName="cordl" data-id="{$element->id}"  data-tableName="andexamination" value="{$element->cordl}">
                </td>
            </tr>
        </table>   
    </td>
    <td>
        <textarea class="form-control txtc updateElement" rows="3" data-colName="notes" data-id="{$element->id}"  data-tableName="andexamination" placeholder="Notes here ...." data-toggle="popover" data-trigger="hover" data-placement="bottom" data-content="{$element->notes}">{$element->notes}</textarea>
    </td>

    <td>
        <a class="btn grey-cascade btn-xs deletemsgEX" data-id="{$element->id}" style=" float: left;" href="#" data-link="and_examination" data-fn="del" data-tableName="andexamination">
            <i class="fa fa-close"></i>
        </a>
    </td>
    {if $ProgramesettingData->displaydoctorname eq 1}
    <td class="bold">
        {$element->doctorName}
    </td>
    {/if}
</tr>
<!----------------------------------------------------------------------------------------------------------------------------------------------------->
{else if $type == "general_history"}
<div>
    {if $ProgramesettingData->displaydoctorname eq 1}
    <div class="row ltr" >
        <div class="">
            <div class="">
                <label class="control-label col-md-2 ">{$element->doctorName}</label>
            </div>
        </div>
    </div>
    {/if}

    <div class="row ltr" >
        <div class="col-md-1">
            <div class="form-group form-md-line-input form-md-floating-label has-info">
                <input type="text" placeholder="marriage" class="form-control updateElement" data-colName="marriage"  data-id="{$element->id}" data-tableName="andhistory" value="{$element->marriage}"/>
                <!--<label for="menarche1">Menarche</label>-->
            </div>
        </div>
        <div class="col-md-1">
            <div class="form-group">
                <select class="form-control updateElement fertile " data-colName="fertile"  data-id="{$element->id}" data-tableName="andhistory" >
                    <option value="">choose</option>
                    <option value="1"> fertile  </option>
                    <option value="2"> infertile  </option>
                </select>
            </div>
        </div>
        <div class="col-md-1">
            <div class="form-group">
                <select class="form-control updateElement" style="display: none;"  id="fertiletype{$element->id}" data-colName="fertiletype"  data-id="{$element->id}" data-tableName="andhistory" >
                    <option value="">choose</option>
                    <option value="1"> primary  </option>
                    <option value="2"> secondary  </option>
                </select>
            </div>
        </div>
        <div class="col-md-3">
            <div class="form-group">
                <!--<label class="control-label col-md-2 ls2">Amount</label>-->

                <select class="form-control  updateElement  editSelect  durationid" name="durationid" id="durationid{$element->id}" data-val=""  data-colName="durationid" select-tableName="infertileduration"  data-id="{$element->id}" data-tableName="andhistory" >
                    <option value="">choose</option>
                    {foreach  $infertileduration as $data}
                    <option value="{$data->id}">{$data->name} </option>
                    {/foreach}
                    <option value="-2" class="deleteoptincompo">Delete</option>
                </select>
            </div>
        </div>
        <div class="col-md-1">
            <center>{$abortionCount} </center>
        </div>
        <div class="col-md-1">
            <div class="form-group">
                <select class="form-control updateElement" data-colName="trauma"  data-id="{$element->id}" data-tableName="andhistory" >
                    <option value="">choose</option>
                    <option value="1"> No  </option>
                    <option value="2"> Yes  </option>
                </select>
            </div>
        </div>
        <div class="col-md-1">
            <div class="form-group">
                <select class="form-control updateElement" data-colName="inflammation"  data-id="{$element->id}" data-tableName="andhistory" >
                    <option value="">choose</option>
                    <option value="1"> No  </option>
                    <option value="2"> Yes  </option>
                </select>
            </div>
        </div>
        <div class="col-md-1">
            <div class="form-group">
                <select class="form-control updateElement smoking" id="smoking{$element->id}"  data-colName="smoking"  data-id="{$element->id}" data-tableName="andhistory" >
                    <option value="">choose</option>
                    <option value="1"> No  </option>
                    <option value="2"> Yes  </option>
                </select>
            </div>
        </div>
        <div class="col-md-2">
            <div class="form-group">
                <select class="form-control updateElement"   id="smokinglevel{$element->id}"  data-colName="smokinglevel"  data-id="{$element->id}" data-tableName="andhistory" >
                    <option value="">choose</option>
                    <option value="1"> mild  </option>
                    <option value="2"> moderate  </option>
                    <option value="3"> seafarer  </option>
                </select>
                <button type="button" class="btn btn-xs red fright deleteElementDivs delbtnsml" data-id="{$element->id}" data-tableName="andhistory"><i class="fa fa-close"></i></button>
            </div>
        </div>
        <input type="hidden" id="newId" value="{$element->id}"/>

    </div></div>
<!----------------------------------------------------------------------------------------------------------------------------------------------------->
{else if $type == "mProblems"}
<div>
    {if $ProgramesettingData->displaydoctorname eq 1}
    <div class="row ltr" >
        <div class="">
            <div class="">
                <label class="control-label col-md-2 ">{$element->doctorName}</label>
            </div>
        </div>
    </div>
    {/if}

    <div class="row ltr" >
        <div class="col-md-3">
            <div class="form-group">
                <select class="form-control  updateElement  editSelect mdiseaseid" name="mdiseaseid" id="mdiseaseid{$element->id}" data-val=""  data-colName="diseaseid" select-tableName="medicaldisease"  data-id="{$element->id}" data-tableName="andmedicalproblems" >
                    <option value="">choose</option>
                    {foreach  $medicaldisease as $data}
                    <option value="{$data->id}">{$data->name} </option>
                    {/foreach}
                    <option value="-2" class="deleteoptincompo">Delete</option>
                </select>
            </div>
        </div>
        <div class="col-md-9">
            <div class="form-group form-md-line-input form-md-floating-label has-info">
                <div class="form-group form-md-line-input form-md-floating-label has-info">
                    <input type="text" class="amrpop form-control updateElement"  name="notes" data-colName="notes" placeholder="Note" value="{$element->notes}" data-id="{$element->id}" data-tableName="andmedicalproblems"/>
                </div>
                <button type="button" class="btn btn-xs red fright deleteElementDivs delbtnsml" data-id="{$element->id}" data-tableName="andhistory"><i class="fa fa-close"></i></button>
            </div>
        </div>
        <input type="hidden" id="newId1" value="{$element->id}"/>
    </div>
</div>
<!----------------------------------------------------------------------------------------------------------------------------------------------------->
{else if $type == "erection"}
<div>
    {if $ProgramesettingData->displaydoctorname eq 1}
    <div class="row ltr" >
        <div class="">
            <div class="">
                <label class="control-label col-md-2 ">{$element->doctorName}</label>
            </div>
        </div>
    </div>
    {/if}

    <div class="row ltr" >
        <div class="col-md-3">
            <div class="form-group">
                <select class="form-control  updateElement  editSelect erectiondiseaseid" name="erectiondiseaseid" id="erectiondiseaseid{$element->id}" data-val="{$element->diseaseid}"  data-colName="diseaseid" select-tableName="erectiondisease"  data-id="{$element->id}" data-tableName="anderection" >
                    <option value="">choose</option>
                    {foreach  $erectiondisease as $data}
                    <option value="{$data->id}">{$data->name} </option>
                    {/foreach}
                    <option value="-2" class="deleteoptincompo">Delete</option>
                </select>
            </div>
        </div>
        <div class="col-md-9">
            <div class="form-group form-md-line-input form-md-floating-label has-info">
                <div class="form-group form-md-line-input form-md-floating-label has-info">
                    <input type="text" class="amrpop form-control updateElement"  name="notes" data-colName="notes" placeholder="Note" value="{$element->notes}" data-id="{$element->id}" data-tableName="anderection"/>
                </div>
                <button type="button" class="btn btn-xs red fright deleteElementDivs delbtnsml" data-id="{$element->id}" data-tableName="anderection"><i class="fa fa-close"></i></button>
            </div>
        </div>
        <input type="hidden" id="newId2" value="{$element->id}"/>
    </div>

</div>
<!----------------------------------------------------------------------------------------------------------------------------------------------------->
{else if $type == "ejaculation"}
<div>
    {if $ProgramesettingData->displaydoctorname eq 1}
    <div class="row ltr" >
        <div class="">
            <div class="">
                <label class="control-label col-md-2 ">{$element->doctorName}</label>
            </div>
        </div>
    </div>
    {/if}

    <div class="row ltr" >
        <div class="col-md-3">
            <div class="form-group">
                <select class="form-control  updateElement  editSelect ejaculationdiseaseid" name="ejaculationdiseaseid" id="ejaculationdiseaseid{$element->id}" data-val="{$element->diseaseid}"  data-colName="diseaseid" select-tableName="ejaculationdisease"  data-id="{$element->id}" data-tableName="andejaculation" >
                    <option value="">choose</option>
                    {foreach  $ejaculationdisease as $data}
                    <option value="{$data->id}">{$data->name} </option>
                    {/foreach}
                    <option value="-2" class="deleteoptincompo">Delete</option>
                </select>
            </div>
        </div>
        <div class="col-md-9">
            <div class="form-group form-md-line-input form-md-floating-label has-info">
                <div class="form-group form-md-line-input form-md-floating-label has-info">
                    <input type="text" class="amrpop form-control updateElement"  name="notes" data-colName="notes" placeholder="Note" value="{$element->notes}" data-id="{$element->id}" data-tableName="andejaculation"/>
                </div>
                <button type="button" class="btn btn-xs red fright deleteElementDivs delbtnsml" data-id="{$element->id}" data-tableName="andejaculation"><i class="fa fa-close"></i></button>
            </div>
        </div>
        <input type="hidden" id="newId3" value="{$element->id}"/>
    </div>
</div>

<!----------------------------------------------------------------------------------------------------------------------------------------------------->
{else if $type == "contraception"}

<div>
    {if $ProgramesettingData->displaydoctorname eq 1}
    <div class="row ltr" >
        <div class="">
            <div class="">
                <label class="control-label col-md-2 ">{$element->doctorName}</label>
            </div>
        </div>
    </div>
    {/if}
    <div class="row ltr" >
        <div class="col-md-2">
            <div class="form-group">
                <!--<label class="control-label col-md-2 ls2">Type</label>-->
                <select class="form-control  updateElement  editSelect typeid" name="typeid" id="typeid{$element->id}" data-val="{$element->typeid}"  data-colName="typeid" select-tableName="andcontratype"  data-id="{$element->id}" data-tableName="andcontraception" >
                    <option value="">choose</option>
                    {foreach  $andcontratype as $data}
                    <option value="{$data->id}">{$data->name} </option>
                    {/foreach}
                    <option value="-2" class="deleteoptincompo">Delete</option>
                </select>
            </div>
        </div>


        <div class="col-md-2">
            <div class="form-group form-md-line-input form-md-floating-label has-info">
                <input type="text" class="amrpop form-control updateElement"  name="duration" data-colName="duration"  value="{$element->duration}" data-id="{$element->id}" data-tableName="andcontraception"/>
                <!--                                                        <label for="form_control_1">Duration</label>-->
                <span class="input-group-addon">Y</span>
            </div>
        </div>


        <div class="col-md-2">
            <div class="form-group form-md-line-input form-md-floating-label has-info">
                <input type="text" class="amrpop form-control updateElement"  name="stopped" data-colName="stopped"  value="{$element->stopped}" data-id="{$element->id}" data-tableName="andcontraception"/>
                <!--                                                        <label for="contstopped">Stopped</label>-->
                <span class="input-group-addon">Y</span>


            </div>
        </div>

        <div class="col-md-6">
            <div class="form-group form-md-line-input form-md-floating-label has-info">
                <div class="form-group form-md-line-input form-md-floating-label has-info">
                    <input type="text" class="amrpop form-control updateElement"  name="notes" data-colName="notes" placeholder="Note" value="{$element->notes}" data-id="{$element->id}" data-tableName="andcontraception"/>
                </div>


                <button type="button" class="btn btn-xs red fright deleteElementDivs delbtnsml" data-id="{$element->id}" data-tableName="andcontraception"><i class="fa fa-close"></i></button>
            </div>
        </div>


        <!-- END SAMPLE FORM PORTLET-->

    </div>
    <input type="hidden" id="newId4" value="{$element->id}"/>
</div>
<!----------------------------------------------------------------------------------------------------------------------------------------------------->
{else if $type == "and_visits"}

<tr>
    <td>
        <input type="text" class="form-control datepicker" data-id="{$element->id}" data-colName="date" data-tableName="andvisits" value="{$element->date}" />
    </td>
    {if $ProgramesettingData->diagnosshow eq 0}
    <td>
        <select multiple="" size="1" class="form-control select2me andcomplaint  andDiagnosis" placeholder="Select" id="andComplaint{$element->id}" name="andComplaint" select-tableName="andcomplaint"  data-id="{$element->id}" data-colName="complaintid" data-tableName="andvisits">
            <option value="">choose</option>

            {foreach $allcomplaint as $comp}
            <option value="{$comp->id}" >{$comp->name}</option>
            {/foreach}
            <option value="-1" class="addDiagnosis">Add</option>
            <option value="-2" class="deleteoptincompo">Delete</option>
        </select>

    </td>
    <td>
        <select multiple="" size="1" class="form-control select2me anddiagnosis andDiagnosis" placeholder="Select" id="andDiagnosis{$element->id}" name="andDiagnosis"  data-id="{$element->id}" select-tableName="anddiagnosis" data-colName="diagnosisid" data-tableName="andvisits">
            <option value="">choose</option>

            {foreach $alldiagnosis as $data}
            <option value="{$data->id}">{$data->name}</option>
            {/foreach}
            <option value="-1" class="addDiagnosis">Add</option>
            <option value="-2" class="deleteoptincompo">Delete</option>
        </select>
    </td>
    {else}


    <td>
        <input type="text" class="form-control updateElement" data-id="{$element->id}" data-colName="complaint" data-tableName="andvisits" value="{$element->complaint}" data-toggle="popover" data-trigger="hover" data-placement="bottom" data-content="{$element->complaint}"/>

    </td>
    {/if}
    <td>
        <textarea class="form-control updateElement txtc" rows="1" data-id="{$element->id}" data-colName="notes" data-tableName="andvisits" placeholder="Enter more text" data-toggle="popover" data-trigger="hover" data-placement="bottom" data-content="{$element->notes}">{$element->notes}</textarea>
    </td>
    <td>
        <a class="btn grey-cascade btn-xs deletemsgEX" data-id="{$element->id}" style=" float: left;" href="#" data-link="and_visits" data-fn="del" data-tableName="andvisits">
            <i class="fa fa-close"></i>
        </a>
        <input type="hidden" id="newId5" value="{$element->id}"/>
    </td>
</tr>
<!----------------------------------------------------------------------------------------------------------------------------------------------------->
{else if $type == "genetictesting"}
<tr>
    <td>
        <input type="checkbox" class="geneticPrint" id="usPrint{$element->id}"  name="pic[]"  value="{$element->id}"/>
    </td>
    <td>
        <input type="text" class="form-control datepicker updateElement" readonly="" placeholder="Date" data-colName="date" data-id="{$element->id}"  data-tableName="andvisitsus" value="{$element->date}"/>
    </td>
    <td>
        <div class="form-group">
            <select class="form-control updateElement" data-colName="chromosome"  data-id="{$element->id}" data-tableName="andvisitsgenetictesting" >
                <option value="">choose</option>
                <option value="1"> normal  </option>
                <option value="2"> abnormal  </option>
            </select>
        </div>                                                </td>
    <td>
        <div class="form-group">
            <select class="form-control updateElement" data-colName="azf"  data-id="{$element->id}" data-tableName="andvisitsgenetictesting" >
                <option value="">choose</option>
                <option value="1"> normal  </option>
                <option value="2"> delection  </option>
            </select>
        </div>                                     
    </td>

    <td>
        <textarea class="form-control updateElement txtc" rows="1" data-id="{$element->id}" data-colName="notes" data-tableName="andvisitsgenetictesting" placeholder="Enter more text" data-toggle="popover" data-trigger="hover" data-placement="bottom" data-content="{$element->notes}">{$element->notes}</textarea>
    </td>
    <td>
        <a class="btn grey-cascade btn-xs deletemsgEX" data-id="{$element->id}" style=" float: left;" href="#" data-link="and_visits" data-fn="del" data-tableName="andvisitsgenetictesting">
            <i class="fa fa-close"></i>
        </a>
    </td>
    {if $ProgramesettingData->displaydoctorname eq 1}
    <td class="bold">
        {$element->doctorname}
    </td>
    {/if}
</tr>
<!----------------------------------------------------------------------------------------------------------------------------------------------------->
{else if $type == "semen"}
<tr>
    <td>
        <input type="checkbox" class="semenPrint" id="usPrint{$element->id}"  name="pic[]"  value="{$element->id}"/>
    </td>
    <td>
        <input type="text" class="form-control datepicker updateElement" readonly="" placeholder="Date" data-colName="date" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->date}"/>
    </td>
    <td>
        <input type="text" class="form-control updateElement" placeholder="vol." data-colName="vol" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->vol}">
    </td>
    <td>
        <input type="text" class="form-control updateElement" placeholder="ph." data-colName="ph" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->ph}">
    </td>
    <td>
        <input type="text" class="form-control updateElement" placeholder="viscosity " data-colName="viscosity" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->viscosity}">
    </td>
    <td>
        <input type="text" class="form-control updateElement" placeholder="aggl. " data-colName="aggl" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->aggl}">
    </td>
    <td>
        <input type="text" class="form-control updateElement" placeholder="conc." data-colName="conc" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->conc}">
    </td>
    <td>
        <input type="text" class="form-control updateElement" placeholder="A+B " data-colName="ab" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->ab}">
    </td>
    <td>
        <input type="text" class="form-control updateElement" placeholder="NF" data-colName="nf" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->nf}">
    </td>
    <td>
        <input type="text" class="form-control updateElement" placeholder="Pus " data-colName="pus" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->pus}">
    </td>
    <td>
        <input type="text" class="form-control updateElement" placeholder="others" data-colName="others" data-id="{$element->id}"  data-tableName="andvisitssemen" value="{$element->others}">
    </td>

    <td>
        <a class="btn grey-cascade btn-xs deletemsgEX" data-id="{$element->id}" style=" float: left;" href="#" data-link="and_visits" data-fn="del" data-tableName="andvisitssemen">
            <i class="fa fa-close"></i>
        </a>
    </td>
    {if $ProgramesettingData->displaydoctorname eq 1}
    <td class="bold">
        {$element->doctorname}
    </td>
    {/if}
</tr>
<!----------------------------------------------------------------------------------------------------------------------------------------------------->
{/if}





{literal}
<script type="text/javascript" >

    var hosturl = $('#hosturl').val();

    $(".datepicker").datepicker({
        todayBtn: "linked",
        autoclose: true,
        todayHighlight: true,
        format: 'yy-mm-dd',
        isRTL: true,
    });

    var newId = $('#newId').val();
    $('#durationid' + newId).select2({
        width: '170px',
        allowClear: true,
        formatNoMatches: function (term) {
            /* customize the no matches output */
            return "<input class='form-control' id='newDuration" + newId + "' value='" + term + "' data-id='" + newId + "'><a href='#' id='addNewDuration" + newId + "' data-id=" + newId + "   class='btn btn-default addnewselect'>Add</a>"
        }
    }).parent().find('.select2-with-searchbox').on('click', '.addnewselect', function () {
        var id = $(this).attr('data-id');
        var patientId = $('#patientId').val();
        var newitem = $('#newDuration' + id).val();
        $.post(hosturl + '/controllers/and_history.php?ac=addduration', {newitem: newitem, id: id, inline: 1, patientId: patientId}, function (data) {
            $('select[name="durationid"] > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + newitem + '</option>');
            //$('<option value="' + Number(data) + '" >' + newitem + '</option>').appendTo('select[name="phregularity"]');
            $('#durationid' + id).select2('val', Number(data)); // select the new term
            $('#durationid' + id).select2('close'); // close the dropdown


        });
    });


    $('#newId').remove();


    var newId1 = $('#newId1').val();
    $('#mdiseaseid' + newId1).select2({
        width: '170px',
        allowClear: true,
        formatNoMatches: function (term) {
            /* customize the no matches output */
            return "<input class='form-control' id='newMDisease" + newId1 + "' value='" + term + "' data-id='" + newId1 + "'><a href='#' id='addNewMDisease" + newId1 + "' data-id=" + newId1 + "   class='btn btn-default addnewselect'>Add</a>"
        }
    }).parent().find('.select2-with-searchbox').on('click', '.addnewselect', function () {
        var id = $(this).attr('data-id');
        var patientId = $('#patientId').val();
        var newitem = $('#newMDisease' + id).val();
        $.post(hosturl + '/controllers/and_history.php?ac=adddmdisease', {newitem: newitem, id: id, inline: 1, patientId: patientId}, function (data) {
            $('select[name="mdiseaseid"] > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + newitem + '</option>');
            //$('<option value="' + Number(data) + '" >' + newitem + '</option>').appendTo('select[name="phregularity"]');
            $('#mdiseaseid' + id).select2('val', Number(data)); // select the new term
            $('#mdiseaseid' + id).select2('close'); // close the dropdown


        });
    });

    $('#newId1').remove();

    var newId2 = $('#newId2').val();
    $('#erectiondiseaseid' + newId2).select2({
        width: '170px',
        allowClear: true,
        formatNoMatches: function (term) {
            /* customize the no matches output */
            return "<input class='form-control' id='newerectiondisease" + newId2 + "' value='" + term + "' data-id='" + newId2 + "'><a href='#' id='addNewerectiondisease" + newId2 + "' data-id=" + newId2 + "   class='btn btn-default addnewselect'>Add</a>"
        }
    }).parent().find('.select2-with-searchbox').on('click', '.addnewselect', function () {
        var id = $(this).attr('data-id');
        var patientId = $('#patientId').val();
        var newitem = $('#newerectiondisease' + id).val();
        $.post(hosturl + '/controllers/and_history.php?ac=addderectiondisease', {newitem: newitem, id: id, inline: 1, patientId: patientId}, function (data) {
            $('select[name="erectiondiseaseid"] > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + newitem + '</option>');
            //$('<option value="' + Number(data) + '" >' + newitem + '</option>').appendTo('select[name="phregularity"]');
            $('#erectiondiseaseid' + id).select2('val', Number(data)); // select the new term
            $('#erectiondiseaseid' + id).select2('close'); // close the dropdown


        });
    });
    $('#newId2').remove();

    var newId3 = $('#newId3').val();
    $('#ejaculationdiseaseid' + newId3).select2({
        width: '170px',
        allowClear: true,
        formatNoMatches: function (term) {
            /* customize the no matches output */
            return "<input class='form-control' id='newejaculationdisease" + newId3 + "' value='" + term + "' data-id='" + newId3 + "'><a href='#' id='addNewejaculationdisease" + newId3 + "' data-id=" + newId3 + "   class='btn btn-default addnewselect'>Add</a>"
        }
    }).parent().find('.select2-with-searchbox').on('click', '.addnewselect', function () {
        var id = $(this).attr('data-id');
        var patientId = $('#patientId').val();
        var newitem = $('#newejaculationdisease' + id).val();
        $.post(hosturl + '/controllers/and_history.php?ac=addejaculationdisease', {newitem: newitem, id: id, inline: 1, patientId: patientId}, function (data) {
            $('select[name="ejaculationdiseaseid"] > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + newitem + '</option>');
            //$('<option value="' + Number(data) + '" >' + newitem + '</option>').appendTo('select[name="phregularity"]');
            $('#ejaculationdiseaseid' + id).select2('val', Number(data)); // select the new term
            $('#ejaculationdiseaseid' + id).select2('close'); // close the dropdown


        });
    });
    $('#newId3').remove();


    var newId4 = $('#newId4').val();
    $('#typeid' + newId4).select2({
        width: '170px',
        allowClear: true,
        formatNoMatches: function (term) {
            /* customize the no matches output */
            return "<input class='form-control' id='newtype" + newId4 + "' value='" + term + "' data-id='" + newId4 + "'><a href='#' id='addNewtype" + newId4 + "' data-id=" + newId4 + "   class='btn btn-default addnewselect'>Add</a>"
        }
    }).parent().find('.select2-with-searchbox').on('click', '.addnewselect', function () {
        var id = $(this).attr('data-id');
        var patientId = $('#patientId').val();
        var newitem = $('#newtype' + id).val();
        $.post(hosturl + '/controllers/and_history.php?ac=addcontraception', {newitem: newitem, id: id, inline: 1, patientId: patientId}, function (data) {
            $('select[name="typeid"] > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + newitem + '</option>');
            //$('<option value="' + Number(data) + '" >' + newitem + '</option>').appendTo('select[name="phregularity"]');
            $('#typeid' + id).select2('val', Number(data)); // select the new term
            $('#typeid' + id).select2('close'); // close the dropdown


        });
    });
    $('#newId4').remove();


    var newId5 = $('#newId5').val();

    $('#andDiagnosis' + newId5).select2({
        width: '270px',
        allowClear: true,
        formatNoMatches: function (term) {
        }
    });
    $('#andComplaint' + newId5).select2({
        width: '270px',
        allowClear: true,
        formatNoMatches: function (term) {
        }
    });

    $('#newId5').remove();
</script>
{/literal}
