<!---diagnosis.cfc--->
<cfcomponent displayname="Reports"  hint="ColdFusion Component for Reports">
<cfinclude template='/__Security-Block.cfm' />   
    
    <cffunction name="get_priority_pat"  access="remote" output="Yes" returntype="query">   
            <cfargument name="patient_status"   hint="patient_status" deafault="">	
           <cfquery  datasource="#Application.DataSrc#" name="GetP">


                  SELECT DISTINCT pPatients.Patient_ID, pPatients.Status, 
                      pPatients.Pt_Last, pPatients.Pt_First, pPatients.Pt_Middle,pPatients.Comments AS Comment,
                      pPatients.Pt_Street,pPatients.Pt_City,
                       pPatients.Pt_State,pPatients.Pt_Zip,pPatients.Pt_Phone, 
                      pPtContacts.Patient_ID, pPtContacts.Last_Name, pPtContacts.First_Name, pPtContacts.Pt_Realtionship, pPtContacts.Telephone1, 
                       pPtContacts.Emergency AS PrimaryContact,pa.Emerg_Priority AS Priority,pPayer.Pay_Name,pPtPayer.Payer_ID,
                       pPhysicians.Phys_First,pPhysicians.Phys_Last,pPhysicians.Phys_Phone
                       FROM #Request.prefix_db_agency#.pPatients 
                       JOIN #Request.prefix_db_agency#.pPtContacts ON  pPatients.Patient_ID = pPtContacts.Patient_ID AND pPtContacts.status = 0
                       JOIN #Request.prefix_db_agency#.pAdmit pa  ON pPatients.Patient_ID = pa.Patient_ID  AND pa.status = 0
                       JOIN  #Request.prefix_db_lookup#.pPhysicians    ON pPhysicians.Phys_ID = pa.Render_Phys_ID  AND pPhysicians.status = 0
                       JOIN  #Request.prefix_db_agency#.pPtPayer ON  pPatients.Patient_ID = pPtPayer.Patient_ID AND pPtPayer.status = 0
                         JOIN  #Request.prefix_db_agency#.pPayer ON  pPayer.Pay_ID = pPtPayer.Payer_ID AND pPtPayer.status = 0

                      WHERE pPatients.Loc_ID = #session.AgencyID#
                      AND pPatients.Status < 2
                      <cfif (#arguments.patient_status# contains 'Yes' AND  #arguments.patient_status# contains 'NO')   
                        OR  #arguments.patient_status# contains 'all'> 
                      <cfelseif #arguments.patient_status# contains 'Yes'>  AND  pPatients.Status = '0'
                      <cfelseif #arguments.patient_status# contains 'No'>   AND  pPatients.Status = '1'
                      </cfif>
                      Order by  pPtContacts.Emergency ASC,Pt_Last ASC


                <!--- SELECT patient.Patient_ID, patient.Status, patient.Last_Name_M0040, patient.First_Name_M0040, patient.Middle_Initial_M0040,patient.Comment,patient.Street_Address,patient.City,
                   patient.State_M0050,patient.Zip_M0060,patient.Telephone,
				  patient.Admission_Status, patient.Primary_ReferringPhys_ID_M0072,
				  PatientContact.Patient_ID, PatientContact.ContactName, PatientContact.ContactType, PatientContact.Telephone1,              PatientContact.PrimaryContact,patient.Priority,PatientContact.ContactStreet,PatientContact.ContactCity,
                   Employee.First_Name,Employee.Last_Name,Employee.Home_Phone,patient.Payer_ID,Payer.PayName
                   FROM #Request.prefix_db_agency#.patient
                   JOIN #Request.prefix_db_agency#.PatientContact ON  patient.Patient_ID = PatientContact.Patient_ID
                   LEFT OUTER JOIN  #Request.prefix_db_agency#.Payer ON Payer.Payer_ID = patient.Payer_ID
                   LEFT OUTER JOIN  #Request.prefix_db_lookup#.Physician ON Physician.Physician_ID = patient.Primary_ReferringPhys_ID_M0072
                   JOIN #Request.prefix_db_lookup#.Employee ON Employee.Employee_ID = Physician.Employee_ID
                   WHERE patient.Agency_ID = #session.AgencyID#
				  <cfif (#arguments.patient_status# contains 'Yes' AND  #arguments.patient_status# contains 'NO')  OR  #arguments.patient_status# contains 'all'> 
				  <cfelseif #arguments.patient_status# contains 'Yes'>  AND  patient.Status = 'Active'
				   <cfelseif #arguments.patient_status# contains 'No'> AND  patient.Status = 'Inactive'</cfif>
				  AND patient.Patient_ID = PatientContact.Patient_ID
				  Order by  patient.Priority ASC, PatientContact.Priority ASC,Last_Name_M0040 ASC --->
				</cfquery>
           <cfreturn GetP>
   </cffunction>  
 
                
               
  </cfcomponent>