<!---dashboard.cfc--->
<cfcomponent displayname="Get_Customize_teachplan"  hint="ColdFusion Component for  coding wizard PRINT Careplan & Teachning Plan">
<cfinclude template='/__Security-Block.cfm' />   
     					

<cffunction name="Get_Teach_diagnoses_list_employee"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="patient_id" required="yes">
	<cfargument name="Assmt_ID" required="yes">
	<cfquery name="Teach_diagnoses_grid" datasource="#Application.DataSrc#">
			SELECT 
				pProblem.Problem_ID as Dg_id, pProblem.Assmt_ID as Dg_Assmt_ID, pProblem.Assmt_ID as Dg_Assessment_Tracker_ID, pProblem.Careplan, pPatients.Patient_ID as Dg_Patient_ID, pPatients.Loc_ID as Dg_Agency_ID,	pProblem.Description as Dg_Diagnosis, vetted_190924.ICD as Dg_ICD, vetted_190924.Assessment as Dig_Pathway_Type, pProblem.Description as Dig_Primary_Diagnosis, vetted_190924.PDGM as Dg_PDGM_Primary, vetted_190924.SUBCHAPTER as Dg_PDGM_Subchapter, vetted_190924.Comorbid as Dg_PDGM_Comorbidity, pProblem.Date_Create as Dg_Record_Creation_Date, pProblem.Created_by as Dg_Record_Created_By, pProblem.Date_Change as Dg_Record_Mod_Date, pProblem.Change_by as Dg_Record_Mod_By, pPatients.Pt_First, pPatients.Pt_Last, pPatients.Pt_Middle, pAssessments.F26 AS Assessment_Reason_M0100, pAssessments.F176 AS Assessment_Completed_M0090, pEmployee.Emp_First as super_user_name , '' as Employee_username, pEmployee.Emp_Last, pEmployee.Emp_First
			FROM 				
				#Request.prefix_db_agency#.pProblem
				JOIN #Request.prefix_db_lookup#.vetted_190924 ON  vetted_190924.Diagnosis = pProblem.Description	
				LEFT JOIN #Request.prefix_db_agency#.pAssessments ON pAssessments.Assmt_ID = pProblem.Assmt_ID	
				LEFT JOIN #Request.prefix_db_agency#.pPatients ON pPatients.Patient_ID = pAssessments.Patient_ID
				LEFT JOIN #Request.prefix_db_lookup#.pEmployee ON pEmployee.Emp_ID = pProblem.Created_by	
			WHERE   pPatients.Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer">
				AND pProblem.Assmt_ID=<cfqueryparam value="#arguments.Assmt_ID#" cfsqltype="cf_sql_integer"> 
				AND pProblem.Status = 0  
				AND pPatients.Status = 0  
				AND pAssessments.Status = 0  
				ORDER BY pProblem.Problem_ID ASC 
    </cfquery> 
	<cfreturn Teach_diagnoses_grid />	
</cffunction>


<cffunction name="Pathway_ID_based"  access="remote" output="Yes"  returntype="query">  
	<cfargument name="Patient_ID" required="yes">
	<cfargument name="Assmt_ID" required="yes">
	<cfargument name="Diagnosis_ID" required="yes">
	<cfargument name="ICD" required="yes">
    <cfargument name="language" hint="language" default="eng">
    <cfargument name="sym_prev" hint="sym_prev" default="0">
        <cfif arguments.language EQ 'eng'>
           <cfset teach_sk = 'Teaching_Skills'>
           <cfset teach_prev = 'Teaching_Prevention'>
        <cfelse>
           <cfset teach_sk = 'Teaching_Skills_span'>
           <cfset teach_prev = 'Teaching_Prevention_span'>
        </cfif>
         <cfif sym_prev EQ 1>
                <cfquery  datasource="#Application.DataSrc#" name="GET_Diagnosis_data">
                    SELECT * FROM  #Request.prefix_db_agency#.pProblem 
                    LEFT OUTER JOIN #Request.prefix_db_lookup#.vetted_190924 ON  vetted_190924.Diagnosis = pProblem.Description 
                    WHERE Assmt_ID = <cfqueryparam value = "#arguments.Assmt_ID#" CFSQLType ="CF_SQL_INTEGER"> 
                    AND ICD = <cfqueryparam value = "#arguments.ICD#" CFSQLType ="CF_SQL_VARCHAR">
                    AND pProblem.status = 0 
                    AND (pProblem.M0_No like 'M1023%' OR pProblem.M0_No like 'M1021%')
                    GROUP BY pProblem.Problem_ID
                </cfquery>
                <cfloop query ="GET_Diagnosis_data">
                    <cfset check_recordcfc = CreateObject("Component", "checkrecord") />
                    <cfif GET_Diagnosis_data.M0_No EQ 'DME/supplies'  OR GET_Diagnosis_data.M0_No EQ 'diet'>
                          <cfset variables.path_ID = #GET_Diagnosis_data.ICD# >
                    <cfelse>
                        <cfset getpathway  = check_recordcfc.get_pathwayid(#arguments.ICD#) />
                        <cfset variables.path_ID = #getpathway.Pathway# >
                    </cfif>
                    <cfif arguments.language EQ 'eng'>
                     	<cfset Teach_symptoms_chk = check_recordcfc.check_teaching_skills(#arguments.Patient_ID#,#arguments.Assmt_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,'symptom' ) />
                     	<cfset Teach_prevention_chk = check_recordcfc.check_teaching_skills(#arguments.Patient_ID#,#arguments.Assmt_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,'Teaching' ) />
                     	 <cfif Teach_prevention_chk neq 'success'>
                           <cfset insert_prevention = check_recordcfc.insert_preventions(#arguments.Patient_ID#,#arguments.Assmt_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,#variables.path_ID#,'eng' ) />	
                     	</cfif>
                     	<cfif Teach_symptoms_chk neq 'success'>
                            <cfset insert_sym = check_recordcfc.insert_symptoms(#arguments.Patient_ID#,#arguments.Assmt_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,#variables.path_ID#,'eng' ) />	
                       </cfif>
                    <cfelse>
	                     <cfset Teach_symptoms_span = check_recordcfc.check_teaching_skills(#arguments.Patient_ID#,#arguments.Assmt_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,'symptom','span' ) />
	                     <cfset Teach_prevention_span = check_recordcfc.check_teaching_skills(#arguments.Patient_ID#,#arguments.Assmt_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,'Teaching','span' ) />
	                    
	                    <cfif Teach_prevention_span neq 'success'>
	                           <cfset insert_prevention = check_recordcfc.insert_preventions(#arguments.Patient_ID#,#arguments.Assmt_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,#variables.path_ID#,'span' ) />	
	                    </cfif>
	                      
                      	<cfif Teach_symptoms_span neq 'success'>
                           <cfset insert_sym_span = check_recordcfc.insert_symptoms(#arguments.Patient_ID#,#arguments.Assmt_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,#variables.path_ID#,'span' ) />	
                        </cfif> 
                    </cfif>
                </cfloop>         
        </cfif>
		<cfquery  datasource="#Application.DataSrc#" name="get_TeachSkills_type_1">
			SELECT    ts.ID, ts.ICD,ts.Explanation,ts.Step_ID,ts.Line_ID,ts.Diagnosis_ID,ts.Pathway_Type,ts.Order_ID,ts.Pathway_ID,(SELECT type FROM #Request.prefix_db_lookup#.#teach_prev# as tp WHERE tp.Pathway_ID = ts.Pathway_ID AND tp.Type = 'Title' ) as title_type
			FROM  
				#Request.prefix_db_agency#.#teach_sk# as ts
			WHERE  ts.Diagnosis_ID=<cfqueryparam value = "#arguments.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER"> 
				AND ts.Patient_ID=<cfqueryparam value = "#arguments.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
				AND ts.Assmt_ID=<cfqueryparam value = "#arguments.Assmt_ID#" CFSQLType ="CF_SQL_INTEGER"> 
				AND ts.ICD=<cfqueryparam value = "#arguments.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
				AND ts.Deleted=0 
				AND ts.Pathway_Type NOT LIKE 'goal%' 
				AND ts.Pathway_Type NOT LIKE 'intervention%'
				AND ts.Pathway_Type NOT LIKE 'Source%' 
				AND ts.Title_Order_ID IS NOT NULL 
				AND ts.Pathway_Type <> 'Title'
				AND ts.Pathway_ID <> 0
				GROUP BY ts.Pathway_Type 
				<!---ORDER BY Title_Order_ID ASC--->
	            ORDER BY ts.Pathway_Type ASC			
		</cfquery>
		<cfreturn get_TeachSkills_type_1 />	
</cffunction>




<cffunction name="Groupby_Teach_diagnoses_list"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="patient_id" required="yes">
	<cfargument name="Assmt_ID" required="yes">
	<cfquery name="Teach_diagnoses_grid" datasource="#Application.DataSrc#">
			SELECT 
				pProblem.Problem_ID as Dg_id, pProblem.Assmt_ID as Dg_Assmt_ID, pProblem.Assmt_ID as Dg_Assessment_Tracker_ID, pPatients.Patient_ID as Dg_Patient_ID, pPatients.Loc_ID as Dg_Agency_ID,	pProblem.Description as Dg_Diagnosis,pProblem.Careplan, 

				vetted_190924.ICD as Dg_ICD, vetted_190924.Assessment as Dig_Pathway_Type, pProblem.Description as Dig_Primary_Diagnosis, vetted_190924.PDGM as Dg_PDGM_Primary, vetted_190924.SUBCHAPTER as Dg_PDGM_Subchapter, vetted_190924.Comorbid as Dg_PDGM_Comorbidity, pProblem.Date_Create as Dg_Record_Creation_Date, pProblem.Created_by as Dg_Record_Created_By, pProblem.Date_Change as Dg_Record_Mod_Date, pProblem.Change_by as Dg_Record_Mod_By, pPatients.Pt_First, pPatients.Pt_Last, pPatients.Pt_Middle, pAssessments.F26 AS Assessment_Reason_M0100, pAssessments.F176 AS Assessment_Completed_M0090, pEmployee.Emp_First as super_user_name , '' as Employee_username, pEmployee.Emp_Last, pEmployee.Emp_First
			FROM 				
				#Request.prefix_db_agency#.pProblem	
				JOIN #Request.prefix_db_lookup#.vetted_190924 ON  vetted_190924.Diagnosis = pProblem.Description		
				LEFT JOIN #Request.prefix_db_agency#.pAssessments on pAssessments.Assmt_ID = pProblem.Assmt_ID
				LEFT JOIN #Request.prefix_db_agency#.pPatients on pAssessments.Patient_ID = pPatients.Patient_ID
				LEFT JOIN #Request.prefix_db_lookup#.pEmployee ON pEmployee.Emp_ID = pProblem.Created_by
			WHERE 
				pPatients.Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer">
				AND pProblem.Assmt_ID=<cfqueryparam value="#arguments.Assmt_ID#" cfsqltype="cf_sql_integer"> 
				AND pProblem.Status = 0  
				AND pPatients.Status = 0  
				AND pAssessments.Status = 0  
				GROUP BY vetted_190924.Assessment ORDER BY pProblem.dx_order ASC
    </cfquery> 
	<cfreturn Teach_diagnoses_grid />	
</cffunction>


<cffunction name="Group_Diagnoses_list"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="patient_id" required="yes">
	<cfargument name="Assmt_ID" required="yes"> 
	<cfquery name="Teach_diagnoses_grid" datasource="#Application.DataSrc#">
			SELECT 
				pProblem.Problem_ID as Dg_id, pProblem.Assmt_ID as Dg_Assmt_ID, pProblem.Assmt_ID as Dg_Assessment_Tracker_ID, pPatients.Patient_ID as Dg_Patient_ID, pProblem.Careplan, 
				pPatients.Loc_ID as Dg_Agency_ID,	pProblem.Description as Dg_Diagnosis, 
				vetted_190924.ICD as Dg_ICD, vetted_190924.Assessment as Dig_Pathway_Type, pProblem.Description as Dig_Primary_Diagnosis, vetted_190924.PDGM as Dg_PDGM_Primary, vetted_190924.SUBCHAPTER as Dg_PDGM_Subchapter, vetted_190924.Comorbid as Dg_PDGM_Comorbidity, pProblem.Date_Create as Dg_Record_Creation_Date, pProblem.Created_by as Dg_Record_Created_By, pProblem.Date_Change as Dg_Record_Mod_Date, pProblem.Change_by as Dg_Record_Mod_By, pPatients.Pt_First, pPatients.Pt_Last, pPatients.Pt_Middle, pAssessments.F26 AS Assessment_Reason_M0100, pAssessments.F176 AS Assessment_Completed_M0090, pEmployee.Emp_First as super_user_name , '' as Employee_username, pEmployee.Emp_Last, pEmployee.Emp_First, pProblem.dx_order



			FROM 				
				#Request.prefix_db_agency#.pProblem		
				JOIN #Request.prefix_db_lookup#.vetted_190924 ON  vetted_190924.Diagnosis = pProblem.Description		
				LEFT JOIN #Request.prefix_db_agency#.pAssessments on pAssessments.Assmt_ID = pProblem.Assmt_ID
				LEFT JOIN #Request.prefix_db_agency#.pPatients on pAssessments.Patient_ID = pAssessments.Patient_ID
				LEFT JOIN #Request.prefix_db_lookup#.pEmployee ON pEmployee.Emp_ID = pProblem.Created_by	
			WHERE 

			pPatients.Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer">
				AND pProblem.Assmt_ID=<cfqueryparam value="#arguments.Assmt_ID#" cfsqltype="cf_sql_integer"> 
				AND pProblem.Status = 0  
				AND pPatients.Status = 0  
				AND pAssessments.Status = 0  
               <cfif #arguments.Pathway_type# eq 'DME/supplies' or #arguments.Pathway_type# eq 'diet'> 			
					 AND (pProblem.M0_No like 'M1023%' OR pProblem.M0_No like 'M1021%')
				</cfif>				 
				<cfif #arguments.Pathway_type# eq 'diagnosis' OR #arguments.Pathway_type# eq '' > 			
					 AND (pProblem.M0_No like 'M1023%' OR pProblem.M0_No like 'M1021%')
				</cfif>
				GROUP BY pProblem.Problem_ID ORDER BY pProblem.dx_order ASC
    </cfquery> 
	<cfreturn Teach_diagnoses_grid />	
</cffunction>


</cfcomponent>