<?php
class classVisits
{
	  	private $visitID=NULL;
		private $locationID=NULL;
		private $organizationID=NULL;
		private $visitDate=NULL;
		private $tokenNumber=NULL;
		private $ipdBedAllotmentID=NULL;
		private $doctorID=NULL;
		private $shiftID=NULL;
		private $patientID=NULL;
		private $transactionID=NULL;
		
		private $temp=NULL;
		private $bp=NULL;
		private $bsr=NULL;
		private $weight=NULL;
		private $complaint=NULL;
		private $diagnosis=NULL;
		private $notes=NULL;
		
		private $dosageID=NULL;
		private $dosage=NULL;
		private $quantity=NULL;
		private $duration=NULL;
		private $medicineID=NULL;
		private $labTestID=NULL;
		private $procedureID=NULL;
		private $medicineName=NULL;
		private $medicineType=NULL;
		private $labTestName=NULL;
		private $procedureName=NULL;
		
		private $fee=NULL;
		private $discount=NULL;
		private $amountPayable=NULL;
		private $payment=NULL;
		private $balance=NULL;
		private $zakat=NULL;
		private $khairat=NULL;
		private $paymentStatus=NULL;
		
		private $medicalIssueID=NULL;
		private $medicalIssueName=NULL;
		
		private $dressingID=NULL;
		private $dressing=NULL;
		
		########################################## set functions ##############################
		
	    function setVisitID($visitID)
		{
			if($visitID!="")
			{
				if(classFilter::validateInteger($visitID))
				{
					$this->visitID = classFilter::addMySlashes($visitID);
				}
				else
				{
					throw new MyException(113100);
				}
			}
			else
			{
				throw new MyException(113101);
			}
		}
		function setOrganizationID($organizationID)
		{
			if($organizationID!="")
			{
				$this->organizationID = $organizationID;
			}
			
		}
		function setLocationID($locationID)
		{
			if($locationID!="")
			{
				$this->locationID = $locationID;
			}
			
		}
		function setVisitDate($visitDate) 
		{
			if($visitDate!="")
			{
				$this->visitDate = $visitDate;
			}
			else
			{
				throw new MyException(113102);
			}
		}
		function setTokenNumber($tokenNumber) 
		{
			if($tokenNumber!="")
			{
				$this->tokenNumber = $tokenNumber;
			}
			else
			{
				throw new MyException(113103);
			}
		}
		
		function setIpdBedAllotmentID($ipdBedAllotmentID)
		{
			if($ipdBedAllotmentID!="")
			{
				$this->ipdBedAllotmentID = $ipdBedAllotmentID;
			}
		}
	  	
	  	function setDoctorID($doctorID)
		{
			if($doctorID!="")
			{
				if(classFilter::validateInteger($doctorID))
				{
					$this->doctorID = classFilter::addMySlashes($doctorID);
				}
				else
				{
					throw new MyException(113104);
				}
			}
			else
			{
				throw new MyException(113105);
			}
		}
		function setShiftID($shiftID) 
		{
			if($shiftID!="")
			{
				if(classFilter::validateInteger($shiftID))
				{
					$this->shiftID = classFilter::addMySlashes($shiftID);
				}
				else
				{
					throw new MyException(113106);
				}
			}
			else
			{
				throw new MyException(113107);
			}
		}
		function setPatientID($patientID)
		{
			if($patientID!="")
			{
				if(classFilter::validateInteger($patientID))
				{
					$this->patientID = classFilter::addMySlashes($patientID);
				}
				else
				{
					throw new MyException(113108);
				}
			}
			else
			{
				throw new MyException(113109);
			}
		}
		function setTransactionID($transactionID) 
		{
			if($transactionID!="")
			{
				if(classFilter::validateInteger($transactionID))
				{
					$this->transactionID = classFilter::addMySlashes($transactionID);
				}
				else
				{
					throw new MyException(113110);
				}
			}
			else
			{
				throw new MyException(113111);
			}
		}
		
		function setTemp($temp) 
		{
			if($temp!="")
			{
				$this->temp = $temp;
			}
		}
		function setBp($bp) 
		{
			if($bp!="")
			{
				$this->bp = $bp;
			}
		}
		function setBsr($bsr) 
		{
			if($bsr!="")
			{
				$this->bsr = $bsr;
			}
		}
		function setWeight($weight) 
		{
			if($weight!="")
			{
				$this->weight = $weight;
			}
		}
		function setComplaint($complaint) 
		{
			if($complaint!="")
			{
				$this->complaint = $complaint;
			}
		}
		function setDiagnosis($diagnosis) 
		{
			if($diagnosis!="")
			{
				$this->diagnosis = $diagnosis;
			}
		}
		function setNotes($notes) 
		{
			if($notes!="")
			{
				$this->notes = $notes;
			}
		}
		
		function setFee($fee)
		{
			if($fee!='')
			{
				$this->fee = $fee;
			}
			else
			{
				throw new MyException(113126);
			}
		}
		
		function setDiscount($discount)
		{
			if($discount!='')
			{
				$this->discount = $discount;
			}
			else
			{
				//throw new MyException(113112);
			}
		}
		function setAmountPayable($amountPayable)
		{
			if($amountPayable!='')
			{
				$this->amountPayable = $amountPayable;
			}
			else
			{
				throw new MyException(113113);
			}
		}
		function setPayment($payment)
		{
			if($payment!='')
			{
				if(is_numeric($payment))
				{
					$this->payment = $payment;
				}
				else
				{
					throw new MyException(113114);
				}
			}
			else
			{
				throw new MyException(113115);
			}
		}
		function setBalance($balance)
		{
			if($balance!='')
			{
				$this->balance = $balance;
			}
		}
		function setZakat($zakat)
		{
			if($zakat!='')
			{
				$this->zakat = $zakat;
			}
		}
		function setKhairat($khairat)
		{
			if($khairat!='')
			{
				$this->khairat = $khairat;
			}
		}
		function setPaymentStatus($paymentStatus)
		{
			if($paymentStatus!='')
			{
				$this->paymentStatus = $paymentStatus;
			}
		}
		
		function setPrescriptionItemID($prescriptionItemID) 
		{
			if($prescriptionItemID!="")
			{
				$this->prescriptionItemID = $prescriptionItemID;
			}
			else
			{
				throw new MyException(113129);
			}
		}
		
		function setDosageID($dosageID) 
		{
			if($dosageID!="")
			{
				$this->dosageID = $dosageID;
			}
		}
		function setDosage($dosage) 
		{
			if($dosage!="")
			{
				$this->dosage = $dosage;
			}
		}
		function setQuantity($quantity) 
		{
			if($quantity!="")
			{
				$this->quantity = $quantity;
			}
		}
		function setDuration($duration) 
		{
			if($duration!="")
			{
				$this->duration = $duration;
			}
		}
		
		function setMedicineID($medicineID) 
		{
			if($medicineID!="")
			{
				$this->medicineID = $medicineID;
			}
			else
			{
				throw new MyException(113131);
			}
		}
		function setLabTestID($labTestID) 
		{
			if($labTestID!="")
			{
				$this->labTestID = $labTestID;
			}
			else
			{
				throw new MyException(113132);
			}
		}
		function setProcedureID($procedureID) 
		{
			if($procedureID!="")
			{
				$this->procedureID = $procedureID;
			}
			else
			{
				throw new MyException(113133);
			}
		}
		function setMedicineName($medicineName) 
		{
			if($medicineName!="")
			{
				$this->medicineName = $medicineName;
			}
			else
			{
				throw new MyException(113134);
			}
		}
		
		function setMedicineType($medicineType) 
		{
			if($medicineType!="")
			{
				$this->medicineType = $medicineType;
			}
		}
		
		function setLabTestName($labTestName) 
		{
			if($labTestName!="")
			{
				$this->labTestName = $labTestName;
			}
			else
			{
				throw new MyException(113135);
			}
		}
		function setProcedureName($procedureName) 
		{
			if($procedureName!="")
			{
				$this->procedureName = $procedureName;
			}
			else
			{
				throw new MyException(113136);
			}
		}
	
		function setMedicalIssueID($medicalIssueID) 
		{
			if($medicalIssueID!="")
			{
				$this->medicalIssueID = $medicalIssueID;
			}
			else
			{
				throw new MyException(113143);
			}
		}
		function setMedicalIssueName($medicalIssueName) 
		{
			if($medicalIssueName!="")
			{
				$this->medicalIssueName = $medicalIssueName;
			}
			else
			{
				throw new MyException(113144);
			}
		}
		
		function setDressingID($dressingID) 
		{
			if($dressingID!="")
			{
				$this->dressingID = $dressingID;
			}
		}
		function setDressing($dressing) 
		{
			if($dressing!="")
			{
				$this->dressing = $dressing;
			}
		}
	
		
		
		##################################################################### GET FUNCTIONS  ########################

		function getVisitID()
		{
			if($this->visitID!="")
			{
				return $this->visitID;
			}
			else
			{
				throw new MyException(113116);
			}
		}
		function getLocationID()
		{
			if($this->locationID!="")
			{
				return $this->locationID;
			}
			
		}
		function getOrganizationID()
		{
			if($this->organizationID!="")
			{
				return $this->organizationID;
			}
			
		}
		function getVisitDate() 
		{
			if($this->visitDate!="")
			{
				return $this->visitDate;
			}
			else
			{
				throw new MyException(113116);
			}
		}
		function getTokenNumber() 
		{
			if($this->tokenNumber!="")
			{
				return $this->tokenNumber;
			}
			else
			{
				throw new MyException(113117);
			}
		}
		
		function getIpdBedAllotmentID()
		{
			if($this->ipdBedAllotmentID!="")
			{
				return $this->ipdBedAllotmentID;
			}
		}
	  	
	  	function getDoctorID()
		{
			if($this->doctorID!="")
			{
				return $this->doctorID;
			}
			else
			{
				throw new MyException(113118);
			}
		}
		function getShiftID() 
		{
			if($this->shiftID!="")
			{
				return $this->shiftID;
			}
			else
			{
				throw new MyException(113119);
			}
		}
		function getPatientID()
		{
			if($this->patientID!="")
			{
				return $this->patientID;
			
			}
			else
			{
				throw new MyException(113120);
			}
		}
		function getTransactionID() 
		{
			if($this->transactionID!="")
			{
				return $this->transactionID;
			}
			else
			{
				throw new MyException(113121);
			}
		}
		
		function getTemp() 
		{
			if($this->temp!="")
			{
				return $this->temp;
			}
		}
		function getBp() 
		{
			if($this->bp!="")
			{
				return $this->bp;
			}
		}
		function getBsr() 
		{
			if($this->bsr!="")
			{
				return $this->bsr;
			}
		}
		function getWeight() 
		{
			if($this->weight!="")
			{
				return $this->weight;
			}
		}
		function getComplaint() 
		{
			if($this->complaint!="")
			{
				return $this->complaint;
			}
		}
		function getDiagnosis() 
		{
			if($this->diagnosis!="")
			{
				return $this->diagnosis;
			}
		}
		function getNotes() 
		{
			if($this->notes!="")
			{
				return $this->notes;
			}
		}
		
		function getFee()
		{
			if($this->fee!='')
			{
				return $this->fee;
			}
			else
			{
				throw new MyException(113127);
			}
		}
		
		function getDiscount()
		{
			if($this->discount!='')
			{
				return $this->discount;
			}
			else
			{
				//throw new MyException(113122);
			}
		}
		function getAmountPayable()
		{
			if($this->amountPayable!='')
			{
				return $this->amountPayable;
			}
			else
			{
				throw new MyException(113123);
			}
		}
		function getPayment()
		{
			if($this->payment!='')
			{
				return $this->payment;
			}
			else
			{
				throw new MyException(113124);
			}
		}
		function getBalance()
		{
			if($this->balance!='')
			{
				return $this->balance;
			}
		}
		function getZakat()
		{
			if($this->zakat!='')
			{
				return $this->zakat;
			}
		}
		function getKhairat()
		{
			if($this->khairat!='')
			{
				return $this->khairat;
			}
		}
		function getPaymentStatus()
		{
			if($this->paymentStatus!='')
			{
				return $this->paymentStatus;
			}
		}
		
		function getPrescriptionItemID() 
		{
			if($this->prescriptionItemID!="")
			{
				return $this->prescriptionItemID ;
			}
			else
			{
				throw new MyException(113130);
			}
		}
		
		function getDosageID() 
		{
			if($this->dosageID!="")
			{
				return $this->dosageID;
			}
		}
		function getDosage() 
		{
			if($this->dosage!="")
			{
				return $this->dosage;
			}
		}
		
		function getQuantity() 
		{
			if($this->quantity!="")
			{
				return $this->quantity;
			}
		}
		function getDuration() 
		{
			if($this->duration!="")
			{
				return $this->duration;
			}
		}
		function getMedicineID() 
		{
			if($this->medicineID!="")
			{
				return $this->medicineID;
			}
			else
			{
				throw new MyException(113137);
			}
		}
		function getLabTestID() 
		{
			if($this->labTestID!="")
			{
				return $this->labTestID;
			}
			else
			{
				throw new MyException(113138);
			}
		}
		function getProcedureID() 
		{
			if($this->procedureID!="")
			{
				return $this->procedureID;
			}
			else
			{
				throw new MyException(113139);
			}
		}
		function getMedicineName() 
		{
			if($this->medicineName!="")
			{
				return $this->medicineName;
			}
			else
			{
				throw new MyException(113140);
			}
		}
		
		function getMedicineType() 
		{
			if($this->medicineType!="")
			{
				return $this->medicineType;
			}
		}
		
		function getLabTestName() 
		{
			if($this->labTestName!="")
			{
				return $this->labTestName;
			}
			else
			{
				throw new MyException(113141);
			}
		}
		function getProcedureName() 
		{
			if($this->procedureName!="")
			{
				return $this->procedureName;
			}
			else
			{
				throw new MyException(113142);
			}
		}
		
		function getMedicalIssueID() 
		{
			if($this->medicalIssueID!="")
			{
				return $this->medicalIssueID;
			}
			else
			{
				throw new MyException(113145);
			}
		}
		function getMedicalIssueName() 
		{
			if($this->medicalIssueName!="")
			{
				return $this->medicalIssueName;
			}
			else
			{
				throw new MyException(113146);
			}
		}
		
		function getDressingID() 
		{
			if($this->dressingID!="")
			{
				return $this->dressingID;
			}
		}
		function getDressing() 
		{
			if($this->dressing!="")
			{
				return $this->dressing;
			}
		}
	
		##################################################################### Check FUNCTIONS  #####################
	  
		function checkPatientAlreadyInShift($patient_id,$shift_id) 
		{
			$query = "SELECT visit_id FROM visits WHERE patient_id = '$patient_id' AND shift_id = '$shift_id'";
			$queryOb = new classQueryGlobal;
			$array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($array[0]['visit_id'])&&$array[0]['visit_id']!= "")
			{
				return 0;
			}
			else
			{
				return 1;
			}
			
			
		}
		
		function checkMedicineLabTestProcedureAlreadyInPrescription($visit_id,$type,$id) 
		{
			if($type=='medicine')
			{
				$column_name = 'product_id';
			}
			if($type=='labtest')
			{
				$column_name = 'labtest_id';
			}
			if($type=='procedure')
			{
				$column_name = 'procedure_id';
			}
			if($type=='dressing')
			{
				$column_name = 'dressing_id';
			}
			
			$query = "SELECT presc_item_id FROM presc_items WHERE visit_id = '$visit_id' AND $column_name = '$id'";
			$queryOb = new classQueryGlobal;
			$array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($array[0]['presc_item_id'])&&$array[0]['presc_item_id']!= "")
			{
				return 0;
			}
			else
			{
				return 1;
			}
			
			
		}
		
		function checkMedicineLabTestProcedureAlreadyInIPDPrescription($ipd_bed_allotment_id,$type,$id) 
		{
			if($type=='medicine')
			{
				$column_name = 'product_id';
			}
			if($type=='labtest')
			{
				$column_name = 'labtest_id';
			}
			if($type=='procedure')
			{
				$column_name = 'procedure_id';
			}
			if($type=='dressing')
			{
				$column_name = 'dressing_id';
			}
			
			$query = "SELECT presc_item_id FROM presc_items WHERE ipd_bed_allotment_id = '$ipd_bed_allotment_id' AND $column_name = '$id'";
			$queryOb = new classQueryGlobal;
			$array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($array[0]['presc_item_id'])&&$array[0]['presc_item_id']!= "")
			{
				return 0;
			}
			else
			{
				return 1;
			}
			
			
		}
		
		function checkMedicineLabTestProcedureInPrescription($visit_id,$type) 
		{
			if($type=='medicine')
			{
				$column_name = 'product_id';
			}
			if($type=='labtest')
			{
				$column_name = 'labtest_id';
			}
			if($type=='procedure')
			{
				$column_name = 'procedure_id';
			}
			if($type=='dosage')
			{
				$column_name = 'dosage_id';
			}
			if($type=='dressing')
			{
				$column_name = 'dressing_id';
			}
			
			$query = "SELECT presc_item_id FROM presc_items WHERE visit_id = '$visit_id' AND $column_name != 0";
			$queryOb = new classQueryGlobal;
			$array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($array[0]['presc_item_id'])&&$array[0]['presc_item_id']!= "")
			{
				return 1;
			}
			else
			{
				return 0;
			}
			
			
		}
		
		function checkMedicineLabTestProcedureInAllPrescription($type,$id) 
		{
			if($type=='medicine')
			{
				$column_name = 'product_id';
			}
			if($type=='labtest')
			{
				$column_name = 'labtest_id';
			}
			if($type=='procedure')
			{
				$column_name = 'procedure_id';
			}
			if($type=='dosage')
			{
				$column_name = 'dosage_id';
			}
			if($type=='dressing')
			{
				$column_name = 'dressing_id';
			}
			
			$query = "SELECT presc_item_id FROM presc_items WHERE $column_name ='$id'";
			$queryOb = new classQueryGlobal;
			$array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($array[0]['presc_item_id'])&&$array[0]['presc_item_id']!= "")
			{
				return 1;
			}
			else
			{
				return 0;
			}
			
			
		}
		
		function checkMedicalIssueAlreadyInExist($medical_issue,$org_id) 
		{
			$medical_issue = strtolower($medical_issue);
			
			$query = "SELECT med_issue_id FROM medical_issues WHERE org_id = '$org_id' AND medical_issue = '$medical_issue'";
			$queryOb = new classQueryGlobal;
			$array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($array[0]['med_issue_id'])&&$array[0]['med_issue_id']!= "")
			{
				return 0;
			}
			else
			{
				return 1;
			}
			
			
		}
		
		##################################################################### Main INSERT FUNCTIONS  ###################
		
		function execute() 
		{
			if($this->checkPatientAlreadyInShift($this->getPatientID(),$this->getShiftID()))
			{
				$doctor_id = $this->getDoctorID();
				$shift_id = $this->getShiftID();
				$patient_id = $this->getPatientID();
				$location_id = $this->getLocationID();
				
				$patientOb = new classPatient;
				$session_fee = $patientOb->retrievePatientSessionFeeByPatientID($patient_id);
				if($session_fee!='')
				{
					
					$fee = $session_fee;
				}
				else
				{
					$doctorOb = new classDoctor;
					$doctorOb->setDoctorID($doctor_id);
					$doctor_detail = $doctorOb->retrieveDoctorByDoctorID();
					$fee = $doctor_detail[0]['consultancy_fee'];
				}
				
				
				
				$payable = $fee;
				$balance = $payable;
				
				$visit_date=time();
				$token_no = $this->retrieveTokenNumber($shift_id);
				
				$shiftOb = new classShift;
				$shift_date = $shiftOb->retrieveShiftDateByShiftID($shift_id);
				
				$query="INSERT INTO visits 
				(
					
					visit_date,
					shift_date,
					location_id,
					token_no,
					doctor_id,
					shift_id,
					patient_id,
					fee,
					payable,
					balance
				) 
				VALUES
				(
					'$visit_date',
					'$shift_date',
					'$location_id',
					'$token_no',
					'$doctor_id',
					'$shift_id',
					'$patient_id',
					'$fee',
					'$payable',
					'$balance'
				)";
				$queryOb = new classQueryGlobal;
				$this->visitID = $queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
			}
			else
			{
				throw new MyException(113125);
			}
		}
		
		function insertPrescriptionItems($visit_id,$type,$ids)
		{
			if($type=='medicine')
			{
				$column_name = 'product_id';
			}
			if($type=='labtest')
			{
				$column_name = 'labtest_id';
			}
			if($type=='procedure')
			{
				$column_name = 'procedure_id';
			}
			if($type=='dressing')
			{
				$column_name = 'dressing_id';
			}
			
			for($p=0;$p<count($ids);$p++)
			{	
				$id = $ids[$p];
				if($this->checkMedicineLabTestProcedureAlreadyInPrescription($visit_id,$type,$id))
				{
					$query = "INSERT INTO presc_items (visit_id,$column_name) VALUES ('$visit_id','$id')";
					$queryOb = new classQueryGlobal;
					$queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
				}
				else
				{
					//$token = array('var1'=>ucwords($type));
					//throw new MyException(113128,$token);
				}
			}
		}
		
		function insertPrescriptionItemsForIPD($ipd_bed_allotment_id,$type,$ids,$requested_by)
		{
			if($type=='medicine')
			{
				$column_name = 'product_id';
			}
			if($type=='labtest')
			{
				$column_name = 'labtest_id';
			}
			if($type=='procedure')
			{
				$column_name = 'procedure_id';
			}
			if($type=='dressing')
			{
				$column_name = 'dressing_id';
			}
			$requested_time = time();
			for($p=0;$p<count($ids);$p++)
			{	
				$id = $ids[$p];
				if($this->checkMedicineLabTestProcedureAlreadyInIPDPrescription($ipd_bed_allotment_id,$type,$id))
				{
					$query = "INSERT INTO presc_items (ipd_bed_allotment_id,$column_name,presc_type,requested_by,requested_time) VALUES ('$ipd_bed_allotment_id','$id','ipd','$requested_by','$requested_time')";
					$queryOb = new classQueryGlobal;
					$queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
				}
				else
				{
					//$token = array('var1'=>ucwords($type));
					//throw new MyException(113128,$token);
				}
			}
		}
		
		function insertMedicine()
		{
			$product_name = $this->getMedicineName();
			$medicine_type = $this->getMedicineType();
			$org_id = $this->getOrganizationID();
			$query = "INSERT INTO products (product_name,category,medicine_type,org_id,active) VALUES ('$product_name','medicine','$medicine_type','$org_id',1)";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
		}
		function insertLabTest()
		{
			$labtest_name = $this->getLabTestName();
			$org_id = $this->getOrganizationID();
			$query = "INSERT INTO labtests (labtest_name,org_id) VALUES ('$labtest_name','$org_id')";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
		}
		function insertProcedure()
		{
			$procedure_name = $this->getProcedureName();
			$org_id = $this->getOrganizationID();
			$query = "INSERT INTO procedures (procedure_name,org_id) VALUES ('$procedure_name','$org_id')";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
		}
		
		function insertMedicalIssues()
		{
			$med_issue = strtolower($this->getMedicalIssueName());
			$org_id = $this->getOrganizationID();
			$active = 1;
			
			if($this->checkMedicalIssueAlreadyInExist($med_issue,$org_id))
			{
				$query = "INSERT INTO medical_issues (med_issue,org_id,active) VALUES ('$med_issue','$org_id','$active')";
				$queryOb = new classQueryGlobal;
				$this->medicalIssueID = $queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
			}
			else
			{
				throw new MyException(113147);
			}
		}
		
		function insertDosage()
		{
			$dosage = $this->getDosage();
			$org_id = $this->getOrganizationID();
			$query = "INSERT INTO dosage (dosage,org_id) VALUES ('$dosage','$org_id')";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
		}
		
		function insertDressing()
		{
			$dressing = $this->getDressing();
			$org_id = $this->getOrganizationID();
			$query = "INSERT INTO dressing (dressing,org_id) VALUES ('$dressing','$org_id')";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
		}
		
		##################################################################### Main UPDATE FUNCTIONS  ###################
	  
	  	function updatePayment()
		{
			$visit_id = $this->getVisitID();
			$pay_status = $this->getPaymentStatus();
			$payable = $this->getAmountPayable();
			$payment = $this->getPayment();
			$balance = $this->getBalance();
			
			
			$query = "UPDATE visits SET 
			pay_status = '$pay_status' ,
			fee = '$payable' ,
			payable = '$payable' ,
			payment = '$payment' ,
			balance = '$balance' 
			WHERE visit_id = '$visit_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
			
			
		}
		
		function updatePaymentAfterBalanceTransaction()
		{
			$visit_id = $this->getVisitID();
			$payment_status = $this->getPaymentStatus();
			$payment = $this->getPayment();
			$balance = $this->getBalance();
			
			
			$query = "UPDATE visits SET 
			 pay_status='$payment_status',
			 payment = payment+'$payment',
			 balance = '$balance'
			 where visit_id = '$visit_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		}
		
		function updatePrescription()
		{
			$visit_id = $this->getVisitID();
			$temp=$this->getTemp();
			$bp=$this->getBp();
			$bsr=$this->getBsr();
			$weight=$this->getWeight();
			$complaint=$this->getComplaint();
			$diagnosis=$this->getDiagnosis();
			$notes=$this->getNotes();
			
			$fee=$this->getFee();
			$payment = $this->getPayment();
			$zakat = $this->getZakat();
			$khairat = $this->getKhairat();
			$discount = $this->getDiscount();
			
			$minus_value = $zakat+$khairat+$discount;
			
			if($minus_value>$fee||$minus_value<0)
			{
				throw new MyException(113148);
			}
			
			$payable = $fee-$minus_value;
			$balance = $payable-$payment;
			
			
			$query = "UPDATE visits SET temp='$temp', bp='$bp', bsr='$bsr', weight='$weight', complaint='$complaint', diagnosis='$diagnosis', notes='$notes', fee='$fee', payable='$payable', balance='$balance', zakat='$zakat', khairat='$khairat', discount='$discount' WHERE visit_id = '$visit_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
			
			
		}
		
		function updateDosage()
		{
			$visit_id = $this->getVisitID();
			$dosage = $this->getDosage();
			
			foreach($dosage as $key => $value)
			{
				if($value!='')
				{
					$val = $value;
				}
				else
				{
					$val = '';
				}
				$product_id = $key;
				$dosage = $val;
				
				$query = "UPDATE presc_items SET dosage_id = '$dosage' WHERE visit_id='$visit_id' AND product_id='$product_id'";
				$queryOb = new classQueryGlobal;
				$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
				
			}
		}
		function updateDosageQuantity()
		{
			$visit_id = $this->getVisitID();
			$quantity = $this->getQuantity();
			
			foreach($quantity as $key => $value)
			{
				if($value!='')
				{
					$val = $value;
				}
				else
				{
					$val = '';
				}
				$product_id = $key;
				$quantity = $val;
				
				$query = "UPDATE presc_items SET quantity = '$quantity' WHERE visit_id='$visit_id' AND product_id='$product_id'";
				$queryOb = new classQueryGlobal;
				$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
				
			}
		}
		function updateDosageDuration()
		{
			$visit_id = $this->getVisitID();
			$duration = $this->getDuration();
			
			foreach($duration as $key => $value)
			{
				if($value!='')
				{
					$val = $value;
				}
				else
				{
					$val = '';
				}
				$product_id = $key;
				$duration = $val;
				
				$query = "UPDATE presc_items SET duration = '$duration' WHERE visit_id='$visit_id' AND product_id='$product_id'";
				$queryOb = new classQueryGlobal;
				$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
				
			}
		}
		function updateDressingDuration()
		{
			$visit_id = $this->getVisitID();
			$duration = $this->getDuration();
			
			foreach($duration as $key => $value)
			{
				if($value!='')
				{
					$val = $value;
				}
				else
				{
					$val = '';
				}
				$dressing_id = $key;
				$duration = $val;
				
				$query = "UPDATE presc_items SET duration = '$duration' WHERE visit_id='$visit_id' AND dressing_id='$dressing_id'";
				$queryOb = new classQueryGlobal;
				$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
				
			}
		}
		
		function updateMedicalIssues()
		{
			$med_issue = $this->getMedicalIssueName();
			$med_issue_id = $this->getMedicalIssueID();
			
			$query = "UPDATE medical_issues SET  med_issue = '$med_issue' WHERE med_issue_id = '$med_issue_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		}
		
		function updateMedicalIssueInVisit()
		{
			$visit_id = $this->getVisitID();
			$med_issue_id = $this->getMedicalIssueID();
			
			$query = "UPDATE visits SET med_issue_id = '$med_issue_id' WHERE visit_id = '$visit_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
			
			
		}
		
		function updateMedicine()
		{
			$product_name = $this->getMedicineName();
			$product_id = $this->getMedicineID();
			$medicine_type = $this->getMedicineType();
			
			$query = "UPDATE products SET product_name = '$product_name' , medicine_type = '$medicine_type' WHERE product_id = '$product_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		}
		
		function updateLabTest()
		{
			$labtest_name = $this->getLabTestName();
			$labtest_id = $this->getLabTestID();
			
			$query = "UPDATE labtests SET labtest_name = '$labtest_name' WHERE labtest_id = '$labtest_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		}
		
		function updateProcedure()
		{
			$procedure_name = $this->getProcedureName();
			$procedure_id = $this->getProcedureID();
			
			$query = "UPDATE procedures SET procedure_name = '$procedure_name' WHERE procedure_id = '$procedure_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		}
		
		function updateDosageName()
		{
			$dosage = $this->getDosage();
			$dosage_id = $this->getDosageID();
			$query = "UPDATE dosage SET dosage = '$dosage' WHERE dosage_id = '$dosage_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		}
		
		function updateDressingName()
		{
			$dressing = $this->getDressing();
			$dressing_id = $this->getDressingID();
			$query = "UPDATE dressing SET dressing = '$dressing' WHERE dressing_id = '$dressing_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		}
		
		##################################################################### Main DELETE  FUNCTIONS  ###################
		
		function deleteVisit()
		{
			$visit_id = $this->getVisitID();
			
			$query = "DELETE FROM visits WHERE visit_id = '$visit_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'delete',$server="",$debug_mode="off");
			
			
		}
		
		function deletePrescription()
		{
			$presc_item_id = $this->getPrescriptionItemID();
			
			$query = "DELETE FROM presc_items WHERE  presc_item_id = '$presc_item_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'delete',$server="",$debug_mode="off");
			
			
		}
		
		function deleteMedicalIssues()
		{
			
			$med_issue_id = $this->getMedicalIssueID();
			
			$query = "UPDATE medical_issues SET active = 0 WHERE med_issue_id = '$med_issue_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'delete',$server="",$debug_mode="off");
		}
		
		function deleteMedicines()
		{
			$product_id = $this->getMedicineID();
			
			$query = "DELETE FROM products WHERE product_id = '$product_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'delete',$server="",$debug_mode="off");
		}
		
		function deleteLabTests()
		{
			$labtest_id = $this->getLabTestID();
			
			$query = "DELETE FROM labtests WHERE labtest_id = '$labtest_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'delete',$server="",$debug_mode="off");
		}
		
		function deleteProcedures()
		{
			$procedure_id = $this->getProcedureID();
			
			$query = "DELETE FROM procedures WHERE procedure_id = '$procedure_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'delete',$server="",$debug_mode="off");
		}
		
		function deleteDosage()
		{
			$dosage_id = $this->getDosageID();
			
			$query = "DELETE FROM dosage WHERE dosage_id = '$dosage_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'delete',$server="",$debug_mode="off");
		}
		
		function deleteDressing()
		{
			$dressing_id = $this->getDressingID();
			
			$query = "DELETE FROM dressing WHERE dressing_id = '$dressing_id'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'delete',$server="",$debug_mode="off");
		}
		
		##################################################################### Main RETRIEVE FUNCTIONS  ##########
		
		function retrieveTokenNumber($shift_id)
		{
			$query = " SELECT MAX(token_no) AS token FROM visits WHERE shift_id = '$shift_id' ";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]['token'])&&$visits_array[0]['token']!='')
			{
				$token_no = $visits_array[0]['token']+1;
				
				return $token_no;
			}
			else
			{
				return 1;
			}
		}
		
		function retrieveVisits()
		{
			$doctor_id = $this->getDoctorID();
			$shift_id = $this->getShiftID();
			
			$query = "SELECT * FROM visits WHERE doctor_id = '$doctor_id' AND shift_id = '$shift_id' order by token_no asc";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		
		function retrieveLaserVisits()
		{
			$doctor_id = $this->getDoctorID();
			$shift_id = $this->getShiftID();
			
			$query = "SELECT * FROM visits JOIN medical_issues ON visits.med_issue_id = medical_issues.med_issue_id WHERE visits.doctor_id = '$doctor_id' AND visits.shift_id = '$shift_id' AND medical_issues.med_issue LIKE '%laser%' order by visits.token_no asc";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		
		function retrieveMedIssueVisits($from,$to,$doctor_id,$shift_id,$med_issue_id)
		{
			$query = "SELECT * FROM visits  WHERE doctor_id = '$doctor_id' AND shift_id = '$shift_id' AND med_issue_id = '$med_issue_id'";
			
			$startDateArray = explode('-',$from);
			$startTime = mktime(0,0,0,$startDateArray[1],$startDateArray[2],$startDateArray[0]);
			
			$endDateArray = explode('-',$to);
			$endTime = mktime(23,59,59,$endDateArray[1],$endDateArray[2],$endDateArray[0]);
			
			if($startTime!="")
			{
				if(($endTime!="" && $endTime > $startTime) || $endTime="")
				{
					$query .= " AND visit_date  > $startTime";
				}
			}
			
			if($endTime!="")
			{
				if(($startTime!="" && $startTime < $endTime) || $startTime="")
				{
					$query .= " AND visit_date  <= $endTime";
				}
			}
			$query .= " order by visits.token_no asc";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		
		function retrieveVisitsHaivingTests()
		{
			$location_id = $this->getLocationID();
			$query = "SELECT  v.* FROM visits v WHERE  v.location_id = '$location_id' AND  v.visit_id IN ( SELECT visit_id FROM presc_items) ";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
		}
		
		function countVisitsByDoctorID()
		{
			$doctor_id = $this->getDoctorID();
		
			$query = "SELECT count(*) FROM visits WHERE doctor_id = '$doctor_id'";
			if(!is_null($from)&&!is_null($to))
			{
				$startDateArray = explode('-',$from);
				$startTime = mktime(0,0,0,$startDateArray[1],$startDateArray[2],$startDateArray[0]);
				
				$endDateArray = explode('-',$to);
				$endTime = mktime(23,59,59,$endDateArray[1],$endDateArray[2],$endDateArray[0]);
				
				if($startTime!="")
				{
					if(($endTime!="" && $endTime > $startTime) || $endTime="")
					{
						$query .= " AND visit_date  > $startTime";
					}
				}
				
				if($endTime!="")
				{
					if(($startTime!="" && $startTime < $endTime) || $startTime="")
					{
						$query .= " AND visit_date  <= $endTime";
					}
				}
			}
			$query .= " order by order by token_no asc";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]['count(*)']))
			{
				return $visits_array[0]['count(*)'];
			}
			
		}
		function retrieveVisitsByDoctorID($from=NULL,$to=NULL,$limit=NULL)
		{
			$doctor_id = $this->getDoctorID();
			
			$query = "SELECT * FROM visits WHERE doctor_id = '$doctor_id'";
			
			if(!is_null($from)&&!is_null($to))
			{
				$startDateArray = explode('-',$from);
				$startTime = mktime(0,0,0,$startDateArray[1],$startDateArray[2],$startDateArray[0]);
				
				$endDateArray = explode('-',$to);
				$endTime = mktime(23,59,59,$endDateArray[1],$endDateArray[2],$endDateArray[0]);
				
				if($startTime!="")
				{
					if(($endTime!="" && $endTime > $startTime) || $endTime="")
					{
						$query .= " AND visit_date  > $startTime";
					}
				}
				
				if($endTime!="")
				{
					if(($startTime!="" && $startTime < $endTime) || $startTime="")
					{
						$query .= " AND visit_date  <= $endTime";
					}
				}
			}
			$query .= " order by order by token_no asc";
			
			if(!is_null($limit))
			{
				$query .= " LIMIT $limit";
			}
			
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		
		function retrieveCountAllVisits($from=NULL,$to=NULL)
		{
			$location_id = $this->getLocationID();
			
			$query = "SELECT count(visit_id) FROM visits WHERE location_id = '$location_id'";
			if(!is_null($from)&&!is_null($to))
			{
				$startDateArray = explode('-',$from);
				$startTime = mktime(0,0,0,$startDateArray[1],$startDateArray[2],$startDateArray[0]);
				
				$endDateArray = explode('-',$to);
				$endTime = mktime(23,59,59,$endDateArray[1],$endDateArray[2],$endDateArray[0]);
				
				if($startTime!="")
				{
					if(($endTime!="" && $endTime > $startTime) || $endTime="")
					{
						$query .= " AND visit_date  > $startTime";
					}
				}
				
				if($endTime!="")
				{
					if(($startTime!="" && $startTime < $endTime) || $startTime="")
					{
						$query .= " AND visit_date  <= $endTime";
					}
				}
			}
			$query .= ' order by visit_date desc';
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]['count(visit_id)']))
			{
				return $visits_array[0]['count(visit_id)'];
			}
			
		}
		function retrieveAllVisits($from=NULL,$to=NULL,$limit=NULL)
		{
			$location_id = $this->getLocationID();
			
			
			$query = "SELECT * FROM visits WHERE location_id = '$location_id'";
			
			if(!is_null($from)&&!is_null($to))
			{
				$startDateArray = explode('-',$from);
				$startTime = mktime(0,0,0,$startDateArray[1],$startDateArray[2],$startDateArray[0]);
				
				$endDateArray = explode('-',$to);
				$endTime = mktime(23,59,59,$endDateArray[1],$endDateArray[2],$endDateArray[0]);
				
				if($startTime!="")
				{
					if(($endTime!="" && $endTime > $startTime) || $endTime="")
					{
						$query .= " AND visit_date  > $startTime";
					}
				}
				
				if($endTime!="")
				{
					if(($startTime!="" && $startTime < $endTime) || $startTime="")
					{
						$query .= " AND visit_date  <= $endTime";
					}
				}
			}
			$query .= " order by visit_date desc";
			
			if(!is_null($limit))
			{
				$query .= " LIMIT $limit";
			}
			
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		
		function retrieveVisitByVisitID()
		{
			$visit_id = $this->getVisitID();
			
			$query = "SELECT * FROM visits WHERE visit_id = '$visit_id'";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		function countVisitsAndPaymenstByPatientID($patient_id)
		{
			
			$query = "SELECT count(*),sum(payment) FROM visits WHERE patient_id = '$patient_id' order by token_no asc";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		function retrieveVisitByPatientID()
		{
			$patient_id = $this->getPatientID();
			
			$query = "SELECT * FROM visits WHERE patient_id = '$patient_id' order by shift_date desc";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		
		function retrieveVisitByPatient($by_id,$by_name,$by_phone,$location_id,$from=NULL,$to=NULL)
		{
			$query ='';
			if($by_id!="")
			{
				$query = "SELECT visits.* , patient_fname,patient_lname,phone FROM visits JOIN patients ON visits.patient_id = patients.patient_auto_id WHERE  patients.patient_id = '$by_id' AND patients.location_id = '$location_id'";
			}
			elseif($by_name!="")
			{
				$query = "SELECT visits.* , patient_fname,patient_lname,phone FROM visits JOIN patients ON visits.patient_id = patients.patient_auto_id WHERE  (patients.patient_fname LIKE '%".$by_name."%' OR patients.patient_lname LIKE '%".$by_name."%') AND patients.location_id = '$location_id'"; 
			}
			elseif($by_phone!="")
			{
				$query = "SELECT visits.* , patient_fname,patient_lname,phone FROM visits JOIN patients ON visits.patient_id = patients.patient_auto_id WHERE  patients.phone LIKE '%".$by_phone."%'  AND patients.location_id = '$location_id'"; 
			}
			
			if(!is_null($from)&&!is_null($to))
			{
				$startDateArray = explode('-',$from);
				$startTime = mktime(0,0,0,$startDateArray[1],$startDateArray[2],$startDateArray[0]);
				
				$endDateArray = explode('-',$to);
				$endTime = mktime(23,59,59,$endDateArray[1],$endDateArray[2],$endDateArray[0]);
				
				if($startTime!="")
				{
					if(($endTime!="" && $endTime > $startTime) || $endTime="")
					{
						$query .= " AND visit_date  > $startTime";
					}
				}
				
				if($endTime!="")
				{
					if(($startTime!="" && $startTime < $endTime) || $startTime="")
					{
						$query .= " AND visit_date  <= $endTime";
					}
				}
			}
			$query .= " order by visit_date desc";
			
			
			
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		function retrieveVisitByPatientIDHavingTests()
		{
			$patient_id = $this->getPatientID();
			$location_id = $this->getLocationID();
			$query = "SELECT  v.* FROM visits v WHERE v.patient_id = '$patient_id' AND  v.location_id = '$location_id' AND  v.visit_id IN ( SELECT visit_id FROM presc_items) ";
			$queryOb = new classQueryGlobal;
			$visits_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($visits_array[0]))
			{
				return $visits_array;
			}
			
		}
		
		
		function retrievePrescription()
		{
			$visit_id = $this->getVisitID();
			
			$query = "SELECT * FROM presc_items LEFT JOIN dosage ON presc_items.dosage_id = dosage.dosage_id  WHERE visit_id = '$visit_id'";
			$queryOb = new classQueryGlobal;
			$prec_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($prec_array[0]))
			{
				return $prec_array;
			}
			
		}
		
		function retrieveIPDPrescription()
		{
			$ipd_bed_allotment_id = $this->getIpdBedAllotmentID();
			
			$query = "SELECT * FROM presc_items LEFT JOIN dosage ON presc_items.dosage_id = dosage.dosage_id  WHERE ipd_bed_allotment_id = '$ipd_bed_allotment_id'";
			$queryOb = new classQueryGlobal;
			$prec_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($prec_array[0]))
			{
				return $prec_array;
			}
			
		}
		
		function retrieveMedicines()
		{
			$org_id = $this->getOrganizationID();
			
			$query = "SELECT * FROM products WHERE active=1 and category='medicine' AND org_id = '$org_id' order by product_name asc";
			$queryOb = new classQueryGlobal;
			$med_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($med_array[0]))
			{
				return $med_array;
			}
		}
		function retrieveLabTests()
		{
			$org_id = $this->getOrganizationID();
			
			$query = "SELECT * FROM labtests WHERE org_id = '$org_id' order by labtest_name asc";
			$queryOb = new classQueryGlobal;
			$labtest_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($labtest_array[0]))
			{
				return $labtest_array;
			}
		}
		function retrieveProcedures()
		{
			$org_id = $this->getOrganizationID();
			
			$query = "SELECT * FROM procedures WHERE org_id = '$org_id' order by procedure_name asc";
			$queryOb = new classQueryGlobal;
			$proc_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($proc_array[0]))
			{
				return $proc_array;
			}
		}
		
		function retrieveMedicineByMedicineID()
		{
			$product_id = $this->getMedicineID();
			$query = "SELECT * FROM products WHERE product_id='$product_id'";
			$queryOb = new classQueryGlobal;
			$med_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($med_array[0]))
			{
				return $med_array;
			}
		}
		function retrieveLabTestsByLabTestID()
		{
			$labtest_id = $this->getLabTestID();
			$query = "SELECT * FROM labtests WHERE labtest_id = '$labtest_id'";
			$queryOb = new classQueryGlobal;
			$labtest_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($labtest_array[0]))
			{
				return $labtest_array;
			}
		}
		function retrieveProcedureByProcedureID()
		{
			$procedure_id = $this->getProcedureID();
			$query = "SELECT * FROM procedures WHERE procedure_id = '$procedure_id'";
			$queryOb = new classQueryGlobal;
			$proc_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($proc_array[0]))
			{
				return $proc_array;
			}
		}
		
		function retrieveDosage()
		{
			$org_id = $this->getOrganizationID();
			
			$query = "SELECT * FROM dosage WHERE org_id = '$org_id' order by dosage_id ASC";
			$queryOb = new classQueryGlobal;
			$dosage_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($dosage_array[0]))
			{
				return $dosage_array;
			}
		}
		
		function retrieveDressing()
		{
			$org_id = $this->getOrganizationID();
			
			$query = "SELECT * FROM dressing WHERE org_id = '$org_id' order by dressing_id ASC";
			$queryOb = new classQueryGlobal;
			$dressing_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($dressing_array[0]))
			{
				return $dressing_array;
			}
		}
		function retrieveDressingByID()
		{
			$dressing_id = $this->getDressingID();
			
			$query = "SELECT * FROM dressing WHERE dressing_id = '$dressing_id'";
			$queryOb = new classQueryGlobal;
			$dressing_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($dressing_array[0]))
			{
				return $dressing_array;
			}
		}
		
		
		function retrieveMedicalIssues()
		{
			$org_id = $this->getOrganizationID();
			
			$query = "SELECT * FROM medical_issues WHERE org_id = '$org_id' AND active = 1 order by med_issue asc";
			$queryOb = new classQueryGlobal;
			$med_issue_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($med_issue_array[0]))
			{
				return $med_issue_array;
			}
		}
		function retrieveMedicalIssueByID()
		{
			$med_issue_id = $this->getMedicalIssueID();
			
			$query = "SELECT * FROM medical_issues WHERE med_issue_id = '$med_issue_id'";
			$queryOb = new classQueryGlobal;
			$med_issue_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($med_issue_array[0]))
			{
				return $med_issue_array;
			}
		}
		
		
		
	  
}
?>