<?php  include('techsyn_header.php'); ?>

<!-- Main Content Container for side bar and body-->
<style>
input{

    margin-left: 20px;

}
</style>
<div class="main-container ace-save-state" id="main-container">

	<script type="text/javascript">

			try{ace.settings.loadState('main-container')}catch(e){}

		</script>

		<?php  include('techsyn_sidebar.php'); ?>

	<div class="main-content">

		<div class="main-content-inner">

			<div class="breadcrumbs ace-save-state" id="breadcrumbs">

				<ul class="breadcrumb">

					<li><i class="ace-icon fa fa-home home-icon"></i> <a href="#">Home</a>

					</li>

					<li class="#">Patient Visit</li>
					<li class="active">Health Surveillance</li>

				</ul>
 <?php    $sql_patient_physical_parameters="select * from medical_examination where medical_exam_id='".$_REQUEST['medical_exam_id']."'"; 
                            $result_patient_physical_parameters= mysqli_query($conn,$sql_patient_physical_parameters);
                           $row_patient_physical_parameters= mysqli_fetch_assoc($result_patient_physical_parameters);											         
                            @extract($row_patient_physical_parameters);		
											
											?>




			</div>
			<div class="page-content">
				<div class="box box-primary"
					style="padding: 10px; margin: 2px 0px 50px 5px; width: 99.5%;">
					<div class="box-header with-border">
						<h3 class="box-title">ANNUAL MEDICAL EXAMINATION (BELOW 40 YEARS)</h3>
					</div>
					<div id="user-profile-2">
						<form class="form-horizontal" id="medical_examination_form"
							name="medical_examination_form" enctype="multipart/form-data" action="#"
							method="post">
							<div class="box-body">
								<div class="row">
									<div class="col-sm-12">
										<table class="table table-bordered">
											<tr>
											    
												<td><b> Height(cms)</b> <input type="hidden" style="height: 30px;" class="col-xs-4"
												 id="hiddenHighlighter" name="hiddenHighlighter" ><input style="margin-left:20px" type="number" name="height" id="height" value="<?php  echo $height ?>"/></td>
												<td><b> Weight(kgs)</b><input style="margin-left:20px" type="number" name="weight" id="weight" value="<?php  echo $weight ?>" /></td>
												<td colspan="2"><b style="margin-left: 188px ">CLINICAL EXAMINATION</</b></td>
												
											</tr>
											<tr>
												<td></td>
												<td></td>
												<td colspan="2"><b > PALLOR</b> <input style="margin-left:171px;width:46%" type="text" name="pallor" id="pallor" value="<?php  echo $pallor ?>" /></td>
											</tr>
											<tr>
												<td></td>
												<td></td>
												<td colspan="2"><b >PULSE</b><input style="margin-left:181px;width:46%" type="number" name="pulse" id="pulse" value="<?php  echo $pulse ?>"  /></td>
											</tr>
											
											<tr>
												<td colspan="2"><b style="margin-left: 188px ">Vision</</b></td>
												
												<td colspan="2"><b >BP</b><input style="margin-left:202px;width:151px" type="text" name="bp" id="bp"  value="<?php  echo $bp ?>"  />&nbsp;&nbsp;mm of Hg</td>
											</tr>
											
											<tr>
											 <td ></td>
												<td ><b style="margin-left:100px">RT.EYE</b><b style="margin-left:134px">LT.EYE</b></td>
												
												<td colspan="2" rowspan="2"><b style="vertical-align: top"> CVS</b> <textarea name="cvs" id="cvs" style="margin-left: 92px"rows="4" cols="50"><?php  echo $cvs?></textarea></td>
											  
												
											</tr>
											<tr>
											<td > <b>Distant Vision</b> <b style="margin-left:170px">Without Glasses</b></td>
												<td ><b>6/</b><input style="margin-left:3px" type="text" name="dis_without_right_eye" id="dis_without_right_eye"  value="<?php  echo $dis_without_right_eye ?>"  /><b style="margin-left:20px">6/</b><input style="margin-left:2px" type="text" name="dis_without_left_eye" id="dis_without_left_eye" value="<?php  echo $dis_without_left_eye ?>" /></td>
												
											 <!-- <option value="">Please Select Option</option>
											  <?php  
											  $param_values=$data[1]['parameter_value'];
											  $parameter_values_array = explode(",", $param_values);
											   for ($p = 0; $p < count($parameter_values_array); $p ++) {?>
											   	 <option value="<?php  echo $parameter_values_array[$p]; ?>"><?php  echo getTableFieldValue('medical_parameter_value', 'med_param_value', 'med_param_val_id',$parameter_values_array[$p])?></option>
											   	
											   <?php  }
											  
											  ?> 
											  </select>-->
                                                 </td>	
											</tr>
											<tr>
											    <td align="right"><b >With Glasses</b></td>
												<td ><b>6/</b><input style="margin-left:3px" type="text" name="dis_with_right_eye" id="dis_with_right_eye" value="<?php  echo $dis_with_right_eye ?>" /><b style="margin-left:20px">6/</b><input style="margin-left:2px" type="text" name="dis_with_left_eye" id="dis_with_left_eye"  value="<?php  echo $dis_with_left_eye ?>" /></td>
												<td colspan="3" rowspan="2" > <b style="vertical-align: top">RS</b><textarea  name="rs" id="rs" style="margin-left: 100px" rows="4" cols="50"><?php  echo $rs?></textarea></td>
											</tr>
											<tr>
												<td > <b>Near Vision</b> <b style="margin-left:185px">Without Glasses</b></td>
												<td ><b>N/</b><input style="margin-left:3px" type="text" name="near_without_right_eye" id="near_without_right_eye" value="<?php  echo $near_without_right_eye ?>" /><b style="margin-left:20px">N/</b><input style="margin-left:3px" type="text" name="near_without_left_eye"   id="near_without_left_eye"  value="<?php  echo $near_without_left_eye ?>" /></td>
													
											</tr>
											<tr>
											  <td align="right"><b >With Glasses</b></td>
												<td ><b>N/</b><input style="margin-left:3px" type="text" name="near_with_right_eye" id="near_with_right_eye" value="<?php  echo $near_with_right_eye ?>" /><b style="margin-left:20px">N/</b><input style="margin-left:3px" type="text" name="near_with_left_eye" id="near_with_left_eye"  value="<?php  echo $near_with_left_eye ?>" /></td>
												<td colspan="3" rowspan="2" > <b style="vertical-align: top">MUSCULO SKELETAL</b><textarea id="musculo_skeletal"  name="musculo_skeletal"  style="margin-left: 8px"rows="4" cols="50"><?php  echo $musculo_skeletal ?></textarea></td>
											
											</tr>
											
												<tr>
											  <td colspan="2" ><b >COLOR VISION</b>
											<?php  
											   if($color_vision!=null && $color_vision!=""){
											   	?>
											   	  <input style="margin-left: 214px"  type="radio" name="color_vision" id="color_vision" <?php  if($color_vision=='NORMAL') echo "checked"; ?> value="NORMAL"  />&nbsp;&nbsp;NORMAL&nbsp;&nbsp; <input type="radio"  style="margin-left:75px" name="color_vision" id="color_vision"  <?php  if($color_vision=='DEFECTIVE') echo "checked"; ?> value="DEFECTIVE"  />&nbsp;&nbsp;DEFECTIVE&nbsp;&nbsp;
											   	
											  <?php  }else{?>
											   	  <input style="margin-left: 214px"  type="radio" name="color_vision" id="color_vision" checked value="NORMAL"  />&nbsp;&nbsp;NORMAL&nbsp;&nbsp; <input type="radio"   style="margin-left:75px" name="color_vision" id="color_vision"  value="DEFECTIVE"  />&nbsp;&nbsp;DEFECTIVE&nbsp;&nbsp;
											   	
											  <?php  }
											  
											  ?>
											  
											
											  </td>
											
												
											
											</tr>
											<tr>
											
											  <td colspan="2" rowspan="2" ><b >IDENTIFICATION OF INDIVIDUAL COLOURS</b>
											  <?php  
											   if($ident_of_individual_colors!=null && $ident_of_individual_colors!=""){
											   	?>
											   	  <input style="margin-left: 80px"  type="radio"  checked name="ident_of_individual_colors" id="ident_of_individual_colors"   <?php  if($ident_of_individual_colors=='NORMAL') echo "checked"; ?> value="NORMAL"  />&nbsp;&nbsp;Normal&nbsp;&nbsp; <input type="radio"  style="margin-left:75px" name="ident_of_individual_colors" id="ident_of_individual_colors"  <?php  if($ident_of_individual_colors=='DEFECTIVE') echo "checked"; ?> value="DEFECTIVE" />&nbsp;&nbsp;DEFECTIVE&nbsp;&nbsp;
									
											   <?php  }else{?>
											     <input style="margin-left: 80px"  type="radio"  checked name="ident_of_individual_colors" id="ident_of_individual_colors" value="NORMAL"  />&nbsp;&nbsp;NORMAL&nbsp;&nbsp; <input type="radio"  style="margin-left:75px" name="ident_of_individual_colors" id="ident_of_individual_colors"  value="DEFECTIVE" />&nbsp;&nbsp;DEFECTIVE&nbsp;&nbsp;
									
											    <?php  }
											  
											  ?>
											  </td>
											  
											 <td colspan="2" ><b style="vertical-align: top">ENT</b><textarea name="ent" id="ent" style="margin-left: 94px"rows="4" cols="50"><?php  echo $ent ?></textarea></td>
												
											
											</tr>
											<tr>
											
											</tr>
											 <tr>
											  
												
											   
											</tr>
											<tr>
											 <td colspan="2" rowspan="2" >
											  </td>
											
											 
											 </tr>
											 <tr>	
											  
											  
											  <td colspan="2"><b style="vertical-align: top">ABDOMEN</b>
											  
											   <textarea  name="abdomen" id="abdomen" style="margin-left: 61px"rows="4" cols="50"><?php  echo $abdomen ?></textarea></td>
											 
											
											
											</tr>
										 <tr>	
											  
											  <td colspan="2"></td>
											  <td colspan="2"><b style="vertical-align: top">ANY OTHER REL. FINDING</b>
											  
											   <textarea name="other_relevant_findings" id="other_relevant_findings"  style="margin-left:-45pxpx"rows="4" cols="50"><?php  echo $other_relevant_findings ?></textarea></td>
											 
											
											
											</tr>
											 <tr>	
											  
											  <td colspan="2"></td>
											  <td colspan="2"><b >Random Blood Sugar</b>
											  
											  <input style="margin-left:181px;width:46%" type="text" name="blood_sugar" id="blood_sugar" value="<?php  echo $blood_sugar ?>">
											 
											
											
											</tr>
											<?php include 'support_medical_document.php'?>
												
											<?php 
											   $query = "select * from employee_signature where emp_id='" . $_SESSION['logged_user_empid'] . "'  ";
											  //R echo $query;
											   if (! $result = @mysqli_query($conn,$query)) {
											   	exit(mysqli_error($conn));
											   }else{
											   	$row = @mysqli_fetch_array($result);
											    @extract($row);
                                      
											   }
											?>
											<?php  if(isset($row['emp_sign']) && $row['emp_sign']!=null){?>
											<tr>
											<td><b>Signature Of Medical Assistant</b></br></br><input  type="radio" name="signature_medical_assistant" id="signature_medical_assistant" value="add" />&nbsp;&nbsp;Add <input style="margin-left:40px"  type="radio" name="signature_medical_assistant" id="signature_medical_assistant" value="remove"  />&nbsp;&nbsp;Remove</td>
											<td colspan="2">
											 <span class="profile-picture" style="margin-left:170px;display:none" >
													
													<img class="editable img-responsive" id="avatar"
												src="data:<?php  echo $row['image_type']?>;base64,<?php  echo base64_encode( $row['emp_sign'] )?>"
												style="display: block; width: 180px; height: 50px;" />
													
											 </span>
											 </td>
											</tr>
											 <?php }?>	
											
											 
										
										
											
										</table>
									</div>
								</div>


							</div>
							
											
							
							 <input type="hidden" name="medical_exam_id" id="medical_exam_id" value="<?php  echo $_REQUEST['medical_exam_id']; ?>">
								<div class="box-footer" style="text-align: center">

								<button class="btn btn-primary" type="button" id="save_button"
									onclick="save_medical_examination()">

									<i class="ace-icon fa fa-save"></i> Save

								</button>
								<button class="btn btn-primary" type="button" id="update_button" style="display:none"
									onclick="save_medical_examination()">

									<i class="ace-icon fa fa-floppy"></i> Update

								</button>
								

								  
									<button class="btn btn-warning"  id="reset_button" type="reset" >

										<i class="ace-icon fa fa-undo"></i> Reset

									</button>

								   
									 <button class="btn btn-success" id="forward_button" onclick="save_medical_examination(this.id)" >

											<i class="ace-icon fa fa-save"></i>Save & Forward

									</button>
							</div>
						
						</form>
					</div>
				</div>



			</div>
		</div>
	</div>
	 <?php include 'image_popup.php'?>
	<?php  include('techsyn_footer.php'); ?>
	<script>
	$("input:radio[name=signature_medical_assistant]"). click(function(){
		 var signatue=$('input:radio[name=signature_medical_assistant]:checked').val();
		    if(signatue=='add'){
			    $(".profile-picture").show();
		    }else{
		    	$(".profile-picture").hide();
		    }
  
});            

	 /*$("#forward_button").on("click", function(){
		 $("#medical_examination_form").submit(function(e){
		        e.preventDefault();
		    });
	     		
		 
		 $("#save_button").hide();
		 BootstrapDialog.show({
	         title: 'Forward',
	         message: '<select class="form-control"  id="forward_status"  style="margin-left:100px;width:60%"><option value="" >Please Select Forward Option</option><option value="R" > Receptionist </option><option value="D" > Doctor </option></select>',
	         buttons: [{
	             label: 'OK',
	             action: function() {
	                 save_forward_status();
	                 $(".close").click();
	             }
	         }]
	     });

		

	 });*/

	   function save_forward_status(){

		   $.ajax({
	           url:'save_medical_examination.php',
	           type:'POST',
	           data:{forward_status:$("#forward_status").val(),medical_exam_id:$("#medical_exam_id").val()},
	           success:function(data){
	               BootstrapDialog.alert("Foward Status  Saved Successfully");
	           },
	           error:function(data){
	          	 BootstrapDialog.alert(" Error In Saving Foward Status ");
	           }
			      });

	   }
			

	function save_medical_examination(id){
		 $("#medical_examination_form").submit(function(e){
		        e.preventDefault();
		    });
		
		
		 $.ajax({
             url:'save_medical_examination.php',
             type:'POST',
             data:$("#medical_examination_form").serialize(),
             success:function(data){
                 //BootstrapDialog.alert("Medical Examination Form Saved Successfully");
            	 BootstrapDialog.show({
        	         title: 'Information',
        	         message: 'Medical Examination Form Saved Successfully',
        	         buttons: [{
        	             label: 'OK',
        	             action: function() {
        	            	 $(".close").click();
        	                if(id=='forward_button'){
        	                	BootstrapDialog.show({
        	           	         title: 'Forward',
        	           	         message: '<select class="form-control"  id="forward_status"  style="margin-left:100px;width:60%"><option value="" >Please Select Forward Option</option><option value="R" > Receptionist </option></option><option value="D" > Doctor </option></select>',
        	           	         buttons: [{
        	           	             label: 'OK',
        	           	             action: function() {
        	           	                 save_forward_status();
        	           	                 $(".close").click();
        	           	             }
        	           	         }]
        	           	     });		

        	                }
        	             }
        	         }]
        	     });		
             },
             error:function(data){
            	 BootstrapDialog.alert(" Error In SavingMedical Examination Form");
             }
		      });
       
		
 
	}         
	

	 
// creat new array to store values
	ids_value = new Array();
	hiddenHighlighter = document.getElementById('hiddenHighlighter');

	// double click color validaton array
	function dblClickcolorValidation(id){
        ids = id;
        ids_value = hiddenHighlighter.value.split(","); 
        // console.log("stored values:"+ids_value);
	       // get the hidden color validation input tag
        hiddenHighlighter = document.getElementById('hiddenHighlighter'); 
        if(ids.style.borderColor=='tomato' || ids.style.color=='tomato'){
        	ids.style.borderColor='lightgrey';
        	 ids.style.color='black';
        	 removeItemOnce(ids_value, ids.name);
        	 hiddenHighlighter.value = ids_value.join();
        	 // console.log(hiddenHighlighter.value);


        }else{	
        ids.style.borderColor='tomato';
        ids.style.color='tomato';
       		 ids_value.push(ids.name);
       		 console.log(ids_value);
        	 hiddenHighlighter.value = ids_value.join();
        	 // console.log(hiddenHighlighter.value);
        }
        // console.log(ids_value);
     }

	function removeItemOnce(arr, value) {
 		var index = arr.indexOf(value);
 		if (index > -1) {
 		arr.splice(index, 1);
  		}
  		return arr;
	}
        
	var highlightedFields="<?php  echo getFieldFromTable("highlighted_fields", "medical_examination_highlighted", "medical_exam_id", $_REQUEST['medical_exam_id'])?>"


	console.log(highlightedFields);
		$(document).ready(function(){
		    $("#hiddenHighlighter").val(highlightedFields);
		    highlightedFields = highlightedFields.split(",")
		    console.log(highlightedFields);
		    // console.log("length"+highlighted_fieldslds.length);
		    for(var i = 1; i<highlightedFields.length; i++){
		    	ids = document.getElementById(highlightedFields[i]);
		    	ids.style.borderColor ="tomato";
		    	ids.style.color = "tomato";

		    }

		  });
	            
	             	
		$("input").dblclick(function() {
	  		dblClickcolorValidation(this);
	  		// alert("hello there!"+this.name);

    	});
    	 $("textarea").dblclick(function() {
    	  		dblClickcolorValidation(this);
    	  		// alert("hello there!"+this.name);
    
    	});
    	 $("select").dblclick(function() {
    	  		dblClickcolorValidation(this);
    	  		// alert("hello there!"+this.name);
    
    	});

	    	
	</script>