<?php
session_start();                                     /* Here session is start */
require_once("../codelibrary/inc/variables.php"); /* This file is required for database connection.  */
require_once("../codelibrary/inc/functions.php"); /* This file contain all function.  */
@extract($_REQUEST);                                 /* This is used for get the request. */
validate_user();                                     /* Validate user for open/access this page with login. */

/* log4php start here */
include('../log4php/Logger.php');
Logger::configure('../logger-config.xml');
$logger = Logger::getLogger("-OPD Patient Prescription-");
/* log4php end here */

//code for edit/delete permissions
$userAccess= mysql_query_db("select * from health_user where userId='".$_SESSION['sess_uid']."'");
$fuserAccess= mysql_fetch_db($userAccess);
$role=$fuserAccess['role'];
//end of code for edit/delete permissions


//find dr id
$doctFind= mysql_query_db("select * from health_user where userId='".$_SESSION['sess_uid']."'");
$fdoctFind= mysql_fetch_db($doctFind);
$doctName= mysql_query_db("select * from health_doctors where id='".$fdoctFind['doctorId']."'");
$fdoctName= mysql_fetch_db($doctName);

/* code for fetch all product(medicine) start here*/
$sql=mysql_query_db("select * from health_opdprescriptionsalt where saltStatus=1 order by saltName asc");
while($line=mysql_fetch_db($sql)){ 
    $pro_name[]='"'.ucfirst($line['saltName']).'"';
}
if($pro_name){
    $pro_name='['.implode(',',$pro_name).']';
}
/* code for fetch all product(medicine) end here*/


/* code for fetch all product(route) start here*/
$sqlRoute=mysql_query_db("select * from health_opdprescriptionroute where status=1");
while($lineRoute=mysql_fetch_db($sqlRoute)){ 
    $route_name[]='"'.ucfirst($lineRoute['name']).'"';
}
if($route_name){
    $route_name='['.implode(',',$route_name).']';
}
/* code for fetch all product(medicine) end here*/

/* code for fetch all product(dosage) start here*/
$sqlDosage=mysql_query_db("select * from health_opdprescriptiondosage where status=1");
while($lineDosage=mysql_fetch_db($sqlDosage)){ 
    $dosage_name[]='"'.ucfirst($lineDosage['name']).'"';
}
if($dosage_name){
    $dosage_name='['.implode(',',$dosage_name).']';
}
/* code for fetch all product(medicine) end here*/


/* code for fetch all product(instruction) start here*/
$sqlInstruction=mysql_query_db("select * from health_opdprescriptioninstruction where status=1");
while($lineInstruction=mysql_fetch_db($sqlInstruction)){ 
    $instruction_name[]='"'.ucfirst($lineInstruction['name']).'"';
}
if($instruction_name){
    $instruction_name='['.implode(',',$instruction_name).']';
}
/* code for fetch all product(medicine) end here*/

/* code for fetch all product(remark) start here*/
$sqlRemark=mysql_query_db("select * from health_opdprescriptionfrequency where status=1");
while($lineRemark=mysql_fetch_db($sqlRemark)){ 
    $remark_name[]='"'.ucfirst($lineRemark['name']).'"';
}
if($remark_name){
    $remark_name='['.implode(',',$remark_name).']';
}

//med type ex cap, tab, syp
$sqlMedType=mysql_query_db("select * from pharmacy_unittype where unitStatus=1");
while($lineMedType=mysql_fetch_db($sqlMedType)){ 
    $medType_name[]='"'.ucfirst($lineMedType['unitName']).'"';
}
if($medType_name){
    $medType_name='['.implode(',',$medType_name).']';
}

//units ex mg, gm
$sqlUnits=mysql_query_db("select * from health_opdprescriptionunits where status=1");
while($lineUnits=mysql_fetch_db($sqlUnits)){ 
    $units_name[]='"'.ucfirst($lineUnits['name']).'"';
}
if($units_name){
    $units_name='['.implode(',',$units_name).']';
}

//timing ex 10 min
$sqlTiming=mysql_query_db("select * from health_opdprescriptiontiming where status=1");
while($lineTiming=mysql_fetch_db($sqlTiming)){ 
    $timing_name[]='"'.ucfirst($lineTiming['name']).'"';
}
if($timing_name){
    $timing_name='['.implode(',',$timing_name).']';
}

//when ex before breakfast
$sqlWhen=mysql_query_db("select * from health_opdprescriptionwhen where status=1");
while($lineWhen=mysql_fetch_db($sqlWhen)){ 
    $when_name[]='"'.ucfirst($lineWhen['name']).'"';
}
if($when_name){
    $when_name='['.implode(',',$when_name).']';
}

//where ex on face
$sqlWhere=mysql_query_db("select * from health_opdprescriptionwhere where status=1");
while($lineWhere=mysql_fetch_db($sqlWhere)){ 
    $where_name[]='"'.ucfirst($lineWhere['name']).'"';
}
if($when_name){
    $where_name='['.implode(',',$where_name).']';
}

//duration ex days / weeks
$sqlDuration=mysql_query_db("select * from health_opdprescriptionduration where status=1");
while($lineDuration=mysql_fetch_db($sqlDuration)){ 
    $duration_name[]='"'.ucfirst($lineDuration['name']).'"';
}
if($duration_name){
    $duration_name='['.implode(',',$duration_name).']';
}
?>
  <?php 

  if(isset($follow_up))
  {
	  $fdate=$_POST['follow_up_date'];
	  //echo $fdate; die;
	  $fdate=date("Y-m-d",strtotime($fdate));
	  $ipdId=$_POST['ipdId'];
	  mysql_query_db("update health_ipd set follow_up='$fdate' where ipdId='$ipdId' ");
  }
if($_POST['ipdId']!='' || isset($ipdId) ||isset($_SESSION['ipdId'])){
	            if(isset($_SESSION['ipdId']) && $ipdId==''){
				$ipdId=$_SESSION['ipdId'];
				}
			   if(isset($_POST['ipdId'])){
				 unset($_SESSION['ipdId']);
				 $ipdId=$_POST['ipdId'];
			   }
			   if(isset($_GET['ipdId'])){
				 unset($_SESSION['ipdId']);
				 $ipdId=$_GET['ipdId'];
			   }
               $opd= mysql_query_db("select * from health_ipd where ipdId='$ipdId'");
			   $findOpd=mysql_num_db($opd);
               $fopd=mysql_fetch_db($opd);
			   
               $pat= mysql_query_db("select * from health_patient where patientId='".$fopd['patientId']."'");
               $fpat= mysql_fetch_db($pat);
			   
			   
			   //for check already prescribed
			   $numCom= mysql_query_db("select * from health_ipdprescriptioncomment where ipdId='$ipdId'");
			   $fnumCom= mysql_num_db($numCom);
			   if($fnumCom>0){
			   $prescriptionCommment=mysql_fetch_db($numCom);
			   }
			   else{
					//copy va, rrt, diet from old rx	
					$numOther= mysql_query_db("select * from health_ipdprescriptioncomment where patientId='".$fopd['patientId']."' order by id desc limit 0,1");
					$fother=mysql_fetch_db($numOther);
			   }
			   
					//shifting prescription from final to temp table, for any of update
				
					$final= mysql_query_db("select * from health_ipdprescriptionfinal where ipdId='$ipdId'");
					$numFinal=mysql_num_db($final);
					if($numFinal!=0 && (!isset($_SESSION['edit_ipd']))){
						$_SESSION['edit_ipd']="1";
						while($ftmp=mysql_fetch_db($final)){
							mysql_query_db("insert into health_ipdprescriptiontemp set ipdId='$ipdId',medType ='".addslashes($ftmp['medType'])."', medicine='".addslashes($ftmp['medicine'])."', drug ='".addslashes($ftmp['drug'])."', dose ='".addslashes($ftmp['dose'])."', unit ='".addslashes($ftmp['unit'])."', timing ='".addslashes($ftmp['timing'])."',whenMed ='".addslashes($ftmp['whenMed'])."', whereMed ='".addslashes($ftmp['whereMed'])."', frequency ='".addslashes($ftmp['frequency'])."', number ='".addslashes($ftmp['number'])."', duration ='".addslashes($ftmp['duration'])."', instruction ='".addslashes($ftmp['instruction'])."'");
						}
					}
					
 }	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title><?php echo SITE_TITLE;?></title>
		<link rel="icon" href="../images/favicon.png" type="image/png" /> <!-- Title-->
        <link href="../css/style.css" rel="stylesheet" type="text/css">                      <!-- CSS link for design the whole phase-->
        <link href="../awesome/css/font-awesome.css" rel="stylesheet" type="text/css">     <!-- Font awesome link for use font awesome icon-->
        <link href="../awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <!-- Font awesome link for use font awesome icon-->
		<script src="../ajax.js"></script>
        <!-- validation css and js start here -->
        <link rel="stylesheet" href="../validation/css/vstyle.css">
        <!-- validation css and js end -->
		<style>
		input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
  border: 1px solid green;
  -webkit-text-fill-color: green;
  -webkit-box-shadow: 0 0 0px 1000px #000 inset;
  transition: background-color 5000s ease-in-out 0s;
}
.ui-autocomplete { height: 200px; overflow-y: scroll; overflow-x: hidden;}

		</style>
        <script>
            function _isNumberKey(evt){
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode > 31 && (charCode < 48 || charCode > 57))
                    return false;
                return true;
            }
        </script>
        <!-- time start---->
        <script>
            function _startTime() {
                var today = new Date();
                var h = today.getHours();
                var m = today.getMinutes();
                var s = today.getSeconds();
                m = checkTime(m);
                s = checkTime(s);
                document.getElementById('txt').innerHTML= h + ":" + m + ":" + s;
                var t = setTimeout(_startTime, 500);
            }
            function checkTime(i) {
                if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
                    return i;
            }
        </script>
		 <!-- auto complete start here -->
        <link rel="stylesheet" href="../css/jquery-ui.css">
        <script src="../js/jquery-1.12.4.js"></script>
        <script src="../js/jquery-ui.js"></script>
		
        <script>
		$(function() {
               $( ".datecalender" ).datepicker({ dateFormat: 'dd-mm-yy' }).datepicker(<?php echo $today;?>);
          } );
		 
		$(document).on("focusout",'#tags',function(){
		  var availableTags=<?php echo $pro_name;?>;
          $( "#tags" ).autocomplete({
            source: availableTags,
			minLength:2,
			delay: 100
          });
		  var availableRoute=<?php echo $route_name;?>;
          $( "#route" ).autocomplete({
            source: availableRoute
          });
		  
		  var availableDosage=<?php echo $dosage_name;?>;
          $( "#dose" ).autocomplete({
            source: availableDosage,
			delay: 100
          });
		  
		 
		   var availableMedType=<?php echo $medType_name;?>;
          $( "#medType" ).autocomplete({
            source: availableMedType,
			minLength: 1,
			delay: 100
          });
		  
		   var availableUnits=<?php echo $units_name;?>;
          $( "#units" ).autocomplete({
            source: availableUnits,
			minLength: 1,
			delay: 100
          });
		  
		  var availableTiming=<?php echo $timing_name;?>;
          $( "#timing" ).autocomplete({
            source: availableTiming,
			minLength: 1,
			delay: 100
          });
		  
		  var availableWhen=<?php echo $when_name;?>;
          $( "#when" ).autocomplete({
            source: availableWhen,
			minLength: 1,
			delay: 100
          });
		  
		  var availableWhere=<?php echo $where_name;?>;
          $( "#where" ).autocomplete({
            source: availableWhere,
			minLength: 1,
			delay: 100
          });
		  
		  var availableDuration=<?php echo $duration_name;?>;
          $( "#duration" ).autocomplete({
            source: availableDuration,
			minLength: 1,
			delay: 100
          });
		  
		    var availableInstruction=<?php echo $instruction_name;?>;
          $( "#instruction" ).autocomplete({
            source: availableInstruction,
			minLength: 1,
			delay: 100
          });
		  
		   var availableFrequency=<?php echo $remark_name;?>;
          $( "#frequency" ).autocomplete({
            source: availableFrequency,
			minLength: 1,
			delay: 100
          });
		  
		});
		
		
		
		$(document).on("focusout",'#instruction',function(){
		  var availableTags=<?php echo $pro_name;?>;
          $( "#tags" ).autocomplete({
            source: availableTags,
			minLength:2,
			delay: 100
          });
		  var availableRoute=<?php echo $route_name;?>;
          $( "#route" ).autocomplete({
            source: availableRoute
          });
		  
		  var availableDosage=<?php echo $dosage_name;?>;
          $( "#dose" ).autocomplete({
            source: availableDosage,
			delay: 100
          });
		  
		 
		   var availableMedType=<?php echo $medType_name;?>;
          $( "#medType" ).autocomplete({
            source: availableMedType,
			minLength: 1,
			delay: 100
          });
		  
		   var availableUnits=<?php echo $units_name;?>;
          $( "#units" ).autocomplete({
            source: availableUnits,
			minLength: 1,
			delay: 100
          });
		  
		  var availableTiming=<?php echo $timing_name;?>;
          $( "#timing" ).autocomplete({
            source: availableTiming,
			minLength: 1,
			delay: 100
          });
		  
		  var availableWhen=<?php echo $when_name;?>;
          $( "#when" ).autocomplete({
            source: availableWhen,
			minLength: 1,
			delay: 100
          });
		  
		  var availableWhere=<?php echo $where_name;?>;
          $( "#where" ).autocomplete({
            source: availableWhere,
			minLength: 1,
			delay: 100
          });
		  
		  var availableDuration=<?php echo $duration_name;?>;
          $( "#duration" ).autocomplete({
            source: availableDuration,
			minLength: 1,
			delay: 100
          });
		  
		    var availableInstruction=<?php echo $instruction_name;?>;
          $( "#instruction" ).autocomplete({
            source: availableInstruction,
			minLength: 1,
			delay: 100
          });
		  
		   var availableFrequency=<?php echo $remark_name;?>;
          $( "#frequency" ).autocomplete({
            source: availableFrequency,
			minLength: 1,
			delay: 100
          });
		  
		});
		
		$(function(){	
		 var availableTags=<?php echo $pro_name;?>;
          $( "#tags" ).autocomplete({
            source: availableTags,
			minLength:2,
			delay: 100
          });
		  
		  var availableRoute=<?php echo $route_name;?>;
          $( "#route" ).autocomplete({
            source: availableRoute,
			delay: 100
          });
		  
		  var availableDosage=<?php echo $dosage_name;?>;
          $( "#dose" ).autocomplete({
            source: availableDosage,
			delay: 100
          });
		  
		 
		   var availableMedType=<?php echo $medType_name;?>;
          $( "#medType" ).autocomplete({
            source: availableMedType,
			minLength: 1,
			delay: 100
          });
		  
		   var availableUnits=<?php echo $units_name;?>;
          $( "#units" ).autocomplete({
            source: availableUnits,
			minLength: 1,
			delay: 100
          });
		  
		  var availableTiming=<?php echo $timing_name;?>;
          $( "#timing" ).autocomplete({
            source: availableTiming,
			minLength: 1,
			delay: 100
          });
		  
		  var availableWhen=<?php echo $when_name;?>;
          $( "#when" ).autocomplete({
            source: availableWhen,
			minLength: 1,
			delay: 100
          });
		  
		  var availableWhere=<?php echo $where_name;?>;
          $( "#where" ).autocomplete({
            source: availableWhere,
			minLength: 1,
			delay: 100
          });
		  
		  var availableDuration=<?php echo $duration_name;?>;
          $( "#duration" ).autocomplete({
            source: availableDuration,
			minLength: 1,
			delay: 100
          });
		  
		    var availableInstruction=<?php echo $instruction_name;?>;
          $( "#instruction" ).autocomplete({
            source: availableInstruction,
			minLength: 1,
			delay: 100
          });
		  
		   var availableFrequency=<?php echo $remark_name;?>;
          $( "#frequency" ).autocomplete({
            source: availableFrequency,
			minLength: 1,
			delay: 100
          });
		  
        });
        </script>
        <!-- auto complete end here --> 
        <script>
		   function _editMedRow(id,ipdId)
            {
				//alert(ipdId);
                url = document.location.href;
                xend = url.lastIndexOf("/") + 1;
                var base_url = url.substring(0, xend);
                url="../allajax/medRowEdit-ipd_ajax.php";
                    if (url.substring(0, 4) != 'http') 
                    {
                        url = base_url + url;		
                    }
                var strSubmit="ipdId="+ipdId+"&id="+id;
                var strURL = url;
                document.getElementById('template').innerHTML="<img src='../images/ajax_progress.gif'>";
                var strResultFunc = "displaysubResult100";
                xmlhttpPost(strURL, strSubmit, strResultFunc)
                return true; 
            }
            function displaysubResult100(strIn100) 
            {    
                document.getElementById('template').innerHTML=strIn100;
				document.getElementById('tags').focus();
            }
		
		function _pullRx(iipdId,ipdId){
			 url = document.location.href;
                xend = url.lastIndexOf("/") + 1;
                var base_url = url.substring(0, xend);
                url="../allajax/copyprescription-ipd-ajax.php";
                    if (url.substring(0, 4) != 'http') 
                    {
                        url = base_url + url;		
                    }
                var strSubmit="iipdId="+iipdId+"&ipdId="+ipdId;
				var strURL = url;
                document.getElementById('del_div').innerHTML="<img src='../images/ajax_progress.gif'>";
                var strResultFunc = "displaysubResult90";
                xmlhttpPost(strURL, strSubmit, strResultFunc)
                return true; 
		}
		function displaysubResult90(strIn90) 
            {   
				document.getElementById('tags').value="";
				document.getElementById('tags').focus();
				document.getElementById('del_div').innerHTML=strIn90;
				
            }
		
		
		function _fillTemplate(templateId,ipdId)
		{
			    url = document.location.href;
                xend = url.lastIndexOf("/") + 1;
                var base_url = url.substring(0, xend);
                url="../allajax/addprescriptiontemplate-ipd-ajax.php";
                    if (url.substring(0, 4) != 'http') 
                    {
                        url = base_url + url;		
                    }
                var strSubmit="templateId="+templateId+"&ipdId="+ipdId;
				var strURL = url;
                document.getElementById('del_div').innerHTML="<img src='../images/loading.gif'>";
                var strResultFunc = "displaysubResult80";
                xmlhttpPost(strURL, strSubmit, strResultFunc)
                return true; 
		}
		  function displaysubResult80(strIn80) 
            {   
				document.getElementById('tags').value="";
				document.getElementById('tags').focus();
				document.getElementById('del_div').innerHTML=strIn80;
				
            }
		
	function _diagnosisAjax(val65)
	{
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	url="../allajax/alldiagnosis-ajax.php";
		 if (url.substring(0, 4) != 'http') 
		 {
			url = base_url + url;		
		}
	var strSubmit="id65="+val65;	
	var strURL = url;
	document.getElementById('all-diagnosis-list').innerHTML="<img src='../images/loding.gif'>";
	var strResultFunc = "displaysubResult65";
	xmlhttpPost(strURL, strSubmit, strResultFunc)
	return true; 
	}
	function displaysubResult65(strIn65) 
	{
		document.getElementById('all-diagnosis-list').innerHTML=strIn65;
	}
	
	function _femaleFindingsAjax(val65)
	{ 
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	url="../allajax/femaleFindings-ajax.php";
		 if (url.substring(0, 4) != 'http') 
		 {
			url = base_url + url;		
		}
	var strSubmit="id65="+val65;	
	var strURL = url;
	document.getElementById('femaleFindings-list').innerHTML="<img src='../images/loding.gif'>";
	var strResultFunc = "displaysubResult66";
	xmlhttpPost(strURL, strSubmit, strResultFunc)
	return true; 
	}
	function displaysubResult66(strIn65) 
	{
		document.getElementById('femaleFindings-list').innerHTML=strIn65;
	}
	
            function _saleUnitType_ajax(val59)
            {
                url = document.location.href;
                xend = url.lastIndexOf("/") + 1;
                var base_url = url.substring(0, xend);
                url="../allajax/prescriptionUnitType-ajax.php";
                    if (url.substring(0, 4) != 'http') 
                    {
                        url = base_url + url;		
                    }
                var strSubmit="id59="+val59;
                var strURL = url;
                document.getElementById('unitId_ajax').innerHTML="<img src='../images/loading_big.gif'>";
                var strResultFunc = "displaysubResult59";
                xmlhttpPost(strURL, strSubmit, strResultFunc)
                return true; 
            }
            function displaysubResult59(strIn44) 
            {    
                document.getElementById('unitId_ajax').innerHTML=strIn44;
            }
			
			<!---Template--->
			function _medicineTemplate_ajax(medicine,ipdId)
            {
				//alert(medicine);
                url = document.location.href;
                xend = url.lastIndexOf("/") + 1;
                var base_url = url.substring(0, xend);
                url="../allajax/medicineTemplate-ipd_ajax.php";
                    if (url.substring(0, 4) != 'http') 
                    {
                        url = base_url + url;		
                    }
                var strSubmit="medicine="+medicine+"&ipdId="+ipdId;
                var strURL = url;
                document.getElementById('template').innerHTML="<img src='../images/ajax_progress.gif'>";
                var strResultFunc = "displaysubResult60";
                xmlhttpPost(strURL, strSubmit, strResultFunc)
                return true; 
            }
            function displaysubResult60(strIn44) 
            {    
		      
                document.getElementById('template').innerHTML=strIn44;
				document.getElementById('tags').focus();
				
            }
			

            function _deleteSaleAjax(val39,val38)
            {
                url = document.location.href;
                xend = url.lastIndexOf("/") + 1;
                var base_url = url.substring(0, xend);
                url="../allajax/deleteprescription-ipd-ajax.php";
                    if (url.substring(0, 4) != 'http') 
                    {
                        url = base_url + url;		
                    }
                var strSubmit="id39="+val39+"&ipdId="+val38;
                var strURL = url;
                document.getElementById('del_div').innerHTML="<img src='../images/loading.gif'>";
                var strResultFunc = "displaysubResult39";
                xmlhttpPost(strURL, strSubmit, strResultFunc)
                return true; 
            }
            function displaysubResult39(strIn44) 
            {    
                document.getElementById('del_div').innerHTML=strIn44;
            }
			
			
            function _addSaleAjax(ipdId,medType,medicine,drug,dose,unit,timing,when,where,frequency,number,duration,instruction)
            {
				//alert("gg");
			    url = document.location.href;
                xend = url.lastIndexOf("/") + 1;
                var base_url = url.substring(0, xend);
                url="../allajax/addprescription-ipd-ajax.php";
                    if (url.substring(0, 4) != 'http') 
                    {
                        url = base_url + url;		
                    }
                var strSubmit="ipdId="+ipdId+"&medType="+medType+"&medicine="+medicine+"&drug="+drug+"&dose="+dose+"&unit="+unit+"&timing="+timing+"&whenMed="+when+"&whereMed="+where+"&frequency="+frequency+"&number="+number+"&duration="+duration+"&instruction="+instruction;
				
				var strURL = url;
                document.getElementById('del_div').innerHTML="<img src='../images/loading.gif'>";
                var strResultFunc = "displaysubResult40";
                xmlhttpPost(strURL, strSubmit, strResultFunc)
                return true; 
            }
            function displaysubResult40(strIn45) 
            {   
				document.getElementById('tags').value="";
				document.getElementById('tags').focus();
				document.getElementById('drug').value="";
				document.getElementById('dose').value="";
				document.getElementById('units').value="";
				document.getElementById('timing').value="";
				document.getElementById('number').value="";
				document.getElementById('when').value="";
				document.getElementById('where').value="";
				document.getElementById('frequency').value="";
				document.getElementById('instruction').value="";
                document.getElementById('del_div').innerHTML=strIn45;
				
            }
            function _isNumberKey(evt){
                var charCode = (evt.which) ? evt.which : event.keyCode
                    if (charCode > 31 && (charCode < 48 || charCode > 57))
                        return false;
                        return true;
            }
     
            </script>
		    <style>
        .loader-report{
			background-color:rgba(255,255,255,1);
			box-shadow: ;
			position:fixed;
			padding:10px;	
			top:0%;
			left:30%;
			right:60%;
			z-index:2;
			display:none;
			border:1px solid grey;
		}
		.loader-img-report{
		}
		</style>
	<script>

	$(document).ready(function(){
		$("b").click(function(){
		var uploadId=$(this).attr("class");
		var path="../reports/reports/"+uploadId+".pdf";
		//alert(path);
		 $.ajax({
            type : 'post',
            url : '../allajax/findPdfReport.php',
            data : {key : path},
            success : function(responce){
                //alert(responce)
				$("#pdfBox").html(responce);
            }
        });
		$(".loader-report").css("display","block");	
		$(".loader-report").animate({height: "600px",width:"600px"});
	});
		
	$("#close-report").click(function(){
	$(".loader-report").animate({height:"10px",width:"10px"},300, function(){	
		$(".loader-report").css("display","none");
	});	
	location.reload();
	});
	
	$("#close-report").click(function(){
	$(".loader-report").animate({height:"10px",width:"10px"},300, function(){
		$(".loader-report").css("display","none");
	});	
	location.reload();
	});

});
</script>

		<script type="text/javascript">
		$(document).ready(function(){
			
			var d=$("#genExamination").val();
			d=d.replace(/<br ?\/?>/g, "\n")
			$("#genExamination").val(d);
			
			var d=$("#sysExamination").val();
			d=d.replace(/<br ?\/?>/g, "\n")
			$("#sysExamination").val(d);
			
			var d=$("#provDiagnosis").val();
			d=d.replace(/<br ?\/?>/g, "\n")
			$("#provDiagnosis").val(d);
			
			var d=$("#investigations").val();
			d=d.replace(/<br ?\/?>/g, "\n")
			$("#investigations").val(d);
			
			var d=$("#diet").val();
			d=d.replace(/<br ?\/?>/g, "\n")
			$("#diet").val(d);
			
			var d=$("#advice").val();
			d=d.replace(/<br ?\/?>/g, "\n")
			$("#advice").val(d);
			
			var d=$("#invFollowup").val();
			d=d.replace(/<br ?\/?>/g, "\n")
			$("#invFollowup").val(d);

			// end of regular string
			<!---------//form values---------->
			$("form").submit(function(){
			
			var i=$("#genExamination").val();
			i=i.replace(/\n/g,"<br>");
			$("#genExamination").val(i);
			
		    var d=$("#sysExamination").val();
			d=d.replace(/\n/g,"<br>");
			$("#sysExamination").val(d);
			
			var i=$("#provDiagnosis").val();
			i=i.replace(/\n/g,"<br>");
			$("#provDiagnosis").val(i);
			
			var i=$("#investigations").val();
			i=i.replace(/\n/g,"<br>");
			$("#investigations").val(i);
			
			var i=$("#diet").val();
			i=i.replace(/\n/g,"<br>");
			$("#diet").val(i);
			
			var i=$("#invFollowup").val();
			i=i.replace(/\n/g,"<br>");
			$("#invFollowup").val(i);
		});
		

});
</script>
    </head>
    <body>
		<div class="loader-report" id="image-loader-report">
			<div id="close-report" style="background-color:red;color:#fff;float:right;border-radius:6px;padding:5px 25px; font-size:20px; cursor: pointer;">X
			</div>
			<div>
			
			<div class="full">
            <div id="pdfBox">
            <embed id="docId" width="100%" height="580px"/>
            </div>										
			</div>
			<div class="clearfix20"></div>
			<div class="full">
				<div class="full" style="float:right">
						<div class="full">
							<a id="close-report" name="submit" class="dash_btn" style="width: 100px; height:30px;padding:4px">Close</a>
						</div>
				</div>
			</div>
			</div>
		    </div>
        <div class="full">
            <?php include("doctor-dashboard-menu.php");?>
            <div class="clearfix10"></div>
            <div class="full">
                <div class="mauto95">
                    <div class="full">
                        <?php include("ipd-menu.php");?>
                    </div>
                    <div class="clearfix10"></div>
                        <div class="full grey_bck22 box_shadow66"><!--full80r-->
                            <div class="full line_hgt35 pink_bck">  <!--right_side_head-->
                                <div class="mauto95">
                                    <div class="full">
                                        <div class="full30 white18">
										 <form name="search_patient" method="post" action="doctor-prescription-ipd.php">
                                                <div class="full">
                                                    <div class="full20 grey14 line_hgt30">IPD No.</div>
                                                    <div class="full5 txt_center line_hgt30"> : </div>
                                                    <div class="full55">
                                                        <div class="full40"><input type="text" <?php if($ipdId==''){?>autofocus<?php }?> name="ipdId" value="<?php echo $ipdId;?>" required placeholder="OPD No." class="grey14 dash_txt_box86" onkeypress="return _isNumberKey(event)"></div>
                                                        <div class="full60"><input type="submit" name="submit" value="Search" class="dash_btn"></div>
                                                    </div>
                                                </div>
                                            </form>
										
										</div>
										<div class="full30 white18">
										OPD Patient(s) under 
										: <span> <i class="fa fa-user-md"></i> &nbsp;Dr.<?php echo $fdoctName['doctorName'];?></span>
										
										</div>
                                        <div class="full30r white18 txt_right">
                                            <div class="full white14 line_hgt35" id="categ_ajax8">
                                                Arrival Date / Time: <?php if($ipdId){ echo date("d-M-Y",strtotime($fopd['dateTime'])); echo " / "; echo $fopd['postTime']; }?>
                                            </div> 
                                                
												
									   </div>
                                       </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                      </div>
                    
                </div>
            </div>
			 <div class="full">
                     <div class="mauto95">
                      <div class="full grey_bck22">
                        <div class="full" style="max-height:310px; overflow-y:scroll;">
                            <table cellpadding="0" cellspacing="0" width="100%">
							 <tr class="grey14 txt_center dark_bck line_hgt25">
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:5%">S.No.</td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:6%">IPD No.</td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:6%;">UHID</td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:17%;">Patient's Name</td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:17%;">Father/Husband</td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:6%;">Age</td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:7%;">Gender</td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:13%;">Contact No.</td>
                                <!--<td class="grey_brdr_rght grey_brdr_btm" style=" width:5%;">Fee(Rs)</td>-->
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:10%;">Date</td>
								<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;">Expand</td>
                            </tr>
                            <?php
                                $i=1;
                                    $patientList=mysql_query_db("select * from health_patient where patientId='".$fopd['patientId']."'");
                                    $fpatientList=mysql_fetch_db($patientList);
									$opdFee= mysql_query_db("select * from health_financeipd where ipdId='".$fopd['ipdId']."'");
									$fopdFee= mysql_fetch_db($opdFee);
									$fees=$fopdFee['opdFee']-$fopdFee['opdDiscount'];
									$total_fees=$total_fees+$fees;
									//for sheet opd details
									
									$doctor= mysql_query_db("select * from health_doctors where id='".$fopd['doctorId']."'");
									$fdoctor= mysql_fetch_db($doctor);
									$deptt= mysql_query_db("select * from health_department where id='".$fopd['depttId']."'");
									$fdeptt= mysql_fetch_db($deptt);
									$notes= mysql_query_db("select * from health_emr_patient where ipdId='".$fopd['ipdId']."'");
									$fnotes= mysql_fetch_db($notes);
									$loc=mysql_query_db("select * from health_location where id='".$fdeptt['location']."'");
									$floc=mysql_fetch_db($loc);

									$sql_payer=mysql_query_db("select * from health_tpa where id='".$fopd['payer']."'");
									$payer=mysql_fetch_db($sql_payer);

									
									
								
                            ?>
                            <tr style="background-color:<?php if($i%2==0){?>#FFFFFF<?php } else {?>#F4F4F4<?php }?>; fpatientList-height:25px;" class="grey14 txt_center">
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:5%;"><?php echo $i;?></td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:6%;"><?php echo $fopd["ipdId"];?>&nbsp; <img src="../images/rx.png" height="25px"></td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:6%;"><?php echo $fpatientList["patientId"];?></a></td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:17%;"><?php echo $fpatientList['patientInitial']." ".$fpatientList['patientName'];?></td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:17%;"><?php echo $fpatientList['fatherHusInitial']." ".$fpatientList['fatherHusName'];?></td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:6%;"><?php echo $fpatientList['age'];?></td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:7%;"><?php echo $fpatientList['gender'];?></td>
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:13%;"><?php echo $fpatientList['mobileNumber'];?></td>
                               <!-- <td class="grey_brdr_rght grey_brdr_btm" style=" width:5%;"><?php echo $fees;?></td>-->
                                <td class="grey_brdr_rght grey_brdr_btm" style=" width:10%;"><?php echo date('d-M-Y',strtotime($fopd['dateTime']));?></td>
								<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;"><a href="javascript:void(0)" onclick="_showHistory2('<?php echo $i;?>','<?php echo $nhis;?>')"><i class="fa fa-arrows-alt" style="color:red;font-size:20px;"></i></a></td>
                            </tr>
							     <tr style="background-color:#FFFFFF; fpatientList-height:25px;" class="grey14 txt_center">
                                            <td class="" style="width:100%;" colspan="8">
                                            <div class="full blue_border" id="his2_<?php echo $i?>" style="display:none;">
                                                             <!--sheet-->
											<div class="full">
                                           <div class="full50">
                                                <div class="full95">
                                                <div class="full printgrey12 txt_left">IPD ID : <?php echo $fopd['ipdId'];?> UHID : <?php echo $fpatientList['patientId'];?></div>
                                                <div class="clearfix7"></div>
                                                <div class="full printgrey12 txt_left">Name :  <?php echo ucfirst($fpatientList['patientInitial']." ".$fpatientList['patientName']);?></div>
                                                <div class="clearfix7"></div>
                                                <div class="full printgrey12 txt_left">Age/Gender :  <?php echo $fpatientList['age']."Y";?>/<?php echo ucfirst($fpatientList['gender']);?></div>
                                                <div class="clearfix7"></div>
                                                <div class="full printgrey12 txt_left">Mobile No. :  <?php echo $fpatientList['mobileNumber'];?></div>
                                                <div class="clearfix7"></div>
												<div class="full printgrey12 txt_left">Address :  <?php echo ucfirst($fpatientList['address']);?></div>
                                                <div class="clearfix7"></div>
												<div class="full printgrey12 txt_left">Comment :  <?php echo ucfirst($fopd['comment']);?> </div>
												</div>
                                            </div>
                                            <div class="full50r">
                                                <div class="full95">
												<div class="full printgrey12 txt_left">Date :  <?php echo date('d-M-Y',strtotime($fopd['dateTime']));?> </div>
                                                <div class="clearfix7"></div>
                                                <div class="full printgrey12 txt_left">Department :  <?php echo ucfirst($fdeptt['depttName']);?></div>
                                                <div class="clearfix7"></div>
                                                <div class="full printgrey12 txt_left">Doctor :  Dr.<?php echo $fdoctor['doctorName'];?></div>
                                                <div class="clearfix7"></div>
												<div class="full printgrey12 txt_left">Referred By :<?php if($fopd['refDoc']!=''){echo $fopd['refDoc'];}else{ echo "NA";}?></div>
                                                <div class="clearfix7"></div>
												
												<div class="full printgrey12 txt_left">TPA :<?php echo $payer['tpa'];?></div>
                                                <div class="clearfix7"></div>
												</div>
                                            </div>
                                             
										  <div class="clearfix5"></div>
										  <div class="full" style="border:1px dotted #000">
													 
														<div class="full20 printgrey12 line_hgt25"><b>&nbsp; BP(mmHg): </b><?php echo $fnotes['sbp'];?>/<?php echo $fnotes['dbp'];?></div>
														<div class="full20 printgrey12 line_hgt25"><b>&nbsp; MAP(mmHg): </b><?php echo $fnotes['map'];?></div>
                                                         <div class="full20 printgrey12 line_hgt25"> <b> &nbsp; Temp(F): </b> </b><?php echo $fnotes['temp'];?></div>
                                                        <div class="full20 printgrey12 line_hgt25"><b> &nbsp; Pulse(bpm): </b><?php echo $fnotes['pulse'];?> </div>
                                                        <div class="full20 printgrey12 line_hgt25"><b> &nbsp; Res(bpm): </b><?php echo $fnotes['res'];?></div>
                                                        <!--
														<div class="full25 printgrey12 line_hgt25"><b>&nbsp; Oxy Sat(%):</b> <?php echo $fnotes['oxygen'];?></div>
														<div class="full20 printgrey12 line_hgt25"><b> &nbsp; Pain Score:</b>  <?php echo $fnotes['pain_score'];?> </div>
														-->
														<div class="full20 printgrey12 line_hgt25"><b> &nbsp; Heigth(cm): </b> <?php echo $fnotes['height'];?></div>
                                                        <div class="full20 printgrey12 line_hgt25"><b> &nbsp; Weight(kg): </b> <?php echo $fnotes['weight'];?></div>
                                                        <div class="full20 printgrey12 line_hgt25"><b> &nbsp; BMI :</b>  <?php echo $fnotes['bmi'];?> </div>
                                                        <div class="full20 printgrey12 line_hgt25"><b> &nbsp; BSA :</b>  <?php echo $fnotes['bsa'];?> </div>
														<div class="full20 printgrey12 line_hgt25"><b> &nbsp; BS(mg%):</b>  <?php echo $fnotes['bsType']." ".$fnotes['bs'];?></div>
                                                        <div class="full20 printgrey12 line_hgt25" style="display:none">&nbsp; 
														<i class="fa fa-user" aria-hidden="true" style="font-size:20px;"></i>
														<?php echo $fnotes['bmi_result'];?> </div>
													</div>
												 </div>
                                             </td>
                                     </tr>
									 <tr class="grey14 txt_left line_hgt25 white_bck">
                                            <td class="" style="width:100%;" colspan="11"><b>Complaints:</b> <?php echo $fnotes['symptoms'];?></td>
									</tr>
							</table>
                    </div>
                </div>
                
                 </div>
                 </div>
                           
                 </div>
			
            <div class="clearfix10"></div>
            <div class="full">
                <div class="mauto95">
                    <form name="add_invoice" id="add_invoice" method="post" action="ipd-prescription-code.php" enctype="multipart/form-data">
                    <input type="hidden" name="ipdId" value="<?php echo $ipdId;?>">
                    <input type="hidden" name="patientId" value="<?php echo $fopd['patientId'];?>">
                    <input type="hidden" name="uhid" value="<?php echo $uhid;?>">
                        <div class="full grey_bck22 box_shadow66"><!--full80r-->
                            <div class="full line_hgt35 pink_bck">  <!--right_side_head-->
                                <div class="mauto95">
                                    <div class="full">
                                        <div class="full50 white16 bold">Prescription</div>
                                    </div>
                                </div>
                            </div>
                            <div class="full">
                                <div class="full">
								 <div class="clearfix10"></div>
								        <div class="full printgrey16 dark_bck">
										   <div class="full50">
                                               <div class="full90">General Examination</div>
                                            </div>
										    <div class="full50">
											   <div class="full90">Systemic Examination</div>
                                           </div>
										 </div>
                                        <div class="full">
											<div class="full45">
                                                <textarea name="genExamination" id="genExamination" placeholder="General Examination" class="txt_area allUpperCase grey14" rows="20"><?php if(isset($prescriptionCommment['genExamination'])){echo $prescriptionCommment['genExamination'];}?></textarea>
                                            </div>
											<div class="full5 txt_left">
											<img src="../images/plus3.png" style="height:40px;cursor:pointer;padding:10px" id="showGen">
											</div>
											<div class="full45">
                                                <textarea name="sysExamination" id="sysExamination" placeholder="Systemic Examination" class="txt_area allUpperCase grey14" rows="20"><?php if(isset($prescriptionCommment['sysExamination'])){echo $prescriptionCommment['sysExamination'];}?></textarea>
                                            </div>
											<div class="full5 txt_left">
											<img src="../images/plus3.png" style="height:40px;cursor:pointer;padding:10px" id="showSys">
											</div>
											
										   <div class="full printgrey16 dark_bck">
										   <div class="full50">
											   <div class="full90">Provisional Diagnosis</div>
                                           </div>
										   <div class="full50">
											<div class="full90">Investigations</div>
											</div>
										   </div>
										   
										   <div class="full">
											<div class="full45">
                                                  <textarea style="display:none" name="provDiagnosis" id="provDiagnosis" placeholder="Provisional Diagnosis" class="txt_area allUpperCase grey14" rows="20"></textarea>
													<table  width="100%" class="display nowrap" id="dia-list">
                                                    <thead>
													<tr style="background-color:#9ea0a7;color:#fff;" class="grey14 txt_left">
                                                    <td id="findDiagnosis" class="grey_brdr_rght grey_brdr_btm" style="cursor:pointer;width:60%;">Diagnosis <img src="../images/plus.png" style="cursor:pointer;height:25px"></td>
													<td class="grey_brdr_rght grey_brdr_btm" style=" width:10%;">Duration</td>
													
                                                    <td class="grey_brdr_rght grey_brdr_btm" style=" width:10%;">Remove</td>
                                                    </tr>
													</thead>
													<?php
															
															$oldValue=mysql_query_db("select * from health_ipdprescriptioncomment where ipdId='$ipdId'");
															$num=mysql_num_db($oldValue);
															if($num!=0){
															$foldValue=mysql_fetch_db($oldValue);
															$ffoldValue=$foldValue['provDiagnosis'];
															if(!empty($ffoldValue)){
															$myArray=array();
															$myArray2=array();
															$myArray = explode(',', $ffoldValue);
															$count=count($myArray);
																	 for($j=0;$j<$count;$j++){
																	 $myArray2 = explode(':', $myArray[$j]);
																	 
																	 ?>
																	 <tr id='<?php echo strtok($myArray2[0],' ');?>'><td style="width:50%"><input style="width:95%" type="text" name='nameDiagnosis[]' value="<?php echo $myArray2[0];?>"></td><td style="width:20%" class="durationDiagnosis"><input style="width:100%" type="text" name='durationDiagnosis[]' class="<?php echo strtok($myArray2[0],' ');?>" value="<?php echo $myArray2[1];?>" onkeyup="pulsar(this)"><ul class="dropdown-content dialist" id="list<?php echo strtok($myArray2[0],' ');?>" style="cursor:pointer"></ul></td><td style="width:10%;cursor:pointer;text-align:center"><img src="../images/delete.png" height="20px" id="rmv_btn" class='<?php echo strtok($myArray2[0],' ');?>'></td></tr>
																	<?php
																	 
																	 }	
															   }
															}
																												
															?>
													</table>
													<div class="dropdown dropbtn" style="width:50%;">
													  <div id="dropdownDia" class="dropdown-content">
													  <input type="text" placeholder="Search.." id="myInputDia" class="myInput" onkeyup="filterFunctionDia()">
													  <div style="overflow-y:scroll;max-height:150px">
													  <ul id="listDia">
														<?php
														$diaList= mysql_query_db("select * from health_emr_diagnosis");
														while($fdiaList= mysql_fetch_db($diaList)){
													   ?>
													   <li id="<?php echo $fdiaList['name'];?>"><?php echo $fdiaList['name'];?></li>
													   <?php }?>
													   </ul>
													   </div>
													 </div>
													</div>
											  
											  </div>
											 <div class="full5 txt_left">
											<img src="../images/plus2.png" style="height:40px;cursor:pointer;padding:10px" id="showDia">
											</div>
										  
										   <div class="full45">
											  <textarea name="investigations" id="investigations" placeholder="Investigations" class="txt_area allUpperCase grey14" rows="20"><?php if(isset($prescriptionCommment['investigations'])){echo $prescriptionCommment['investigations'];}?></textarea>
											  <div class="dropdown dropbtn" style="width:90%;">
											  <div id="dropdownInv" class="dropdown-content">
											  <input type="text" placeholder="Search.." id="myInputInv" class="myInput" onkeyup="filterFunctionInv()">
											  <div style="overflow-y:scroll;max-height:150px">
											  <ul id="listInv">
												<?php
                                                $invList= mysql_query_db("select * from health_managerdiagnosis");
                                                while($finvList= mysql_fetch_db($invList)){
                                               ?>
											   <li id="<?php echo $finvList['diagnosisName'];?>"><?php echo $finvList['diagnosisName'];?></li>
                                               <?php }?>
											   </ul>
											   </div>
										     </div>
											</div>

										  </div>
										  <div class="full5 txt_left">
											<img src="../images/plus2.png" style="height:40px;cursor:pointer;padding:10px" id="showInv">
										  </div>
										  </div>
                                         </div>
										 <div class="clearfix10"></div>
										

                                    <div class="clearfix10"></div>
                                    <div class="full">
                                        <div class="full">
										<div class="full pink_bck white14 bold">
											   <div class="full5" id="unitId_ajax">
                                                   Type
                                                </div>
                                                <div class="full15" id="med_div">
                                                    Medicine   
                                                </div>
												<div class="full15">
                                                   Composition
                                                </div>
												<div class="full5">
												 Dose
                                                </div>
                                                
												<div class="full5">
                                                 Unit   
                                                </div>
												
												<div class="full5">
                                                    Time
                                                </div>
												<div class="full10">
                                                    When
                                                </div>
												<div class="full10">
                                                    Where
                                                </div>
                                                <div class="full10">
												Frequency
                                                </div>
												<div class="full5 disnone">
                                                    No.
                                                </div>
												<div class="full10">
                                                    Duration
                                                </div>
												
												<div class="full10">
                                                   Instruction
                                                </div>
											</div>
										
                                            <div class="full pink_bck" id="template">
											   <div class="full5">
                                                    <input name="medType" id="medType" maxlength="50" placeholder="Type" class="dash_txt_box100 allUpperCase" value="" style="font-size:12px;height:30px">
                                                </div>
                                                <div class="full15" id="med_div">
                                                    <input type="text" id="tags" name="medicine" <?php if($ipdId!=''){?>autofocus<?php }?> maxlength="500"  placeholder="Medicine" class="dash_txt_box100 allUpperCase" style="font-size:12px;height:30px;" onchange="_medicineTemplate_ajax(this.value,<?php echo $ipdId;?>)">
                                                </div>
												<div class="full15" id="drugId">
                                                    <input type="text" id="drug" name="drug"  placeholder="Composition" class="dash_txt_box100 allUpperCase" style="font-size:12px;height:30px">
                                                </div>
												<div class="full5">
												<input id="dose" name="dose" maxlength="500" placeholder="Dose" class="dash_txt_box100 allUpperCase" style="font-size:12px;height:30px"> 
                                                </div>
                                                
												<div class="full5">
                                                    <input name="units" id="units" maxlength="50" placeholder="Unit" class="dash_txt_box100 allUpperCase" value="" style="font-size:12px;height:30px">
                                                </div>
												<div class="full10 disnone">
                                                   <input id="route" name="route" maxlength="500" placeholder="Route" class="dash_txt_box100 allUpperCase" style="font-size:12px;height:30px"> 
                                                </div>
												<div class="full5">
                                                    <input name="timing" id="timing" maxlength="50" placeholder="Time" class="dash_txt_box100 allUpperCase" value="" style="font-size:12px;height:30px">
                                                </div>
												<div class="full10">
                                                    <input name="when" id="when" maxlength="50" placeholder="When" class="dash_txt_box100 allUpperCase" value="" style="font-size:12px;height:30px">
                                                </div>
												<div class="full10">
                                                    <input name="where" id="where" maxlength="50" placeholder="Where" class="dash_txt_box100 allUpperCase" value="" style="font-size:12px;height:30px">
                                                </div>
                                                <div class="full10">
												<input type="text" id="frequency" name="frequency" maxlength="500"  placeholder="Frequency" class="dash_txt_box100 allUpperCase" style="font-size:12px;height:30px">
                                                </div>
												<div class="full5 disnone">
                                                    <input name="number" id="number" maxlength="50" placeholder="No." class="dash_txt_box100 allUpperCase" value="" style="font-size:12px;height:30px">
                                                </div>
												<div class="full10">
                                                    <input type="text" id="duration" name="duration" maxlength="500"  placeholder="Duration" class="dash_txt_box100 allUpperCase" style="font-size:12px;height:30px">
                                                    <ul class="dropdown-content" id="durationitem" style="cursor:pointer;width:5%"></ul>
											   </div>
												
												<div class="full10">
                                                    <input type="text" id="instruction" name="instruction" maxlength="500"  placeholder="Instruction" class="dash_txt_box100 allUpperCase" style="font-size:12px;height:30px" ondblclick="_addSaleAjax(<?php echo $ipdId;?>,medType.value,tags.value,drug.value,dose.value,units.value,timing.value,when.value,where.value,frequency.value,number.value,duration.value,instruction.value)" onfocusout="_addSaleAjax(<?php echo $ipdId;?>,medType.value,tags.value,drug.value,dose.value,units.value,timing.value,when.value,where.value,frequency.value,number.value,duration.value,instruction.value)">
                                                </div>
											</div>
										</div>
										<div class="clearfix10"></div>
                                       
                                        <?php 
                                            $i=1;
                                            $pres= mysql_query_db("select * from health_ipdprescriptiontemp where ipdId='$ipdId'");
                                            $npres=mysql_num_db($pres);
											$npres=1; //all time findings
                                            if($npres>0){
                                        ?>
                                        <div class="full grey_bck22" id="del_div">
                                            <div class="full"><!-- style="max-height:300px; overflow-y:scroll;"-->
                                                <table cellpadding="0" cellspacing="0" width="100%">
												<tr style="line-height:20px;" class="printgrey12 bold txt_left dark_bck">
													<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;">S.No.</td>
													<td class="grey_brdr_rght grey_brdr_btm" style="width:20%;">Medicine</td>
													<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;">Dose</td>
													<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;">Unit</td>
													<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;">Time</td>
													<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;">When</td>
													<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;">Where</td>
													<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;">Frequency</td>
													<!--<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;">No.</td>-->
													<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;">Duration</td>
													<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;">Instruction</td>
													<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;">Delete</td>
												</tr>
												<?php
												$i=1;
												while($fpres=mysql_fetch_db($pres)){
												?>
														<tr style="background-color:#FFFFFF; line-height:25px;" class="printgrey12 txt_left">
                                                        <td class="grey_brdr_rght grey_brdr_btm" style="width:5%;"><?php echo $i;?> <a href="javascript:void(0)" id="editMedRow" onclick="_editMedRow('<?php echo $fpres['id'];?>','<?php echo $ipdId;?>')"><img src="../images/edit.png" style="height:20px"></a></td>
														<td class="grey_brdr_rght grey_brdr_btm" style="width:20%;"><?php echo $fpres['medicine'];?> <span class="printgrey8"><?php echo strtoupper($fpres['drug']);?></span></td>
														<!--<td class="grey_brdr_rght grey_brdr_btm" style="width:16%;"><?php //echo $fpres['formulation'];?></td>
														<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;"><?php echo $fpres['route'];?></td>-->
														<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;"><?php echo $fpres['dose'];?></td>
														<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;"><?php echo $fpres['unit'];?></td>
														<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;"><?php echo $fpres['timing'];?></td>
														<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;"><?php echo $fpres['whenMed'];?></td>
														<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;"><?php echo $fpres['whereMed'];?></td>
														<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;"><?php echo $fpres['frequency'];?></td>
														<!--<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;"><?php echo $fpres['number'];?></td>-->
														<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;"><?php echo $fpres['duration'];?></td>
														<td class="grey_brdr_rght grey_brdr_btm" style="width:10%;"><?php echo $fpres['instruction'];?></td>
														<td class="grey_brdr_rght grey_brdr_btm" style="width:5%;"><a href="javascript:void(0)" onclick="_deleteSaleAjax('<?php echo $fpres['id'];?>','<?php echo $ipdId;?>')"><img src="../images/delete.png" width='25px'></a></td>
													   </tr>
														<?php 
														$i++;}?>
												</table>
                                            </div>
                                        </div>
                                       
                                        <div class="clearfix10"></div>
										<div class="full printgrey16 dark_bck">
										<div class="full25">
                                               <div class="full90">Diet Plan</div>
                                            </div>
										    <div class="full25">
											   <div class="full90">Advice</div>
                                           </div>
										   <div class="full25">
											   <div class="full90">Investigations on Followup</div>
                                           </div>
										   <div class="full25">
											<div class="full90 txt_center">Followup Days</div>
											
											</div>
                                         </div>
                                        <div class="full">
										<div class="full25">
                                                <textarea name="diet" id="diet" placeholder="Diet Plan" class="txt_area90 allUpperCase grey14" rows="20"><?php if(isset($prescriptionCommment['diet'])){echo $prescriptionCommment['diet'];}?></textarea>
                                               <div class="dropdown dropbtn" style="width:90%;">
											  <div id="dropdownDiet" class="dropdown-content">
											  <input type="text" placeholder="Search.." id="myInputDiet" class="myInput" onkeyup="filterFunctionDiet()">
											  <div style="overflow-y:scroll;max-height:150px">
											  <ul id="listDiet">
												<?php
                                                $invList= mysql_query_db("select * from health_emr_diet");
                                                while($finvList= mysql_fetch_db($invList)){
                                               ?>
											   <li id="<?php echo $finvList['details'];?>"><?php echo $finvList['name'];?></li>
                                               <?php }?>
											   </ul>
											   </div>
										     </div>
											</div>
											</div>
										    <div class="full25">
											   <textarea name="advice" id="advice" placeholder="Advice" class="txt_area90 allUpperCase grey14" rows="20"><?php if(isset($prescriptionCommment['advice'])){echo $prescriptionCommment['advice'];}?></textarea>
                                           </div>
										   <div class="full30">
										    <div class="full85">   
										   <textarea name="invFollowup" id="invFollowup" placeholder="Investigations on Followup" class="txt_area90 allUpperCase grey14" rows="20"><?php if(isset($prescriptionCommment['invFollowup'])){echo $prescriptionCommment['invFollowup'];}?></textarea>
                                            
											<div class="dropdown dropbtn" style="width:90%;">
											  <div id="dropdownInvFollow" class="dropdown-content">
											  <input type="text" placeholder="Search.." id="myInputInvFollow" class="myInput" onkeyup="filterFunctionInvFollow()">
											  <div style="overflow-y:scroll;max-height:150px">
											  <ul id="listInvFollow">
												<?php
                                                $invList= mysql_query_db("select * from health_managerdiagnosis");
                                                while($finvList= mysql_fetch_db($invList)){
                                               ?>
											   <li id="<?php echo $finvList['diagnosisName'];?>"><?php echo $finvList['diagnosisName'];?></li>
                                               <?php }?>
											   </ul>
											   </div>
										     </div>
											</div>
											
										   </div>
										   <div class="full0 txt_left">
											<img src="../images/plus2.png" style="height:40px;cursor:pointer;padding:10px" id="showInvFollow">
										   </div>
											</div>
										   <div class="full20">
										   <div class="full">
											<div class="full30 grey14 line_hgt25 bold"> Date </div>
											<div class="full70">
										    <input required type="text" name="days" maxlength="" placeholder="" class="datecalender dash_txt_box50 allUpperCase" value="<?php if(isset($prescriptionCommment['days'])){echo $prescriptionCommment['days'];} else {echo $today;}?>">
											</div>
											</div>
											
											<div class="clearfix5"></div>
											<!----template--->
											<div class="full">
											<div class="full30 grey14 line_hgt25 bold"> Rx Group </div>
											<div class="full70">
											<select  name="templateId"  id="templateId" class="select_txt82 grey14" onchange="_fillTemplate(this.value,<?php echo $ipdId;?>)">
												<option value="0">-- NA --</option>
												<?php
                                               $tempList= mysql_query_db("select * from health_opdprescriptiongroup group by templateId order by name ASC");
                                                while($ftempList= mysql_fetch_db($tempList)){
                                               ?>
                                                <option value="<?php echo $ftempList['templateId'];?>"><?php echo ucwords($ftempList['name']);?></option>
                                                <?php }?>
										     </select>
											</div>
											</div>
											
											<div class="full">
											<div class="full30 grey14 line_hgt25 bold"> Ix Group </div>
											<div class="full70">
											<select disabled  name="templateId"  id="templateId" class="select_txt82 grey14" onchange="_fillTemplate(this.value,<?php echo $ipdId;?>)">
												<option value="0">-- NA --</option>
												<?php
                                               $tempList= mysql_query_db("select * from health_opdprescriptiongroup group by templateId order by name ASC");
                                                while($ftempList= mysql_fetch_db($tempList)){
                                               ?>
                                                <option value="<?php echo $ftempList['templateId'];?>"><?php echo ucwords($ftempList['name']);?></option>
                                                <?php }?>
										     </select>
											</div>
											</div>
											
											</div>
                                         </div>
										 <div class="clearfix10"></div>
										<div class="full">
										<div class="full20r txt_right">
                                           
											<input id="sbt_button" type="submit" name="submit" value="<?php if($fnumCom==0){echo "Submit";}else{echo "Edit";} ?>" class="dash_btn">
                                            <input id="prt_button" type="submit" name="submit" value="Print" class="dash_btn" style="display:<?php if($fnumCom!=0){echo 'none';}?>">
                                            
                                            
                                        </div>
                                         </div>  
                                        <?php } ?>
                                    </div>
                                    <div class="clearfix10"></div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <?php if($fopd['patientId']){?>
            <div class="clearfix20"></div>
            <div class="mauto95">
                <div class="full">
                    <form name="add_invoice" id="add_invoice" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="add_invoice" value="1">
                        <div class="full grey_bck22 box_shadow66"><!--full80r-->
                            <div class="full line_hgt35 grey_bck">  <!--right_side_head-->
                                <div class="mauto95">
                                    <div class="full">
                                        <div class="full50 white16 bold">Rx History</div>
                                    </div>
                                </div>
                            </div>
                            <script>
                                function _showHistory2(r,n){
                                    if(document.getElementById('his2_'+r).style.display=='none'){
                                        for(var k=1;k<=n;k++){
                                            document.getElementById('his2_'+k).style.display='none';
                                        }
                                        document.getElementById('his2_'+r).style.display='block';
                                    } else {
                                      document.getElementById('his2_'+r).style.display='none';  
                                    }
                                }
								   function _showHistory(r,n){
                                    if(document.getElementById('his_'+r).style.display=='none'){
                                        for(var k=1;k<=n;k++){
                                            document.getElementById('his_'+k).style.display='none';
                                        }
                                        document.getElementById('his_'+r).style.display='block';
                                    } else {
                                      document.getElementById('his_'+r).style.display='none';  
                                    }
                                }
                            </script>
                            <div class="full">
                                <div class="mauto95">
                                    <div class="full">
                                        <div class="clearfix10"></div>
                                        <div class="full grey_bck22" id="">
                                            <div class="full" style="max-height:auto; overflow-y:scroll;">
                                                <table cellpadding="0" cellspacing="0" width="100%">
                                                   
                                                    <?php
                                                        $j=1;
                                                        $dtl= mysql_query_db("select * from health_ipdprescriptioncomment where patientId='".$fopd['patientId']."' order by counter desc");
                                                        while($fdtl= mysql_fetch_db($dtl)){
															
                                                    ?>
                                                    <tr class="printgrey14 txt_left line_hgt20 white_bck">
                                                         <td class="grey_brdr_rght grey_brdr_btm" style="width:5%">S.No: <?php echo $j;?></td>
														 <td class="grey_brdr_rght grey_brdr_btm" style="width:5%">IPD ID: <?php echo $fdtl['ipdId'];?></td>
														 <td class="grey_brdr_rght grey_brdr_btm" style="width:10%">Date: <?php $datetime = new DateTime( $fdtl['post_date'] ); echo $datetime->format( 'd-M-Y' );?></td>
														 <td  class="grey_brdr_rght grey_brdr_btm" style="width:10%;">Followup Date: <?php echo $fdtl['days'];?></td>
												         <td class="grey_brdr_rght grey_brdr_btm" style="width:10%">Print: <a href="ipd-prescription-print-preview.php?patientId=<?php echo $fopd['patientId'];?>&ipdId=<?php echo $fdtl['ipdId'];?>&counter=<?php echo $fdtl['counter'];?>&reprint=1" title="Click for Print"><img src="../images/print.png" height="20px"></a> <a href="doctor-index-edit.php?ipdId=<?php echo $fdtl['ipdId'];?>&edit=1" style="text-decoration: none;" title="Click for Edit" class="blue14 disnone"><img src="../images/edit.png" height="20px" style="display:<?php if($role=='0'){echo 'none';}?>"></a> </td>
														 <td  class="grey_brdr_rght grey_brdr_btm" style="width:10%;">Expand Rx: <a href="javascript:void(0)" onclick="_showHistory('<?php echo $j;?>','<?php echo $nhis;?>')"><i class="fa fa-arrows-alt" style="color:red;font-size:20px;"></i></a></td>
														 <td  class="grey_brdr_rght grey_brdr_btm" style="width:10%;">Copy Rx: <a href="javascript:void(0)" onclick="_pullRx('<?php echo $fdtl['ipdId'];?>','<?php echo $ipdId;?>')"><img src="../images/copy.png" height="30px"> </a></td>
												   </tr>
												  
												   <tr class="printgrey14 txt_left line_hgt20">
												   <td colspan="11"  class="grey_brdr_rght grey_brdr_btm" style="width:15%;"><b>Gen Examination:</b> <?php echo strtoupper($fdtl['genExamination']);?></td>
												   </tr>
												   <tr class="printgrey14 txt_left line_hgt20">
												   <td colspan="11"  class="grey_brdr_rght grey_brdr_btm" style="width:15%;"><b>Sys Examination:</b> <?php echo strtoupper($fdtl['sysExamination']);?></td>
												   </tr>
												   <tr class="printgrey14 txt_left line_hgt20">
												   <td  colspan="11"  class="grey_brdr_rght grey_brdr_btm" style="width:15%;"><b>Pro Diagnosis:</b> <?php echo $fdtl['provDiagnosis'];?></td>
													</tr>
													<tr class="printgrey14 txt_left line_hgt20">
													<td colspan="11"  class="grey_brdr_rght grey_brdr_btm" style="width:15%;"><b>Ix:</b> <?php echo $fdtl['investigations'];?></td>
													</tr>
													<tr class="printgrey14 txt_left line_hgt20">
													<td colspan="11"  class="grey_brdr_rght grey_brdr_btm" style="width:10%;"><b>Diet:</b> <?php echo $fdtl['diet'];?></td>
                                                    </tr>
													<tr class="printgrey14 txt_left line_hgt20">
													<td colspan="11"  class="grey_brdr_rght grey_brdr_btm" style="width:10%;"><b>Advice:</b> <?php echo $fdtl['advice'];?></td>
													</tr>
													<tr class="printgrey14 txt_left line_hgt20">
													<td colspan="11"  class="grey_brdr_rght grey_brdr_btm" style="width:10%;"><b>Ix Followup:</b> <?php echo $fdtl['invFollowup'];?></td>
												    </tr>
													
                                                    <tr style="background-color:#FFFFFF; line-height:25px;" class="grey14 txt_right">
                                                        <td class="grey_brdr_rght" style="width:100%;" colspan="10">
                                                            <div class="full blue_border" id="his_<?php echo $j?>" style="display:none;">
															
                                                             <table cellpadding="0" cellspacing="0" width="100%">
															 <tr class="printgrey14 txt_center dark_bck">
																<td class="grey_brdr_top grey_brdr_btm" style="width:5%;">S.No.</td>
																<td class="grey_brdr_top grey_brdr_btm txt_left" style="width:20%;">Medicine</td>
																<td class="grey_brdr_top grey_brdr_btm txt_left" style="width:5%;">Dosage</td>
																<td class="grey_brdr_top grey_brdr_btm " style="width:10%;"></td>
																<td class="grey_brdr_top grey_brdr_btm" style="width:10%;"></td>
																<td class="grey_brdr_top grey_brdr_btm" style="width:10%;"></td>
																<td class="grey_brdr_top grey_brdr_btm" style="width:10%;"></td>
															</tr>
															<?php
															 $pres= mysql_query_db("select * from health_ipdprescriptionfinal where ipdId='".$fdtl['ipdId']."' and counter='".$fdtl['counter']."'");
															 $presNum=mysql_num_db($pres);
															 if($presNum!=0){
												 
															$i=1;
															while($fpres=mysql_fetch_db($pres)){
															?>
															<tr  class="grey14 txt_center line_hgt20">
																	<td class=" " style="width:5%;"><?php echo $i;?>.</td>
																	<td class="txt_left" style="width:20%;"><?php if(!empty($fpres['medType'])){echo $fpres['medType'];}?> <?php echo $fpres['medicine'];?><?php if(!empty($fpres['unit'])){echo "-".$fpres['unit'];}?></td>
																	<td class="txt_left" style="width:5%;"><?php echo $fpres['dose'];?></td>
																	<td class="txt_left" colspan="2" style="width:10%;"><?php echo ucwords($fpres['timing']." ".$fpres['whenMed']);?></td>
																	<td class="txt_left" style="width:10%;"><?php echo ucwords($fpres['frequency']." ".$fpres['duration']);?></td>
																	<td class="txt_left" style="width:10%;"><?php echo ucwords($fpres['whereMed']);?></td>
																	
														   </tr>
														   <tr  class="grey14 txt_center line_hgt20">
																<td class="grey_brdr_btm txt_left" colspan="3" style="width:20%;"><span class="printgrey12">Composition:<?php echo strtoupper($fpres['drug']);?></span></td>
																<td class="grey_brdr_btm txt_left" colspan="4" style="width:10%;">Note:<?php echo ucwords($fpres['instruction']);?></td>
																	
														   </tr>
														<?php 
														$i++;}?>
														</table> 
                                                            </div>
                                                        </td>
                                                    </tr>
														<?php $j++; }}?>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="clearfix20"></div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <?php }?>
        </div>
        <div class="clearfix10"></div>
        <?php include("../footer-inc.php");?>
        </div>
<script>
/* Auto Drop box for user clicks*/

function myFunctionInv() {
  document.getElementById("dropdownInv").classList.toggle("show");
}
function filterFunctionInv() {
  var input, filter, ul, li, a, i;
  input = document.getElementById("myInputInv");
  filter = input.value.toUpperCase();
  div = document.getElementById("dropdownInv");
  a = div.getElementsByTagName("li");
  for (i = 0; i < a.length; i++) {
    txtValue = a[i].textContent || a[i].innerText;
    if (txtValue.toUpperCase().indexOf(filter) > -1) {
      a[i].style.display = "";
    } else {
      a[i].style.display = "none";
    }
  }
}
 
  function myFunctionInvFollow() {
  document.getElementById("dropdownInvFollow").classList.toggle("show");
}
function filterFunctionInvFollow() {
  var input, filter, ul, li, a, i;
  input = document.getElementById("myInputInvFollow");
  filter = input.value.toUpperCase();
  div = document.getElementById("dropdownInvFollow");
  a = div.getElementsByTagName("li");
  for (i = 0; i < a.length; i++) {
    txtValue = a[i].textContent || a[i].innerText;
    if (txtValue.toUpperCase().indexOf(filter) > -1) {
      a[i].style.display = "";
    } else {
      a[i].style.display = "none";
    }
  }
} 

function myFunctionDia() {
  document.getElementById("dropdownInv").classList.toggle("show");
}
function filterFunctionDia() {
  var input, filter, ul, li, a, i;
  input = document.getElementById("myInputDia");
  filter = input.value.toUpperCase();
  div = document.getElementById("dropdownDia");
  a = div.getElementsByTagName("li");
  for (i = 0; i < a.length; i++) {
    txtValue = a[i].textContent || a[i].innerText;
    if (txtValue.toUpperCase().indexOf(filter) > -1) {
      a[i].style.display = "";
    } else {
      a[i].style.display = "none";
    }
  }
}
function myFunctionDiet() {
  document.getElementById("dropdownDiet").classList.toggle("show");
}
function filterFunctionDiet() {
  var input, filter, ul, li, a, i;
  input = document.getElementById("myInputDiet");
  filter = input.value.toUpperCase();
  div = document.getElementById("dropdownDiet");
  a = div.getElementsByTagName("li");
  for (i = 0; i < a.length; i++) {
    txtValue = a[i].textContent || a[i].innerText;
    if (txtValue.toUpperCase().indexOf(filter) > -1) {
      a[i].style.display = "";
    } else {
      a[i].style.display = "none";
    }
  }
}

function pulsar(obj) {
  obj.value=obj.value.toUpperCase();
}
</script>
		<script>
		$(document).ready(function() {
		//id dbl click	
		$("#investigations").dblclick(function() { 
        $("#dropdownInv").toggleClass("show2");
		$("#myInputInv").focus();
         }); 	
		 
		 $("#showInv").click(function() { 
		  $("#dropdownInv").toggleClass("show2");
		 }); 
		 
		//fill investigations id textarea
		$("#listInv li").click(function() { 
        var item=$(this).attr("id");
		var txt=$("#investigations").val();
				if(txt.includes(item)){
				//nothing
				}
				else{
					if(txt==""){
					txt=txt.concat(''+item);	
					}
					else{
					txt=txt.concat(', '+' '+item);	
					}
				}
				$("#investigations").val(txt);
         }); 
		 
		 //for investigations followup
		
		$("#invFollowup").dblclick(function() { 
        $("#dropdownInvFollow").toggleClass("show2");
		$("#myInputInvFollow").focus();
         }); 	
		 
		 $("#showInvFollow").click(function() { 
		  $("#dropdownInvFollow").toggleClass("show2");
		 }); 
		 
		//fill investigations id textarea
		$("#listInvFollow li").click(function() { 
        var item=$(this).attr("id");
		var txt=$("#invFollowup").val();
				if(txt.includes(item)){
				//nothing
				}
				else{
					if(txt==""){
					txt=txt.concat(''+item);	
					}
					else{
					txt=txt.concat(', '+' '+item);	
					}
				}
				$("#invFollowup").val(txt);
         });
		 
		 //for diet

		$("#diet").dblclick(function() { 
        $("#dropdownDiet").toggleClass("show2");
		$("#myInputDiet").focus();
         }); 	
		 
		 $("#showDiet").click(function() { 
		  $("#dropdownDiet").toggleClass("show2");
		 }); 
		 
		//fill investigations id textarea
		$("#listDiet li").click(function() { 
        var item=$(this).attr("id");
		var txt=$("#diet").val();
				if(txt.includes(item)){
				//nothing
				}
				else{
					if(txt==""){
					txt=txt.concat(''+item);	
					}
					else{
					txt=txt.concat(', '+' '+item);	
					}
				}
				$("#diet").val(txt);
         });
		 //end diet
		 
		 
		 //for pro diagnosis-list
		$("#findDiagnosis").click(function() { 
        $("#dropdownDia").toggleClass("show2");
		$("#myInputDia").focus();
         }); 	
		 
		 $("#showDia").click(function() { 
		  $("#dropdownDia").toggleClass("show2");
		 }); 
		 
		//tabular 
		$("#listDia li").click(function() { 
		var item=$(this).attr("id");
		$("#dia-list").append('<tr id='+item+'><td style="width:50%"><input style="width:95%" type="text" name=nameDiagnosis[] value="'+item+'"></td><td style="width:20%" class="durationDiagnosis"><input style="width:100%" type="text" name=durationDiagnosis[] class='+item+' id="duration'+item+'" onkeyup="pulsar(this)"><ul class="dropdown-content dialist" id=list'+item+' style="cursor:pointer"></ul></td><td style="width:10%;cursor:pointer;text-align:center"><img src="../images/delete.png" height="20px" id="rmv_btn" class='+item+'></td></tr>');
		//$("#test-list").append('<tr id='+testId+' class="new-rows"><td><input type="hidden" name=testIds[] value='+testId+'> '+testName+ " - " +current+' </td><td><input required type="text" id="q'+testId+'" name=quantity[] value="" onchange="$.fn.inventory(this.value,'+current+','+testId+')" onkeypress="return _isNumberKey(event)"></td><td id="rmv_btn"><input type="button" value="Remove" name="remove" class='+testId+'></td></tr>');
        }); 
		 $("#listDia li").on("click",function() {
			 $(".datecalender" ).datepicker({ dateFormat: 'yy-mm-dd' });
		 });
		 
		$(document).on("click",'#rmv_btn' ,function(){
		var cls=$(this).attr('class');
		//alert(cls);
		$('#' + cls).remove();
		});
		
		//for duration 
		 $(document).on("change keyup ",'.durationDiagnosis input[type=text]' ,function(){
		 //alert("g");
		 var did=$(this).attr('class');
		 var dAdd=$(this).val();
		 dAdd=dAdd.trim()
		 //alert(did);
		 if(dAdd.length != 0 && dAdd!=0 && $.isNumeric(dAdd)){
		 var itemSelect=did+","+dAdd;
		 $('#list'+did).html("<li id='"+itemSelect+"Days'>"+dAdd+" Day(s)</li><li id='"+itemSelect+"Months'>"+dAdd+" Month(s)</li><li id='"+itemSelect+"Weeks'>"+dAdd+" Week(s)</li><li id='"+itemSelect+"Years'>"+dAdd+" Year(s)</li>");
		 $('#list'+did).removeClass("hide2");
		 $('#list'+did).addClass("show2");
		 }
		 });
		 
		$(document).on("click",'.dialist li' ,function(){
         var item=$(this).attr("id");
		 var htmlitems=$(this).text();
		 var strarray = item.split(',');
		 $("."+strarray[0]).val(htmlitems);
		 //$(.dropdown-content).addClass("hide");
		 $('#list'+strarray[0]).addClass("hide2");
		});
		//end duration
		 
		 
		//pro dia end 
		$('#add_invoice').on("submit",function(){
			$("#sbt_button").css("background-color","rgba(123,123,123)");
			$("#prt_button").css("background-color","rgba(123,123,123)");
		});
		
		 //for duration 
		 $(document).on("change keyup ",'#duration' ,function(){
		 //alert("g");
		 var dAdd=$(this).val();
		 dAdd=dAdd.trim()
		 //alert(dAdd);
		 if(dAdd.length != 0 && dAdd!=0 && $.isNumeric(dAdd)){
		 var itemSelect=dAdd;
		 $('#durationitem').html("<li id='"+itemSelect+"Days'>"+dAdd+" Day(s)</li><li id='"+itemSelect+"Months'>"+dAdd+" Month(s)</li><li id='"+itemSelect+"Weeks'>"+dAdd+" Week(s)</li><li id='"+itemSelect+"Years'>"+dAdd+" Year(s)</li>");
		 $('#durationitem').removeClass("hide2");
		 $('#durationitem').addClass("show2");
		 }
		
		 });
		 
		 $(document).on("click",'#durationitem li' ,function(){
         var item=$(this).attr("id");
		 var htmlitems=$(this).text();
		 var strarray = item.split(',');
		 $("#duration").val(htmlitems);
		 //$(.dropdown-content).addClass("hide");
		 $("#durationitem").addClass("hide2");
		});
		
		//end duration



		});
        </script> 
    </body>
	</html>