
<?php

//echo $_SERVER['DOCUMENT_ROOT'];


//eg CARER NAME 
//DANIE-SWEET-111822

//candidate
//a2u7T000000POWJQA4
//MTK-PA-SPRY-111822

//EJKA295846
//MHLG98427


//FROM Care_Provider__c
//MTJT143813 (care provider code)
//TEST, Mandy
//Dr Johnny Test
	
	
	
// lsm 1/13/25		
//name=				
?>


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	
	
	<meta name="viewport" content="width=device-width, initial-scale=.8, shrink-to-fit=no">
	
	<title>Medtack Document Upload</title>
	
	<link rel="icon" type="image/x-icon" href="favicon.png">
	
	
	<?php require_once("index_meta.php") ?>
	
	
	

	<!-- JQUERY -->
  	<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
  	
		

  	
    <!-- BOOTSTRAP -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
 
 
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
  
  
	<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>

 
 

		
	<!-- BOOTSTRAP DATEPICKER CSS / JS -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css"/>
	<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">

  	<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>


	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">

						
</head>
<body style="margin: 1em;">




<div style="padding: 20px; 20px; 20px; 20px; margin: 0 auto 0 auto; width:100%;  min-width:320px; max-width:900px;">


<div id="" class="" style="">
<a href="https://documents.medtack.net/upload.php"><img src ="medtack_logo_.png" style="width:100%; max-width:300px;margin: 20px 0 0 0"></a>
</div>

<!--
<div id="" class="" style="margin:20px 0 0 0;">
<span style="color:#ff0000;">Development link only :</span> <a href="/medical-records" class="link" target="_blank" >Medical Records / S3</a>
</div>
-->

      

        <div  class="text-left" style="margin:40px 0 0 0;">
		<h4 class="lsm-title">Medtack Document Upload</h4>
		</div>
		

      
      
      <div class="lsm-body" style="height:auto;">
		
		
				<div>	
				<!-- accept=".jpg,.jpeg,.png,.gif etc..." attribute of input tag -->	
				
				<!--  uses jQuery: $('.imageUploadForm').on('submit',(function(e) { -->
				
				
				<div id="" class="" style="margin: 10px 10px 10px 0px">
				
								

						
						<script>
						// lsm 1/13/25
						//added name
						function getApplicantIdFromCareProvider(code,name){
				
		
					
								var data = {
									getApplicantIdFromCareProvider : 'yes',
									code : code,
									name : name,	
								}


								 //jQuery('.ajaxLoader').css('visibility','visible');
								 jQuery.ajax({
									url: 'api_sf/api2.php',
									type: 'post',
									dataType: 'json',
									success: function (result) {
		
				
										
									   if(result["status"]=="no_match"){
										 	alert("No records returned");
											document.location.href="upload.php";
									   }else{
						   
						   

		
											var id_cp = result[0]["id_cp"] || "";
											var id_ap = result[0]["id_ap"] || "";
											var id_rc = result[0]["id_rc"] || "";
											var patient_code = result[0]["patient_code"] || "";									     
											var document_received = result[0]["document_received"] || "";
											
											
											
											
											// lsm 9/18/23
											if(patient_code==""){
												alert("No patient code returned");
												document.location.href="upload.php";
											}else{
											

												<?php if ( $_GET['code']!="" && $_GET['name']=="" ){ ?>	
													document.location.href="upload.php?code="+code+"&id_cp="+id_cp+"&id_ap="+id_ap+"&id_rc="+id_rc+"&patient_code="+patient_code;
												<?php }?>
												
												<?php if ( $_GET['code']=="" && $_GET['name']!="" ){ ?>	
													document.location.href="upload.php?name="+name+"&id_cp="+id_cp+"&id_ap="+id_ap+"&id_rc="+id_rc+"&patient_code="+patient_code;
												<?php }?>
												
												// lsm 2/26/26
												if(code!=""){
													document.location.href="upload.php?code="+code+"&id_cp="+id_cp+"&id_ap="+id_ap+"&id_rc="+id_rc+"&patient_code="+patient_code; 
												}
											
											}	 							   			
			
								
									   }
	

									},
									data: data
								}).always(function(){
								  //console.log("done");
								});



						}
				
				
					<?php if ( ($_GET['code']!="" && $_GET['patient_code']=="") && $_GET['name']==""){ ?>						
						// lsm 9/18/23
						getApplicantIdFromCareProvider("<?php echo $_GET['code']?>","");				
					<?php }?>
					
					
					<?php if ( ($_GET['code']=="" && $_GET['patient_code']=="") && $_GET['name']!=""){ ?>						
						// lsm 1/13/25
						getApplicantIdFromCareProvider("","<?php echo $_GET['name']?>");				
					<?php }?>
					
					
						
					<?php if ( $_GET['code']!="" && $_GET['name']!="" ){ ?>	
						document.location.href="upload.php";
					<?php }?>
			
					
					
						
						
						</script>
						
				
						
						
					<?php if ( $_GET['code']=="" && $_GET['name']=="" ){ ?>
					
						<p>Please enter your User code, for assistance please contact us by email: <a href="mailto:mrrc@medtack.net">mrrc@medtack.net</a></p>

				
						
						<input  id="code" maxlength=60 type="text" style="width:120px;" placeholder="Enter code" > <button onclick="submitCode();" class="imageBrowseUpload btn btn-primary btn-sm">Submit</button>
						
								
						<script>
						
			
						
			
				
				
						
						var code = document.getElementById("code");
						code.addEventListener("keydown", function (e) {
							 if (e.keyCode === 13) {
								submitCode();
							}
						});



						function submitCode(){
							var code = $("#code").val();
							//if (code.length != 6){
							if (code ==""){
								alert("Please enter a valid User code");
								return
							}
							
							// lsm 2/26/26
							//getApplicantIdFromCareProvider(code)
							getApplicantIdFromCareProvider(code,"");
							
							//document.location.href="upload.php?code="+code;
						}
						
						
						</script>
						
						
					
						<?php exit(); ?>
					
					<?php }else{?>
					
					<style>
					.link{
						text-decoration:underline;						
					}
					.link:hover{
						text-decoration:none;
					}
					</style>
					
					
					<div id="" class="" style="">
					
						<?php if ( $_GET['code']!="" && $_GET['name']=="" ){ ?>
							<b>User code: <span style="color:rgb(0, 123, 255);"><?php echo $_GET['code'];?></span></b> <!--<a class="link" href="upload.php">enter a different code.</a>-->
						<?php }?>
						
						<!--// lsm 1/13/25-->
						<?php if ( $_GET['code']=="" && $_GET['name']!="" ){ ?>
							<b><span style="color:rgb(0, 123, 255);"><?php echo $_GET['name'];?></span></b>
						<?php }?>
						
			
					</div>
						
						<!-- [ DEV ONLY:<?php echo $_GET['name__c']; ?> ]-->
						<!--<select class="imageBrowseUpload btn btn-primary btn-sm">-->
						<!--<option value="<?php echo $_GET['id']; ?>">Patient code: <?php echo $_GET['patient_code']; ?></option>-->
						<!--</select>-->
						
						 
						<div id="" class="" style="display:none;">id_cp: <?php echo $_GET['id_cp']; ?></div>
						<div id="" class="" style="display:none;">id_ap: <?php echo $_GET['id_ap']; ?></div>
						<div id="" class="" style="display:none;">id_rc: <?php echo $_GET['id_rc']; ?></div>
						
						
						<!--<div id="" class="" style="font-weight:bold;">Patient code: <span style="color:rgb(0, 123, 255);"><?php echo $_GET['patient_code']; ?></span></div>-->
						
						
						
						
						<!--<div id="" class="" style="font-weight:bold;">New Document(s) received: <span style="color:rgb(0, 123, 255);"><?php echo (($_GET['document_received']=="1")? 'yes':'No');?></span></div>-->
						
						
				
					<?php }?>
				
				</div>
						
			
				<div class='_progress' id="progress_div">
					<div class='_bar' id='bar'></div>
					<div class='_percent' id='percent'>0%</div>
				</div>
				<br>
				
				<form id="form_upload" action="" method="post" class="imageUploadForm" enctype="multipart/form-data">
				
				<!-- only images accept="image/*"      multiple="multiple" --> <!-- , .doc, .docx-->
				<input class="imageBrowse" id ="image_to_upload" type="file" name="file" accept=".pdf, image/png, image/gif, image/jpeg, */dicom,.dcm, image/dcm, */dcm, .dicom, video/mp4, video/webm, video/ogg" value="Browse" style="display:block;" />

				 
				<input style="margin: 20px 0 0 0; width:auto" type= "submit" class="imageBrowseUpload btn btn-primary btn-sm" value="Send document"  /> 
				
				<div id="" class="" style="margin: 20px 0 0 0;">
				
				<p>
				<b style="color:rgb(0, 123, 255);">Resubmit the form for multiple documents linked to the <br>same dedicated user ID above</b><br>
				<b>Accepted file formats:</b> pdf jpg png gif dcm dicom mp4<br>
				<b>Maximum file size:</b> 1GB
				</p>
	
				<p>
				
				This is a secure form; all data is encrypted during storage and transit.<br>
				Please remove any password protection from documents before uploading.<br><br>
				<strong>By clicking “Send document”, you confirm that you are authorized <br>
				to upload documents and agree to our <i>Terms of Use</i> accessed<br>
                 via the Legal link below</strong>
				</p>
				

				<p>
					
					<div id="" class="" style="">
					<a href="#" onclick='jQuery("#contact_panel").toggle();'><b>Support</b> +</a>
					</div>
					
					<div id="contact_panel" class="" style="display:none">
					Medical records team email: <a href="mailto:mrrc@medtack.net" target="_blank">mrrc@medtack.net</a>
					<br>
					Technical support email: <a href="mailto:support:mrrc@medtack.net" target="_blank">support@medtack.net</a>
					</div>
					
				</p>
				
				<p>
				
		
					<div id="" class="" style="">
					<a href="#" onclick='jQuery("#legal_panel").toggle();'><b>Legal</b> +</a>
		

					<div id="legal_panel" class="" style="display:none">
					<a href="#" data-bs-toggle="modal" data-bs-target="#staticBackdrop">Terms of Use</a>
					</div>
				
				</p>

</div>
		

		
				
				<style>
				._progress{
				  position:relative; 
				  width:100%; 
				  border: 1px solid #ddd; 
				  padding: 1px; 
				  border-radius: 3px; 
				}
					._bar{ 
					  background-color: #59c2f4; 
					  width:0%; 
					  height:20px; 
					  border-radius: 3px; 
					}
					._percent{ 
					  position:absolute; 
					  display:inline-block; 
					  top:0px; 
					  left:48%; 
					}
				</style>
				
				
				<br>
				<div id="preview_container">
				
				<img id="preview_img" style="display:block;" src=""  /> 
	
				
				</div>
				
				</form>
				
				</div>
				
				
						
	
				
		
				
				
	

      </div>
      
      

</div>



<style>

@media (min-width: 768px) {
  .modal-dialog {
    min-width: 1000px;
  }
  
  .modal-body {
    margin: 0px 20px 20px 20px;
    font-size:11.5px;
  }


}




</style>

<script>






//UPLOAD IMAGE
 $(function(){
 
    $('.imageUploadForm').on('submit',(function(e) {
    

    
    	e.preventDefault();
    	
    	
    	if($("#image_to_upload").val()==""){alert('Please select a document to upload');return false;}
    	

     	
        var patient_code = "<?php echo $_GET['patient_code']; ?>";
       
        
        var id_cp = "<?php echo $_GET['id_cp']; ?>";
        var id_ap = "<?php echo $_GET['id_ap']; ?>";
        var id_rc = "<?php echo $_GET['id_rc']; ?>";
        
        
        <?php if ($_GET['name']==""){ ?>
        
        // lsm 3/14/24
        if(patient_code==""){alert('Missing User code (patient_code)!');return false;}
        if(id_cp==""){alert('Missing id_cp!');return false;} 
        
        
        <?php }?>
        
        
          
        if(id_ap==""){alert('Missing id_ap!');return false;}
        

        
        
        
        var formData = new FormData(this); 
        
        formData.append("action", "upload_document");

        formData.append("patient_code", patient_code);
        
        formData.append("id_cp", id_cp);
        formData.append("id_ap", id_ap);
        formData.append("id_rc", id_rc);
        

        $.ajax({
			xhr: function() {
				var xhr = new window.XMLHttpRequest();
				xhr.upload.addEventListener("progress", function(evt) {
					if (evt.lengthComputable) {
						var percentComplete = (evt.loaded / evt.total) * 100;
						// Place upload progress bar visibility code here
						//console.log("percentComplete "+percentComplete);
						$('._percent').html(parseInt(percentComplete)+"%");
						$('._bar').css('width',percentComplete+"%");
					}
				}, false);
				return xhr;
			},
            type:'POST',
            url: "upload_api.php",
            data:formData,
            cache:false,
            contentType: false,
            processData: false,
            success:function(data){
                //console.log("upload success");
                //console.log(data);
                
                $('._percent').html("0%");
				$('._bar').css('width',"0%");
	        	$("#preview_img").attr("src","");           
                $(".imageBrowse").val("");
                
                 alert("File(s) uploaded");
                

                
            },
            error: function(data){
                console.log("error");
                console.log(data);
            }
        });
        
    }));
  
    
 }); 





////////////////////
	jQuery(function(){
	
	
		var target2 = "";
		var oversize = false;
		function readURL(input) {
	
		
		  // check file size of FILE upload		
		  if (input.files && input.files[0]) {
					
					var size = input.files[0].size;		
					
					//var maxSize = 20 000000; //20mb
					var maxSize = 1000000000;
				
					//console.log(size+"::"+maxSize);
					
					//alert(input.files[0].type);
					 
					if(size > maxSize){
							alert("Please upload files less that 1 GB");
							oversize = true;
							return false;
				   }else{
						oversize = false;
				   }
 
	  
			var reader = new FileReader();

			target2 = input;
		
			reader.onload = function(e) {	   
				//alert('ok');
				//$(target2).parent().find(".preview").css(...
				
				
				
				if(input.files[0].type.includes("image")){
					$("#preview_img").css({'display':'block','width':'200px','margin':'10px 10px 10px 0px'});				
					$("#preview_img").attr("src", e.target.result); 
				}else{
					$("#preview_img").attr("src", "");
				}
				
				
		
				
				//jQuery('#delete_icon').css('display', 'block');

			}

			reader.readAsDataURL(input.files[0]);
		  } 
		}

		jQuery("input[type=file]").change(function() { 
			readURL(this); 
		});
	
	
	});
	////////////////////
	
	
</script>






<div class="modal fade" id="staticBackdrop"  data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
     	<button type="button" class="btn-close btn-sm" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      
      <div class="modal-body">
       <?php require_once("index_terms_of_use_upload.php"); ?>
      </div>
      
      
    </div>
  </div>
</div>




</body>
</html>


