<!---dashboard.cfc--->
<cfcomponent displayname="Get_Customize_teachplan"  hint="ColdFusion Component for  coding wizard PRINT Careplan & Teachning Plan">
<cfinclude template='/__Security-Block.cfm' />   
     					

<cffunction name="insert_teachplan"  access="remote" output="Yes" returnFormat= "JSON">   
     <cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	 <cfargument name="patient_id" required="yes">
	 <cfargument name="assessment_id" required="yes">
	 <cfargument name="Dx_list_ICD10_id" required="yes">
	 <cfargument name="assessmentTracker_id" required="yes"> 
	  <cfif arguments.patient_id  neq 0>	   		   	  
				<cfoutput>		  			  
						<cfset arguments.patient_id= decrypt(#arguments.patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
                        <cfset arguments.assessment_id= decrypt(#arguments.assessment_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
                        <cfset arguments.Dx_list_ICD10_id= decrypt(#arguments.Dx_list_ICD10_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />				
                        <cfset arguments.assessmentTracker_id= decrypt(#arguments.assessmentTracker_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
                        <cfif isDefined("session.issuperuser") and #session.issuperuser# eq "Yes">
                            <cfset super_user_check="1">
                        <cfelse>
                            <cfset super_user_check="0">
                        </cfif>		
						<cfset url.AID = #arguments.assessment_id# />
						<cfset url.ID = #arguments.patient_id# />
						<cfset url.redirect_from = "TeachPlan_Diagnosis" />
				</cfoutput> 
				<cfquery name="GET_Patient_details" datasource="#Application.DataSrc#">
					SELECT * FROM 
						#Request.prefix_db_agency#.Assessment_New 
					WHERE 
						Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> 						
				</cfquery>	
				<cfset OASIS_2019_2020_PDGM_chk = #GET_Patient_details.OASIS_2019_2020_PDGM# />				
				<cfquery name="Teach_diagnoses" datasource="#Application.DataSrc#">
					SELECT * FROM  #Request.prefix_db_agency#.Teaching_Skills 
					WHERE  Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> 
						AND Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> 
						AND Deleted=0 
						AND ICD=<cfqueryparam value="#arguments.ICD_no#" cfsqltype="CF_SQL_VARCHAR">
				</cfquery>					
				<cfquery name="Get_Teach_diagnoses_order" datasource="#Application.DataSrc#">
					SELECT  MAX(Dx_Order) as diagnosis_order FROM 
						#Request.prefix_db_agency#.Diagnosis 
					WHERE 
						Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> 
						AND Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> 
						AND Disabled=0 
						AND Assessment_Tracker_ID=<cfqueryparam value="#arguments.assessmentTracker_id#" cfsqltype="cf_sql_integer">
				</cfquery>	
				<cfquery name="Teach_diagnoses_list_chk" datasource="#Application.DataSrc#">
					SELECT *
                    FROM  #Request.prefix_db_lookup#.vetted_190924 as vt
                    JOIN  #Request.prefix_db_lookup#.CW_Coding_Class_PDGM  as cw ON  vt.Priority = cw.Priority
                    WHERE
<!---                  vt.Pathway = cw.Pathway_ID  AND --->
                    vt.ID = <cfqueryparam value="#arguments.Dx_list_ICD10_id#" cfsqltype="CF_SQL_INTEGER">  
				</cfquery>
                 <!--- <cfquery name="insert_CW_Visit_Plans" datasource="#Application.DataSrc#">
					SELECT * FROM  #Request.prefix_db_lookup#.CW_Coding_Class_PDGM  as cw
                    JOIN #Request.prefix_db_lookup#.vetted_190924 as vt ON  vt.Priority = cw.Priority
                    WHERE vt.Pathway = cw.Pathway_ID
                    AND vt.ICD = <cfqueryparam value="#Teach_diagnoses_list_chk.ICD#" cfsqltype="CF_SQL_VARCHAR"> 
				</cfquery>	 --->              
                
				<cfif Teach_diagnoses.RecordCount>
					<!---<cfset insert_action_fail="Failed" />	
					<cfreturn insert_action_fail />	--->	
                    <cfquery name="delete_teach" datasource="#Application.DataSrc#">
					    DELETE FROM  #Request.prefix_db_agency#.Teaching_Skills 
					     WHERE  Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> 
						 AND Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> 
						 AND Deleted=0 
						 AND ICD=<cfqueryparam value="#arguments.ICD_no#" cfsqltype="CF_SQL_VARCHAR">
				     </cfquery>	
                     <cfquery name="delet_teach" datasource="#Application.DataSrc#">
                         DELETE FROM  #Request.prefix_db_agency#.Teaching_Skills_span 
                           WHERE  Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> 
                            AND Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> 
                            AND Deleted=0 
                            AND ICD=<cfqueryparam value="#arguments.ICD_no#" cfsqltype="CF_SQL_VARCHAR">
                     </cfquery>	
                     <cfquery name="diable_diagnosis" datasource="#Application.DataSrc#">
                          UPDATE #Request.prefix_db_agency#.Diagnosis 
                           SET Disabled = 1
                           WHERE  Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> 
                            AND Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> 
                            AND ICD=<cfqueryparam value="#arguments.ICD_no#" cfsqltype="CF_SQL_VARCHAR">
                     </cfquery>		
				</cfif>
					<cfif Get_Teach_diagnoses_order.diagnosis_order eq 0 or Get_Teach_diagnoses_order.diagnosis_order eq ''>					
						<cfset Diagnosis_DX_Order_val = "1">
					<cfelse>
						<cfset Diagnosis_DX_Order_val = #Get_Teach_diagnoses_order.diagnosis_order#+1>
					</cfif>
					<cfset Assessment_M0230_Link='#arguments.assessment_id#'&' M0230' />				
					<cfquery  datasource="#Application.DataSrc#" name="insertDiagnoses_teach">	
						INSERT INTO #Request.prefix_db_agency#.Diagnosis
						(
							M0230_Link, Assessment_ID, Assessment_Tracker_ID, Patient_ID, Agency_ID, Diagnosis, ICD, Text_ICD, Short_Diagnosis, Record_Creation_Date,  Record_Created_By, Record_Mod_Date, Record_Mod_By, Dx_Order, Primary_Diagnosis ,<cfif #arguments.Primary_check# eq 0> PDGM_Comorbidity <cfelse> PDGM_Primary,  PDGM_Subchapter </cfif> , symptoms,Symptoms_S 
						) 
						VALUES
						(							
							<cfqueryparam value="#Assessment_M0230_Link#" cfsqltype="CF_SQL_VARCHAR">,
							<cfqueryparam value="#arguments.assessment_id#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value="#arguments.assessmentTracker_id#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value="#arguments.patient_id#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value="#arguments.AgencyID#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value="#Teach_diagnoses_list_chk.Diagnosis#" cfsqltype="CF_SQL_VARCHAR">,
							<cfqueryparam value="#Teach_diagnoses_list_chk.ICD#" cfsqltype="CF_SQL_VARCHAR">,
							<cfqueryparam value="#Teach_diagnoses_list_chk.ICD#" cfsqltype="CF_SQL_VARCHAR">,
							<cfqueryparam value="#Teach_diagnoses_list_chk.Diagnosis_Short#" cfsqltype="CF_SQL_VARCHAR">,							
							<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value ="#Diagnosis_DX_Order_val#" CFSQLType ="CF_SQL_INTEGER">,							
							<cfqueryparam value ="#arguments.Primary_check#" CFSQLType ="CF_SQL_INTEGER">,
							<cfif #arguments.Primary_check# eq 0> 
								<cfqueryparam value="#Teach_diagnoses_list_chk.Comorbid#" cfsqltype="CF_SQL_VARCHAR">
							<cfelse> 
								<cfqueryparam value="#Teach_diagnoses_list_chk.PDGM#" cfsqltype="CF_SQL_VARCHAR">,
								<cfqueryparam value="#Teach_diagnoses_list_chk.Subchapter#" cfsqltype="CF_SQL_VARCHAR">
							</cfif>
								,<cfqueryparam value="#Teach_diagnoses_list_chk.Symptoms#" cfsqltype="CF_SQL_VARCHAR">
                                ,<cfqueryparam value="#Teach_diagnoses_list_chk.Symptoms_S#" cfsqltype="CF_SQL_VARCHAR">
						)
					</cfquery>	
					<cfset Diagnosis_DX_Order_val = "0">
					<cfquery name="last_insert_diagnoses_id_agency" datasource="#Application.DataSrc#">
						select LAST_INSERT_ID() as diagnoses_id_agency
					</cfquery>							
					 <cfset check_recordcfc = CreateObject("Component", "checkrecord") />
                    <cfset insert_prevention = check_recordcfc.insert_preventions(#arguments.patient_id#,#arguments.assessment_id#,#last_insert_diagnoses_id_agency.diagnoses_id_agency#,#Teach_diagnoses_list_chk.ICD#,#Teach_diagnoses_list_chk.Pathway#,'eng' ) />	
                  <cfset insert_prevention = check_recordcfc.insert_preventions(#arguments.patient_id#,#arguments.assessment_id#,#last_insert_diagnoses_id_agency.diagnoses_id_agency#,#Teach_diagnoses_list_chk.ICD#,#Teach_diagnoses_list_chk.Pathway#,'span' ) />	
				    <cfset insert_sym = check_recordcfc.insert_symptoms(#arguments.patient_id#,#arguments.assessment_id#,#last_insert_diagnoses_id_agency.diagnoses_id_agency#,#Teach_diagnoses_list_chk.ICD#,#Teach_diagnoses_list_chk.Pathway#,'eng' ) />	
               <cfset insert_sym_span = check_recordcfc.insert_symptoms(#arguments.patient_id#,#arguments.assessment_id#,#last_insert_diagnoses_id_agency.diagnoses_id_agency#,#Teach_diagnoses_list_chk.ICD#,#Teach_diagnoses_list_chk.Pathway#,'span' ) />
                   <cfset teching_skill_order ="0">						
					<cfset insert_action="Sucess" />					
					<cfif #OASIS_2019_2020_PDGM_chk# eq "Teaching Plan & Visit Plan" >
						<cfinclude template="../patientadmin_new/patient/cron_coding_mel.cfm" />
					</cfif>	
					<cfreturn insert_action />	
							
	<cfelse>						
	</cfif>						
</cffunction>	


<cffunction name="update_teachplan_diagnosis"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="patient_id" required="yes">
	<cfargument name="assessment_id" required="yes">
	<cfargument name="Dx_list_ICD10_id" required="yes">
	<cfargument name="assessmentTracker_id" required="yes">
	<cfoutput>
		<cfset arguments.patient_id= decrypt(#arguments.patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
		<cfset arguments.assessment_id= decrypt(#arguments.assessment_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
		<cfset arguments.Dx_list_ICD10_id= decrypt(#arguments.Dx_list_ICD10_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />				
		<cfset arguments.assessmentTracker_id= decrypt(#arguments.assessmentTracker_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
	</cfoutput>
	
	<cfquery name="Teach_diagnoses_list_chk" datasource="#Application.DataSrc#">
        SELECT *
        FROM  #Request.prefix_db_lookup#.vetted_190924 as vt
        JOIN #Request.prefix_db_lookup#.CW_Coding_Class_PDGM  as cw ON  vt.Priority = cw.Priority
        WHERE
<!---        vt.Pathway = cw.Pathway_ID AND --->
        vt.ID =<cfqueryparam value="#arguments.Dx_list_ICD10_id#" cfsqltype="cf_sql_integer"> 
	</cfquery>	
	
	
	<cfquery name="Diagnoses_list" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_agency#.Diagnosis	WHERE Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> AND Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> AND Disabled=0 AND ICD=<cfqueryparam value="#arguments.ICD_no#" cfsqltype="CF_SQL_VARCHAR">
	</cfquery>	
	
		<cfquery name="Diagnosis_list_check" datasource="#Application.DataSrc#">
			SELECT * FROM #Request.prefix_db_agency#.Diagnosis WHERE Primary_Diagnosis=1 AND Patient_ID=<cfqueryparam value = "#arguments.patient_id#" CFSQLType ="CF_SQL_INTEGER">  AND Assessment_ID=<cfqueryparam value = "#arguments.assessment_id#" CFSQLType ="CF_SQL_INTEGER"> AND Assessment_Tracker_ID=<cfqueryparam value = "#arguments.assessmentTracker_id#" CFSQLType ="CF_SQL_INTEGER"> AND Disabled <> 1 AND Pathway_Type=""	
		</cfquery>
	
	 
	<cfif arguments.Primary_check eq 1>		
			
		<cfif Diagnosis_list_check.RecordCount>
			<cfquery  datasource="#Application.DataSrc#" name="update_Diagnosis_old">	
				UPDATE #Request.prefix_db_agency#.Diagnosis SET	
					Primary_Diagnosis = <cfqueryparam value = "0" CFSQLType ="CF_SQL_INTEGER">,
					Record_Mod_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
					Record_Mod_By = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
				WHERE Diagnosis_ID= <cfqueryparam value = "#Diagnosis_list_check.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>
		</cfif>	
	
		<cfquery  datasource="#Application.DataSrc#" name="Update_Teachplan_Diagnosis">	
			UPDATE 
				#Request.prefix_db_agency#.Diagnosis 
			SET		
				Primary_Diagnosis = <cfqueryparam value ="#arguments.Primary_check#" CFSQLType ="CF_SQL_INTEGER">,
				PDGM_Comorbidity = <cfqueryparam value="#Teach_diagnoses_list_chk.Comorbid#" cfsqltype="CF_SQL_VARCHAR">,		PDGM_Primary = <cfqueryparam value="#Teach_diagnoses_list_chk.PDGM#" cfsqltype="CF_SQL_VARCHAR">,				PDGM_Subchapter = <cfqueryparam value="#Teach_diagnoses_list_chk.Subchapter#" cfsqltype="CF_SQL_VARCHAR">,
				Record_Creation_Date = <cfqueryparam value="#Diagnoses_list.Record_Creation_Date#" cfsqltype="cf_sql_date">,  
				Record_Created_By = <cfqueryparam value = "#Diagnoses_list.Record_Created_By#" CFSQLType ="CF_SQL_INTEGER">,
				Record_Mod_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 				
				Record_Mod_By = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">				
			WHERE 
				Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> AND Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> AND Disabled=0 AND ICD=<cfqueryparam value="#arguments.ICD_no#" cfsqltype="CF_SQL_VARCHAR">
		</cfquery>
		<cfset Diagnosis_update = "Sucess" />
	<cfelse>		
		<cfset Diagnosis_update = "Failed" />														
	</cfif>	
	
	<cfreturn Diagnosis_update />	
		
</cffunction>
	
<cffunction name="update_diagnosis"  access="remote" output="Yes" returnFormat= "plain">   
    <cfargument name="patient_id" required="yes">
	<cfargument name="assessment_id" required="yes">
	<cfargument name="severity" required="yes">
	<cfargument name="diagnosis_id" required="yes">
	<cfoutput>
		<cfset arguments.patient_id= decrypt(#arguments.patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
		<cfset arguments.assessment_id= decrypt(#arguments.assessment_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
	</cfoutput>	
    <cfquery  datasource="#Application.DataSrc#" name="update_Diagnosis_old">	
        UPDATE #Request.prefix_db_agency#.Diagnosis SET	
            severity = <cfqueryparam value = "#arguments.severity#" CFSQLType ="CF_SQL_INTEGER">,
            Dx_Order = <cfqueryparam value = "#arguments.Dx_Order#" CFSQLType ="CF_SQL_INTEGER">,
            Record_Mod_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
            Record_Mod_By = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
        WHERE Diagnosis_ID= <cfqueryparam value = "#arguments.diagnosis_id#" CFSQLType ="CF_SQL_INTEGER">
    </cfquery>
    <cfreturn "Sucess" />	
</cffunction>
                

<cffunction name="get_Assessment_list"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="patient_id" required="yes">								   
		<cfif arguments.patient_id  neq 0>			   	  
			<cfoutput>
				<cfset arguments.patient_id= decrypt(#arguments.patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />								
			</cfoutput> 
			<cfquery  datasource="#Application.DataSrc#" name="get_Assessment_all">
				select Assessment_New.Assessment_ID, Assessment_New.Assessment_Tracker_ID, Assessment_New.Assessment_Completed_M0090, Assessment_New.Assessment_Reason_M0100, Assessment_New.Record_Creation_Date
				from #Request.prefix_db_agency#.Assessment_New 
				WHERE  Patient_ID=<cfqueryparam value = "#arguments.patient_id#" CFSQLType ="CF_SQL_INTEGER"> and Agency_ID=<cfqueryparam value = "#arguments.AgencyID#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>					
			<cfsavecontent	variable = "html_list"> 
				<div class="portlet box red">
					<div class="portlet-title">
						<div class="caption">
							<i class="fa fa-gear"></i>Select an assessment from the list below
						</div>
					</div>
					<div class="portlet-body flip-scroll">
						<table class="table table-bordered table-striped table-condensed flip-content">
							<thead class="flip-content">
								<tr>
									<th>
										Assessment Type
									</th>
									<th>
										Date Completed
									</th>
									<th>
										Created Dated
									</th>									
								</tr>
							</thead>
							<tbody>									
								<cfif isdefined('get_Assessment_all.recordcount') and  get_Assessment_all.RecordCount GT 0>												
									<cfoutput query="get_Assessment_all">										
										<cfset Encrypted_PatientID=encrypt(#arguments.patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") /> 
										<cfset Encrypted_AssesmentID=encrypt(#get_Assessment_all.Assessment_ID#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") /> 
										<tr>
											<td class="cell" style="width:400px;" >
												<a href="javascript:void(0);" onclick="javascript:secureHREF('/dashboard/index.cfm?page=dashboard&cat&rpt=teachplan_new&patient_id=#Encrypted_PatientID#&assessment_id=#Encrypted_AssesmentID#')">
								 #get_Assessment_all.Assessment_Reason_M0100#</a>
											</td>
											<td class="cell" style="width:200px;">#DateFormat(get_Assessment_all.Assessment_Completed_M0090,"mm/dd/yyyy")#
												
											</td>
											<td class="cell" style="width:200px;">#DateFormat(get_Assessment_all.Record_Creation_Date,"mm/dd/yyyy")#
												
											</td>											
										</tr>
									</cfoutput>
								<cfelse>
										<tr>
											<td align="center" valign="middle" colspan="3" height="50px">
												No Assesments Found
											</td>
										</tr>										
								</cfif>
							</tbody>
						</table>
					</div>
				</div>
			</cfsavecontent>	
			<cfreturn html_list />	
		</cfif>	
</cffunction>

<!---	

<cffunction name="Orderchange_Teachplan"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 		
						   
	   <cfif arguments.teachtitle_tbl_agency_id  neq 0>			  
	   
		  <cfoutput>
			<cfset arguments.patient_id= decrypt(#arguments.patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
			<cfset arguments.assessment_id= decrypt(#arguments.assessment_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />						
			<cfset arguments.teachtitle_tbl_agency_id= decrypt(#arguments.teachtitle_tbl_agency_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />					
		  </cfoutput> 
		  
		  	<cfquery  datasource="#Application.DataSrc#" name="SelectDiagnoses_teach">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Title 
				WHERE  id=<cfqueryparam value = "#arguments.teachtitle_tbl_agency_id#" CFSQLType ="CF_SQL_INTEGER"> AND Type=<cfqueryparam value="#arguments.teach_plantype#" cfsqltype="CF_SQL_VARCHAR">	
			</cfquery>	
			
			
			<cfquery  datasource="#Application.DataSrc#" name="Diagnoses_teach_Check">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Title 
				WHERE  id <> <cfqueryparam value = "#arguments.teachtitle_tbl_agency_id#" CFSQLType ="CF_SQL_INTEGER"> AND `Order` = <cfqueryparam value = "#arguments.teachtitle_order_no#" CFSQLType ="CF_SQL_INTEGER"> AND Assessment_ID=<cfqueryparam value = "#arguments.assessment_id#" CFSQLType ="CF_SQL_INTEGER">  AND Agency_ID=<cfqueryparam value = "#arguments.AgencyID#" CFSQLType ="CF_SQL_INTEGER"> AND Patient_ID=<cfqueryparam value = "#arguments.patient_id#" CFSQLType ="CF_SQL_INTEGER"> AND Deleted=0 
				AND Type=<cfqueryparam value="#arguments.teach_plantype#" cfsqltype="CF_SQL_VARCHAR">				
				
			</cfquery>	
			
		
				  <cfif Diagnoses_teach_Check.RecordCount eq 0>
				  
					<cfquery  name="editTeachTitle_update" datasource="#Application.DataSrc#">
						UPDATE #Request.prefix_db_agency#.Teaching_Title SET			
							`Order` = <cfqueryparam value = "#arguments.teachtitle_order_no#" CFSQLType ="CF_SQL_INTEGER">,					
							Record_creation_date = <cfqueryparam value="#SelectDiagnoses_teach.Record_creation_date#" cfsqltype="cf_sql_date">,
							Created_By = <cfqueryparam value = "#SelectDiagnoses_teach.Created_By#" CFSQLType ="CF_SQL_INTEGER">,
							Record_updated_date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
							Updated_By = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
						WHERE id= <cfqueryparam value = "#arguments.teachtitle_tbl_agency_id#" CFSQLType ="CF_SQL_INTEGER">
					</cfquery>
					
					<cfset teachskill_update = "Sucess" />	
							  
				  <cfelse>
					
					<cfquery  name="TeachsTitle_old_update_order" datasource="#Application.DataSrc#">
						UPDATE #Request.prefix_db_agency#.Teaching_Title SET			
							`Order` = <cfqueryparam value = "#SelectDiagnoses_teach.Order#" CFSQLType ="CF_SQL_INTEGER">,					
							Record_creation_date = <cfqueryparam value="#Diagnoses_teach_Check.Record_creation_date#" cfsqltype="cf_sql_date">,
							Created_By = <cfqueryparam value = "#Diagnoses_teach_Check.Created_By#" CFSQLType ="CF_SQL_INTEGER">,
							Record_updated_date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
							Updated_By = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
						WHERE id= <cfqueryparam value = "#Diagnoses_teach_Check.id#" CFSQLType ="CF_SQL_INTEGER">
					</cfquery>
					
					
					<cfquery  name="TeachsTitle_new_update_order" datasource="#Application.DataSrc#">
						UPDATE #Request.prefix_db_agency#.Teaching_Title SET			
							`Order` = <cfqueryparam value = "#arguments.teachtitle_order_no#" CFSQLType ="CF_SQL_INTEGER">,					
							Record_creation_date = <cfqueryparam value="#SelectDiagnoses_teach.Record_creation_date#" cfsqltype="cf_sql_date">,
							Created_By = <cfqueryparam value = "#SelectDiagnoses_teach.Created_By#" CFSQLType ="CF_SQL_INTEGER">,
							Record_updated_date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
							Updated_By = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
						WHERE id= <cfqueryparam value = "#arguments.teachtitle_tbl_agency_id#" CFSQLType ="CF_SQL_INTEGER">
					</cfquery>
						  
						<cfset teachskill_update = "Sucess" />
				  </cfif>	  		
								
			<cfreturn teachskill_update />	
			
		</cfif>	
</cffunction>

--->

		<!---							Get list from database	start					--->
		

<cffunction name="get_TeachSkills_list"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="diagnosis_table_id" required="yes">								   
		<cfif arguments.diagnosis_table_id  neq ''>					
			<cfquery  datasource="#Application.DataSrc#" name="get_TeachSkills_all">
				SELECT 
					Teaching_Skills.ID, Teaching_Skills.ICD, Teaching_Skills.Explanation, Teaching_Skills.Step_ID, Teaching_Skills.Diagnosis_ID, Teaching_Skills.Pathway_Type
				FROM 
					(SELECT Teaching_Skills.ID, Teaching_Skills.ICD, Teaching_Skills.Explanation, Teaching_Skills.Step_ID, Teaching_Skills.Diagnosis_ID, Teaching_Skills.Pathway_Type FROM #Request.prefix_db_agency#.Teaching_Skills WHERE Diagnosis_ID=<cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> AND Deleted=0 AND Pathway_Type NOT IN('goal','intervention') ORDER BY Step_ID ASC) as Teaching_Skills 
				ORDER BY Pathway_Type
			</cfquery>	
			
			<cfreturn get_TeachSkills_all />	
		</cfif>	
</cffunction>



<cffunction name="GET_Teach_Skills_Li"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="diagnosis_table_id" required="yes">							   
		<cfif arguments.diagnosis_table_id  neq ''>		
			
			<cfquery  datasource="#Application.DataSrc#" name="get_TeachSkills_all">
				SELECT 
					Teaching_Skills.ID, Teaching_Skills.ICD, Teaching_Skills.Explanation, Teaching_Skills.Step_ID, Teaching_Skills.Diagnosis_ID, Teaching_Skills.Pathway_Type, Teaching_Skills.Order_ID
				FROM 
					#Request.prefix_db_agency#.Teaching_Skills 
				WHERE 
					Diagnosis_ID=<cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> AND Deleted=0 AND Pathway_Type NOT LIKE 'goal%' 
AND  Pathway_Type NOT LIKE 'intervention%' AND  Pathway_Type NOT LIKE 'Source%' ORDER BY Order_ID ASC
			</cfquery>	
			
			<cfreturn get_TeachSkills_all />	
		</cfif>	
</cffunction>




<cffunction name="GET_Teach_Skills_list_dup"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="diagnosis_table_id" required="yes">						   
		<cfif arguments.diagnosis_table_id  neq '' >	
			<cfquery  datasource="#Application.DataSrc#" name="GET_Diagnosis_data">
				SELECT * FROM  #Request.prefix_db_agency#.Diagnosis 
				WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> 
                AND Disabled = 0 
			</cfquery>
            <cfset check_recordcfc = CreateObject("Component", "checkrecord") />
            <cfset Teach_symptoms_chk = check_recordcfc.check_teaching_skills(#GET_Diagnosis_data.Patient_ID#,#GET_Diagnosis_data.Assessment_ID#,#GET_Diagnosis_data.Diagnosis_ID#,#GET_Diagnosis_data.ICD#,'symptom' ) />
            <cfset Teach_prevention_chk = check_recordcfc.check_teaching_skills(#GET_Diagnosis_data.Patient_ID#,#GET_Diagnosis_data.Assessment_ID#,#GET_Diagnosis_data.Diagnosis_ID#,#GET_Diagnosis_data.ICD#,'Teaching' ) />
             <cfset Teach_symptoms_span = check_recordcfc.check_teaching_skills(#GET_Diagnosis_data.Patient_ID#,#GET_Diagnosis_data.Assessment_ID#,#GET_Diagnosis_data.Diagnosis_ID#,#GET_Diagnosis_data.ICD#,'symptom','span' ) />
            <cfset Teach_prevention_span = check_recordcfc.check_teaching_skills(#GET_Diagnosis_data.Patient_ID#,#GET_Diagnosis_data.Assessment_ID#,#GET_Diagnosis_data.Diagnosis_ID#,#GET_Diagnosis_data.ICD#,'Teaching','span' ) />
            <cfparam name="teching_skill_order" default="0">
			<cfparam name="teching_skill_title_order_id" default="1">	
                <cfif GET_Diagnosis_data.Pathway_Type EQ 'DME/supplies' OR GET_Diagnosis_data.Pathway_Type EQ 'diet'>
                      <cfset path_ID = #GET_Diagnosis_data.ICD# >
                 <cfelse>
                    <cfset getpathway  = check_recordcfc.get_pathwayid(#GET_Diagnosis_data.ICD#) />
                    <cfset path_ID = #getpathway.Pathway# >
                </cfif>
			
			<cfquery name="insert_CW_Visit_Plans" datasource="#Application.DataSrc#">
				 SELECT *
                    FROM  #Request.prefix_db_lookup#.vetted_190924 as vt
                    JOIN #Request.prefix_db_lookup#.CW_Coding_Class_PDGM  as cw ON  vt.Priority = cw.Priority
                    WHERE
                   <!--- vt.Pathway = cw.Pathway_ID AND --->
                            vt.ICD = <cfqueryparam value="#GET_Diagnosis_data.ICD#" cfsqltype="CF_SQL_VARCHAR"> 
			</cfquery>
                
           
                
			<cfif Teach_prevention_chk eq 'success'> 
				<cfquery  datasource="#Application.DataSrc#" name="Get_order_count">
					SELECT  ID, Patient_ID, Assessment_ID, ICD, 3Digit, Pathway_Type, Pathway_ID, Diagnosis_ID, Deleted, max(Order_ID) as max_order, max(Title_Order_ID) as max_title_order 	 FROM  #Request.prefix_db_agency#.Teaching_Skills 
					  WHERE 
						Diagnosis_ID=<cfqueryparam value = "#GET_Diagnosis_data.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER"> 
						AND Patient_ID=<cfqueryparam value = "#GET_Diagnosis_data.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
						AND Assessment_ID=<cfqueryparam value = "#GET_Diagnosis_data.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> 
						AND ICD=<cfqueryparam value = "#GET_Diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
						AND Pathway_Type='Teaching'
						AND Pathway_ID <> 0
						AND Deleted=0 
				</cfquery>
				<cfset teching_skill_order = Get_order_count.max_order+2 />		
				<cfset teching_skill_title_order_id = Get_order_count.max_title_order+2 />						
			<cfelse>	
                <cfset insert_prevention = check_recordcfc.insert_preventions(#GET_Diagnosis_data.Patient_ID#,#GET_Diagnosis_data.Assessment_ID#,#GET_Diagnosis_data.Diagnosis_ID#,#GET_Diagnosis_data.ICD#,#path_ID#,'eng' ) />	
            </cfif>	
            <cfif Teach_prevention_span neq 'success'>
                  <cfset insert_prevention = check_recordcfc.insert_preventions(#GET_Diagnosis_data.Patient_ID#,#GET_Diagnosis_data.Assessment_ID#,#GET_Diagnosis_data.Diagnosis_ID#,#GET_Diagnosis_data.ICD#,#path_ID#,'span' ) />	
                  </cfif>
			<cfif Teach_symptoms_chk neq 'success'>
				    <cfset insert_sym = check_recordcfc.insert_symptoms(#GET_Diagnosis_data.Patient_ID#,#GET_Diagnosis_data.Assessment_ID#,#GET_Diagnosis_data.Diagnosis_ID#,#GET_Diagnosis_data.ICD#,#path_ID#,'eng' ) />	
            </cfif>
            <cfif Teach_symptoms_span neq 'success'>
               <cfset insert_sym_span = check_recordcfc.insert_symptoms(#GET_Diagnosis_data.Patient_ID#,#GET_Diagnosis_data.Assessment_ID#,#GET_Diagnosis_data.Diagnosis_ID#,#GET_Diagnosis_data.ICD#,#path_ID#,'span' ) />	
            </cfif>
			    <cfset teching_skill_order ="0">		
		       <cfset response_key = [] />
                <cfset exp_all = []/>
                <cfparam name="obj" default="">
				<cfparam name="Explanation_obj" default="">				 
				<cfquery  datasource="#Application.DataSrc#" name="get_TeachSkills_all_groupby">
                    SELECT   Teaching_Skills.ID, Teaching_Skills.ICD, Teaching_Skills.Explanation, Teaching_Skills.Step_ID, Teaching_Skills.Line_ID, Teaching_Skills.Diagnosis_ID, Teaching_Skills.Pathway_Type, Teaching_Skills.Order_ID,Teaching_Skills.Pathway_ID,(SELECT type FROM #Request.prefix_db_lookup#.Teaching_Prevention WHERE Teaching_Prevention.Pathway_ID = Teaching_Skills.Pathway_ID AND Type = 'Title' ) as title_type
                    FROM  
						#Request.prefix_db_agency#.Teaching_Skills 
                    WHERE  
						Diagnosis_ID = <cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> 
						AND Deleted=0 
						AND Pathway_Type NOT LIKE 'goal%' 
						AND  Pathway_Type NOT LIKE 'intervention%'
						AND  Pathway_Type NOT LIKE 'Source%' 
						AND Title_Order_ID IS NOT NULL 
						AND Pathway_Type <> 'Title'
						AND Pathway_ID <> 0
						GROUP BY Pathway_Type 
						ORDER BY Title_Order_ID ASC
                </cfquery>	
				<cfloop query="get_TeachSkills_all_groupby">				 
					 <cfquery  datasource="#Application.DataSrc#" name="get_TeachSkills_all">
						SELECT   Teaching_Skills.ID, Teaching_Skills.ICD, Teaching_Skills.Explanation, Teaching_Skills.Step_ID, Teaching_Skills.Diagnosis_ID, Teaching_Skills.Line_ID, Teaching_Skills.Pathway_Type, Teaching_Skills.Order_ID,Teaching_Skills.Pathway_ID,<cfif #get_TeachSkills_all_groupby.Pathway_ID# eq 0> 'Title' as title_type <cfelse>(SELECT type FROM #Request.prefix_db_lookup#.Teaching_Prevention WHERE Teaching_Prevention.Pathway_ID = Teaching_Skills.Pathway_ID AND Type = 'Title' ) as title_type </cfif>
						FROM  
							#Request.prefix_db_agency#.Teaching_Skills 
						WHERE  
							Diagnosis_ID = <cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> 
							AND Deleted=0 
							AND Pathway_Type NOT LIKE 'goal%' 
							AND Pathway_Type NOT LIKE 'intervention%'
							AND Pathway_Type NOT LIKE 'Source%' 
							AND Pathway_ID <> 0
							<cfif #get_TeachSkills_all_groupby.Pathway_Type# neq ''>AND Pathway_Type = '#get_TeachSkills_all_groupby.Pathway_Type#'</cfif>  
							<cfif #get_TeachSkills_all_groupby.Pathway_Type# eq "Teaching">
								OR ( Pathway_Type = 'Title' AND Step_ID=129 AND Line_ID=0 AND Diagnosis_ID = <cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> AND Pathway_ID <> 0 )
							<cfelseif #get_TeachSkills_all_groupby.Pathway_Type# eq "symptom">
								OR ( Pathway_Type = 'Title' AND Step_ID=0 AND Line_ID=0 AND Diagnosis_ID = <cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> AND Pathway_ID <> 0 )
							</cfif> 
							ORDER BY Order_ID ASC
					</cfquery>
					<cfoutput query="get_TeachSkills_all">						
							<cfset Explanation_obj  = {"Order_ID" = #get_TeachSkills_all.Order_ID#, "Pathway_ID"  = #get_TeachSkills_all.Pathway_ID#, "Pathway_Type" = #get_TeachSkills_all.Pathway_Type#, "Diagnosis_ID" = #get_TeachSkills_all.Diagnosis_ID#, "Step_ID" = #get_TeachSkills_all.Step_ID#, "Explanation" = #get_TeachSkills_all.Explanation# , "ICD" = #get_TeachSkills_all.ICD#, "ID" = #get_TeachSkills_all.ID#, "Line_ID" = #get_TeachSkills_all.Line_ID# }  />
							<cfset arrayAppend(exp_all,Explanation_obj) />
					</cfoutput>															
					<cfset obj  = {"title" = #get_TeachSkills_all.title_type# , "Data_All" = exp_all }  />
					<cfset arrayAppend(response_key,obj) />					
					<cfset exp_all = []>
					<cfset obj = "">
					<cfset Explanation_obj = "">					
				</cfloop>	
				<!---<cfif CGI.REMOTE_ADDR eq '103.66.78.232'>					
					<cfdump var="#response_key#">
					<cfabort>
				</cfif>--->							
			    <cfreturn  serializeJSON(response_key) >  
		</cfif>	
        
        <!---<cfif arguments.diagnosis_table_id  neq '' and session.agencyid neq 179>	
			<cfquery  datasource="#Application.DataSrc#" name="GET_Diagnosis_data">
				SELECT * FROM  #Request.prefix_db_agency#.Diagnosis 
				WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> 
			</cfquery>
            
			<cfquery  datasource="#Application.DataSrc#" name="Teach_symptoms_chk">
				SELECT * FROM 
					#Request.prefix_db_agency#.Teaching_Skills 
				WHERE 
					Diagnosis_ID=<cfqueryparam value = "#GET_Diagnosis_data.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER">
					AND Patient_ID=<cfqueryparam value = "#GET_Diagnosis_data.Patient_ID#" CFSQLType ="CF_SQL_INTEGER">  
					AND Assessment_ID=<cfqueryparam value = "#GET_Diagnosis_data.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND ICD=<cfqueryparam value = "#GET_Diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
					AND Pathway_Type='symptom'
					AND Pathway_ID <> 0
					AND Deleted=0 
			</cfquery>
			<cfquery  datasource="#Application.DataSrc#" name="Teach_prevention_chk">
				SELECT 	* FROM 
					#Request.prefix_db_agency#.Teaching_Skills 
				WHERE 
					Diagnosis_ID=<cfqueryparam value = "#GET_Diagnosis_data.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND Patient_ID=<cfqueryparam value = "#GET_Diagnosis_data.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND Assessment_ID=<cfqueryparam value = "#GET_Diagnosis_data.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND ICD=<cfqueryparam value = "#GET_Diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
					AND Pathway_Type='Teaching'
					AND Pathway_ID <> 0
					AND Deleted=0 
			</cfquery>
			<cfparam name="teching_skill_order" default="0">
			<cfparam name="teching_skill_title_order_id" default="1">	
			
			<cfquery name="insert_CW_Visit_Plans" datasource="#Application.DataSrc#">
				SELECT * FROM  #Request.prefix_db_lookup#.CW_Coding_Class_PDGM  as cw
				JOIN #Request.prefix_db_lookup#.vetted_190924 as vt ON  vt.Priority = cw.Priority
				WHERE vt.Pathway = cw.Pathway_ID
				AND vt.ICD = <cfqueryparam value="#GET_Diagnosis_data.ICD#" cfsqltype="CF_SQL_VARCHAR"> 
			</cfquery>
					
			<cfif Teach_prevention_chk.RecordCount and Teach_prevention_chk.RecordCount gt 0> 
				<cfquery  datasource="#Application.DataSrc#" name="Get_order_count">
					SELECT 
						ID, Patient_ID, Assessment_ID, ICD, 3Digit, Pathway_Type, Pathway_ID, Diagnosis_ID, Deleted, max(Order_ID) as max_order, max(Title_Order_ID) as max_title_order 	
					FROM 
						#Request.prefix_db_agency#.Teaching_Skills 
					WHERE 
						Diagnosis_ID=<cfqueryparam value = "#GET_Diagnosis_data.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER"> 
						AND Patient_ID=<cfqueryparam value = "#GET_Diagnosis_data.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
						AND Assessment_ID=<cfqueryparam value = "#GET_Diagnosis_data.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> 
						AND ICD=<cfqueryparam value = "#GET_Diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
						AND Pathway_Type='Teaching'
						AND Pathway_ID <> 0
						AND Deleted=0 
				</cfquery>
				<cfset teching_skill_order = Get_order_count.max_order+2 />		
				<cfset teching_skill_title_order_id = Get_order_count.max_title_order+2 />						
			<cfelse>	 						
				<cfquery name="select_Teach_Prevention" datasource="#Application.DataSrc#">
					SELECT * FROM #Request.prefix_db_lookup#.Teaching_Prevention 
					WHERE 
						Pathway_ID=<cfqueryparam value="#insert_CW_Visit_Plans.Pathway#" cfsqltype="CF_SQL_INTEGER">  
						ORDER BY Step_ID ASC
				</cfquery>					
				<cfoutput query="select_Teach_Prevention">									
					<cfset teching_skill_order = teching_skill_order+1>	
					<cfset teching_skill_title_order_id =teching_skill_title_order_id+1>										
					<cfquery  datasource="#Application.DataSrc#" name="insert_Teaching_Skills">
						INSERT INTO #Request.prefix_db_agency#.Teaching_Skills 
						(
							Patient_ID, Assessment_ID, ICD, 3Digit, Pathway_Type, Pathway_ID, <cfif #select_Teach_Prevention.Step_ID# neq ''> Step_ID,</cfif> <cfif #select_Teach_Prevention.Line_ID# neq ''> Line_ID, </cfif> Explanation, Created_Date, Created_by, Updated_Date, Updated_by, Diagnosis_ID, `Order_ID`, Title_Order_ID
						)
						VALUES 
						(								
							<cfqueryparam value="#GET_Diagnosis_data.Patient_ID#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value="#GET_Diagnosis_data.Assessment_ID#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value = "#GET_Diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
							<cfqueryparam value = "#Left(GET_Diagnosis_data.ICD,3)#" CFSQLType ="CF_SQL_VARCHAR">,
							<cfqueryparam value = "#select_Teach_Prevention.Type#" CFSQLType ="CF_SQL_VARCHAR">,
							<cfqueryparam value="#insert_CW_Visit_Plans.Pathway#" cfsqltype="CF_SQL_INTEGER">,									
							<cfif #select_Teach_Prevention.Step_ID# neq ''>		
								<cfqueryparam value = "#select_Teach_Prevention.Step_ID#" CFSQLType ="CF_SQL_INTEGER">,		
							</cfif>						
							<cfif #select_Teach_Prevention.Line_ID# neq ''>		
								<cfqueryparam value = "#select_Teach_Prevention.Line_ID#" CFSQLType ="CF_SQL_INTEGER">,
							</cfif>		
							<cfqueryparam value = "#select_Teach_Prevention.Explanation#" CFSQLType ="CF_SQL_VARCHAR">,								
							<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value = "#GET_Diagnosis_data.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value = "#teching_skill_order#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value = "#teching_skill_title_order_id#" CFSQLType ="CF_SQL_INTEGER">													
						)	
					</cfquery>								
				</cfoutput>			
			</cfif>	
			
		
			<cfif Teach_symptoms_chk.RecordCount and Teach_symptoms_chk.RecordCount gt 0>
						
			<cfelse>
				<cfquery  datasource="#Application.DataSrc#" name="Teach_symp_list_chk">					
					SELECT * FROM 
						#Request.prefix_db_lookup#.Teaching_Symptoms 
					WHERE 
						3Digit = '#Left(GET_Diagnosis_data.ICD,3)#'
						ORDER BY Step_ID ASC
				</cfquery>					
				<cfoutput query="Teach_symp_list_chk">					
					<cfset teching_skill_order = teching_skill_order+1>		
					<cfset teching_skill_title_order_id =teching_skill_title_order_id+1>										
					<cfquery  datasource="#Application.DataSrc#" name="insert_teach_Skills">
						INSERT INTO #Request.prefix_db_agency#.Teaching_Skills 
						(
							Patient_ID, Assessment_ID, ICD, 3Digit, Pathway_Type, Pathway_ID, <cfif #Teach_symp_list_chk.Step_ID# neq ''> Step_ID,</cfif> <cfif #Teach_symp_list_chk.Line_ID# neq ''> Line_ID, </cfif> Explanation, Created_Date, Created_by, Updated_Date, Updated_by, Diagnosis_ID, Order_ID, Title_Order_ID
						)
						VALUES 
						(
							<cfqueryparam value ="#GET_Diagnosis_data.Patient_ID#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value ="#GET_Diagnosis_data.Assessment_ID#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value ="#GET_Diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
							<cfqueryparam value ="#Teach_symp_list_chk.3Digit#" CFSQLType ="CF_SQL_VARCHAR">,
							<cfqueryparam value ="#Teach_symp_list_chk.Type#" CFSQLType ="CF_SQL_VARCHAR">,
							<cfqueryparam value ="#insert_CW_Visit_Plans.Pathway#" cfsqltype="CF_SQL_INTEGER">,	 							
							<cfif #Teach_symp_list_chk.Step_ID# neq ''>		
								<cfqueryparam value ="#Teach_symp_list_chk.Step_ID#" CFSQLType ="CF_SQL_INTEGER">,	
							</cfif>								
							<cfif #Teach_symp_list_chk.Line_ID# neq ''>		
								<cfqueryparam value ="#Teach_symp_list_chk.Line_ID#" CFSQLType ="CF_SQL_INTEGER">,
							</cfif>									
							<cfqueryparam value ="#Teach_symp_list_chk.Explanation#" CFSQLType ="CF_SQL_VARCHAR">,								
							<cfqueryparam value ="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value ="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value ="#GET_Diagnosis_data.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value = "#teching_skill_order#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value = "#teching_skill_title_order_id#" CFSQLType ="CF_SQL_INTEGER">		
						)	
					</cfquery>				
				</cfoutput>				
			</cfif>
			<cfset teching_skill_order ="0">		
		
		
							
                <cfset response_key = [] />
                <cfset exp_all = []/>
                <cfparam name="obj" default="">
				<cfparam name="Explanation_obj" default="">				 
				<cfquery  datasource="#Application.DataSrc#" name="get_TeachSkills_all_groupby">
                    SELECT   Teaching_Skills.ID, Teaching_Skills.ICD, Teaching_Skills.Explanation, Teaching_Skills.Step_ID, Teaching_Skills.Line_ID, Teaching_Skills.Diagnosis_ID, Teaching_Skills.Pathway_Type, Teaching_Skills.Order_ID,Teaching_Skills.Pathway_ID,(SELECT type FROM #Request.prefix_db_lookup#.Teaching_Prevention WHERE Teaching_Prevention.Pathway_ID = Teaching_Skills.Pathway_ID AND Type = 'Title' ) as title_type
                    FROM  
						#Request.prefix_db_agency#.Teaching_Skills 
                    WHERE  
						Diagnosis_ID = <cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> 
						AND Deleted=0 
						AND Pathway_Type NOT LIKE 'goal%' 
						AND  Pathway_Type NOT LIKE 'intervention%'
						AND  Pathway_Type NOT LIKE 'Source%' 
						AND Title_Order_ID IS NOT NULL 
						AND Pathway_Type <> 'Title'
						AND Pathway_ID <> 0
						GROUP BY Pathway_Type 
						ORDER BY Title_Order_ID ASC
                </cfquery>	
				<cfloop query="get_TeachSkills_all_groupby">				 
					 <cfquery  datasource="#Application.DataSrc#" name="get_TeachSkills_all">
						SELECT   Teaching_Skills.ID, Teaching_Skills.ICD, Teaching_Skills.Explanation, Teaching_Skills.Step_ID, Teaching_Skills.Diagnosis_ID, Teaching_Skills.Line_ID, Teaching_Skills.Pathway_Type, Teaching_Skills.Order_ID,Teaching_Skills.Pathway_ID,<cfif #get_TeachSkills_all_groupby.Pathway_ID# eq 0> 'Title' as title_type <cfelse>(SELECT type FROM #Request.prefix_db_lookup#.Teaching_Prevention WHERE Teaching_Prevention.Pathway_ID = Teaching_Skills.Pathway_ID AND Type = 'Title' ) as title_type </cfif>
						FROM  
							#Request.prefix_db_agency#.Teaching_Skills 
						WHERE  
							Diagnosis_ID = <cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> 
							AND Deleted=0 
							AND Pathway_Type NOT LIKE 'goal%' 
							AND Pathway_Type NOT LIKE 'intervention%'
							AND Pathway_Type NOT LIKE 'Source%' 
							AND Pathway_ID <> 0
							<cfif #get_TeachSkills_all_groupby.Pathway_Type# neq ''>AND Pathway_Type = '#get_TeachSkills_all_groupby.Pathway_Type#'</cfif>  
							<cfif #get_TeachSkills_all_groupby.Pathway_Type# eq "Teaching">
								OR ( Pathway_Type = 'Title' AND Step_ID=129 AND Line_ID=0 AND Diagnosis_ID = <cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> AND Pathway_ID <> 0 )
							<cfelseif #get_TeachSkills_all_groupby.Pathway_Type# eq "symptom">
								OR ( Pathway_Type = 'Title' AND Step_ID=0 AND Line_ID=0 AND Diagnosis_ID = <cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> AND Pathway_ID <> 0 )
							</cfif> 
							ORDER BY Order_ID ASC
					</cfquery>
					<cfoutput query="get_TeachSkills_all">						
							<cfset Explanation_obj  = {"Order_ID" = #get_TeachSkills_all.Order_ID#, "Pathway_ID"  = #get_TeachSkills_all.Pathway_ID#, "Pathway_Type" = #get_TeachSkills_all.Pathway_Type#, "Diagnosis_ID" = #get_TeachSkills_all.Diagnosis_ID#, "Step_ID" = #get_TeachSkills_all.Step_ID#, "Explanation" = #get_TeachSkills_all.Explanation# , "ICD" = #get_TeachSkills_all.ICD#, "ID" = #get_TeachSkills_all.ID#, "Line_ID" = #get_TeachSkills_all.Line_ID# }  />
							<cfset arrayAppend(exp_all,Explanation_obj) />
					</cfoutput>															
					<cfset obj  = {"title" = #get_TeachSkills_all.title_type# , "Data_All" = exp_all }  />
					<cfset arrayAppend(response_key,obj) />					
					<cfset exp_all = []>
					<cfset obj = "">
					<cfset Explanation_obj = "">					
				</cfloop>	
				<!---<cfif CGI.REMOTE_ADDR eq '103.66.78.232'>					
					<cfdump var="#response_key#">
					<cfabort>
				</cfif>--->							
			    <cfreturn  serializeJSON(response_key) >  
		</cfif>--->
</cffunction>


<cffunction name="GET_Teach_Skills_list"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="diagnosis_table_id" required="yes">						   
		<cfif arguments.diagnosis_table_id  neq ''>						
                <cfset response_key = [] />
                <cfset exp_all = []/>
                <cfparam name="obj" default="">
				<cfparam name="Explanation_obj" default="">			
                
                <cfquery name="get_diagnosis" datasource="#Application.DataSrc#" >
                    SELECT * FROM  #Request.prefix_db_agency#.Diagnosis 
                    JOIN    #Request.prefix_db_lookup#.vetted_190924 ON  vetted_190924.ICD = Diagnosis.ICD 
                    WHERE  Diagnosis.Diagnosis_ID = <cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> 
                    AND  Diagnosis.Disabled = 0 
                 </cfquery>
                 <cfloop query="get_diagnosis">
                    <cfquery  datasource="#Application.DataSrc#" name="get_teaching_prevention">
                       SELECT * FROM #Request.prefix_db_lookup#.Teaching_Prevention ORDER BY Step_ID ASC
                   </cfquery>
                     <cfoutput query="get_teaching_prevention">						
							<cfset Explanation_obj  = {"Order_ID" = #get_teaching_prevention.Step_ID#, "Pathway_ID"  = #get_teaching_prevention.Pathway_ID#, "Pathway_Type" = #get_diagnosis.Pathway_Type#, "Diagnosis_ID" = #get_diagnosis.Diagnosis_ID#, "Step_ID" = #get_teaching_prevention.Step_ID#, "Explanation" = #get_teaching_prevention.Explanation# , "ICD" = #get_diagnosis.ICD#, "ID" = #get_teaching_prevention.ID# }  />
							<cfset arrayAppend(exp_all,Explanation_obj) />
					</cfoutput>															
					<cfset obj  = {"title" = #get_teaching_prevention.Type# , "Data_All" = exp_all }  />
					<cfset arrayAppend(response_key,obj) />					
					<cfset exp_all = []>
					<cfset obj = "">
					<cfset Explanation_obj = "">	
                 </cfloop>
                 <cfreturn  serializeJSON(response_key) >  
		</cfif>	
</cffunction>
<cffunction name="GETTeachSkills_List"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="diagnosis_table_id" required="yes">
		<cfoutput>#arguments.diagnosis_table_id#</cfoutput>									   
		<cfif arguments.diagnosis_table_id  neq ''>	
			<cfquery  datasource="#Application.DataSrc#" name="get_TeachSkills_all">
				SELECT 
					Teaching_Skills.ID, Teaching_Skills.ICD, Teaching_Skills.Explanation, Teaching_Skills.Step_ID, Teaching_Skills.Diagnosis_ID, Teaching_Skills.Pathway_Type, Teaching_Skills.Order_ID
				FROM 
					#Request.prefix_db_agency#.Teaching_Skills 
				WHERE 
					Diagnosis_ID=<cfqueryparam value = "#arguments.diagnosis_table_id#" CFSQLType ="CF_SQL_INTEGER"> AND Deleted=0 AND Pathway_Type NOT LIKE 'goal%' 
AND  Pathway_Type NOT LIKE 'intervention%' AND  Pathway_Type NOT LIKE 'Source%' AND Pathway_Type="Title" GROUP BY Pathway_ID 
			</cfquery>
			<cfreturn get_TeachSkills_all />	
		</cfif>	
</cffunction>

<cffunction name="Get_Teach_diagnoses_list"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="patient_id" required="yes">
	<cfargument name="assessment_id" required="yes">
	<cfquery name="Teach_diagnoses_grid" datasource="#Application.DataSrc#">
			SELECT 
				Diagnosis.Diagnosis_ID as Dg_id, Diagnosis.Assessment_ID as Dg_Assessment_ID, Diagnosis.Assessment_Tracker_ID as Dg_Assessment_Tracker_ID, Diagnosis.Patient_ID as Dg_Patient_ID, Diagnosis.Agency_ID as Dg_Agency_ID,	Diagnosis.Diagnosis as Dg_Diagnosis, Diagnosis.ICD as Dg_ICD, Diagnosis.Pathway_Type as Dig_Pathway_Type, Diagnosis.Primary_Diagnosis as Dig_Primary_Diagnosis, Diagnosis.PDGM_Primary as Dg_PDGM_Primary, Diagnosis.PDGM_Subchapter as Dg_PDGM_Subchapter, Diagnosis.PDGM_Comorbidity as Dg_PDGM_Comorbidity, Diagnosis.Record_Creation_Date as Dg_Record_Creation_Date, Diagnosis.Record_Created_By as Dg_Record_Created_By, Diagnosis.Record_Mod_Date as Dg_Record_Mod_Date, Diagnosis.Record_Mod_By as Dg_Record_Mod_By, patient.First_Name_M0040, patient.Last_Name_M0040, patient.Middle_Initial_M0040, Assessment_New.Assessment_Reason_M0100, Assessment_New.Assessment_Completed_M0090,SuperUsers.Full_Name as super_user_name
			FROM 				
				#Request.prefix_db_agency#.Diagnosis		
				LEFT JOIN #Request.prefix_db_agency#.patient on patient.Patient_ID = Diagnosis.Patient_ID
				LEFT JOIN #Request.prefix_db_agency#.Assessment_New on Assessment_New.Assessment_ID = Diagnosis.Assessment_ID
				LEFT JOIN #Request.prefix_db_lookup#.SuperUsers on SuperUsers.User_ID = Diagnosis.Record_Created_By	
			WHERE 
				Diagnosis.Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> AND Diagnosis.Agency_ID=<cfqueryparam value="#session.AgencyID#" cfsqltype="cf_sql_integer"> AND Diagnosis.Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> 
				ORDER BY Diagnosis.Diagnosis_ID ASC
    </cfquery> 
	<cfreturn Teach_diagnoses_grid />	
</cffunction>


<cffunction name="Get_Teach_diagnoses_list_employee"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="patient_id" required="yes">
	<cfargument name="assessment_id" required="yes">
	<cfquery name="Teach_diagnoses_grid" datasource="#Application.DataSrc#">
			SELECT 
				Diagnosis.Diagnosis_ID as Dg_id, Diagnosis.Assessment_ID as Dg_Assessment_ID, Diagnosis.Assessment_Tracker_ID as Dg_Assessment_Tracker_ID, Diagnosis.Patient_ID as Dg_Patient_ID, Diagnosis.Agency_ID as Dg_Agency_ID,	Diagnosis.Diagnosis as Dg_Diagnosis, Diagnosis.ICD as Dg_ICD, Diagnosis.Pathway_Type as Dig_Pathway_Type, Diagnosis.Primary_Diagnosis as Dig_Primary_Diagnosis, Diagnosis.PDGM_Primary as Dg_PDGM_Primary, Diagnosis.PDGM_Subchapter as Dg_PDGM_Subchapter, Diagnosis.PDGM_Comorbidity as Dg_PDGM_Comorbidity, Diagnosis.Record_Creation_Date as Dg_Record_Creation_Date, Diagnosis.Record_Created_By as Dg_Record_Created_By, Diagnosis.Record_Mod_Date as Dg_Record_Mod_Date, Diagnosis.Record_Mod_By as Dg_Record_Mod_By, patient.First_Name_M0040, patient.Last_Name_M0040, patient.Middle_Initial_M0040, Assessment_New.Assessment_Reason_M0100, Assessment_New.Assessment_Completed_M0090,SuperUsers.Full_Name as super_user_name , Employee.Username as Employee_username, Employee.Last_Name as Employee_Last_Name, Employee.First_Name as Employee_First_Name
			FROM 				
				#Request.prefix_db_agency#.Diagnosis		
				LEFT JOIN #Request.prefix_db_agency#.patient on patient.Patient_ID = Diagnosis.Patient_ID
				LEFT JOIN #Request.prefix_db_agency#.Assessment_New on Assessment_New.Assessment_ID = Diagnosis.Assessment_ID
				LEFT JOIN #Request.prefix_db_lookup#.SuperUsers on SuperUsers.User_ID = Diagnosis.Record_Created_By	
				LEFT JOIN #Request.prefix_db_lookup#.Employee on Employee.Employee_ID = patient.Employee_ID	
			WHERE 
				Diagnosis.Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> AND Diagnosis.Agency_ID=<cfqueryparam value="#session.AgencyID#" cfsqltype="cf_sql_integer"> AND Diagnosis.Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer">  
				ORDER BY Diagnosis.Diagnosis_ID ASC 
    </cfquery> 
	<cfreturn Teach_diagnoses_grid />	
</cffunction>




<cffunction name="Groupby_Teach_diagnoses_list"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="patient_id" required="yes">
	<cfargument name="assessment_id" required="yes">
	<cfquery name="Teach_diagnoses_grid" datasource="#Application.DataSrc#">
			SELECT 
				Diagnosis.Diagnosis_ID as Dg_id, Diagnosis.Assessment_ID as Dg_Assessment_ID, Diagnosis.Assessment_Tracker_ID as Dg_Assessment_Tracker_ID, Diagnosis.Patient_ID as Dg_Patient_ID, Diagnosis.Agency_ID as Dg_Agency_ID,	Diagnosis.Diagnosis as Dg_Diagnosis, Diagnosis.ICD as Dg_ICD, Diagnosis.Pathway_Type as Dig_Pathway_Type, Diagnosis.Clinical_Type as Dg_Pathway_ID,Diagnosis.Primary_Diagnosis as Dig_Primary_Diagnosis, Diagnosis.PDGM_Primary as Dg_PDGM_Primary, Diagnosis.PDGM_Subchapter as Dg_PDGM_Subchapter, Diagnosis.PDGM_Comorbidity as Dg_PDGM_Comorbidity, Diagnosis.Record_Creation_Date as Dg_Record_Creation_Date, Diagnosis.Record_Created_By as Dg_Record_Created_By, Diagnosis.Record_Mod_Date as Dg_Record_Mod_Date, Diagnosis.Record_Mod_By as Dg_Record_Mod_By, patient.First_Name_M0040, patient.Last_Name_M0040, patient.Middle_Initial_M0040, Assessment_New.Assessment_Reason_M0100, Assessment_New.Assessment_Completed_M0090,SuperUsers.Full_Name as super_user_name
			FROM 				
				#Request.prefix_db_agency#.Diagnosis		
				LEFT JOIN #Request.prefix_db_agency#.patient on patient.Patient_ID = Diagnosis.Patient_ID
				LEFT JOIN #Request.prefix_db_agency#.Assessment_New on Assessment_New.Assessment_ID = Diagnosis.Assessment_ID
				LEFT JOIN #Request.prefix_db_lookup#.SuperUsers on SuperUsers.User_ID = Diagnosis.Record_Created_By	
			WHERE 
				Diagnosis.Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> 
				AND Diagnosis.Agency_ID=<cfqueryparam value="#session.AgencyID#" cfsqltype="cf_sql_integer"> 
				AND Diagnosis.Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> 
				AND Diagnosis.Disabled=0 
				GROUP BY Diagnosis.Pathway_Type ORDER BY Diagnosis.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="assessment_id" required="yes"> 
	<cfquery name="Teach_diagnoses_grid" datasource="#Application.DataSrc#">
			SELECT 
				Diagnosis.Diagnosis_ID as Dg_id, Diagnosis.Assessment_ID as Dg_Assessment_ID, Diagnosis.Assessment_Tracker_ID as Dg_Assessment_Tracker_ID, Diagnosis.Patient_ID as Dg_Patient_ID, Diagnosis.Agency_ID as Dg_Agency_ID,	Diagnosis.Diagnosis as Dg_Diagnosis, Diagnosis.ICD as Dg_ICD, Diagnosis.Pathway_Type as Dig_Pathway_Type,Diagnosis.Clinical_Type as Dg_Clinical_Type, Diagnosis.Dx_Order as Dig_Dx_Order, Diagnosis.Primary_Diagnosis as Dig_Primary_Diagnosis, Diagnosis.PDGM_Primary as Dg_PDGM_Primary, Diagnosis.PDGM_Subchapter as Dg_PDGM_Subchapter, Diagnosis.PDGM_Comorbidity as Dg_PDGM_Comorbidity, Diagnosis.Record_Creation_Date as Dg_Record_Creation_Date, Diagnosis.Record_Created_By as Dg_Record_Created_By, Diagnosis.Record_Mod_Date as Dg_Record_Mod_Date, Diagnosis.Record_Mod_By as Dg_Record_Mod_By, patient.First_Name_M0040, patient.Last_Name_M0040, patient.Middle_Initial_M0040, Assessment_New.Assessment_Reason_M0100, Assessment_New.Assessment_Completed_M0090,SuperUsers.Full_Name as super_user_name
			FROM 				
				#Request.prefix_db_agency#.Diagnosis		
				LEFT JOIN #Request.prefix_db_agency#.patient on patient.Patient_ID = Diagnosis.Patient_ID
				LEFT JOIN #Request.prefix_db_agency#.Assessment_New on Assessment_New.Assessment_ID = Diagnosis.Assessment_ID
				LEFT JOIN #Request.prefix_db_lookup#.SuperUsers on SuperUsers.User_ID = Diagnosis.Record_Created_By	
			WHERE 
				Diagnosis.Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> 
				AND Diagnosis.Agency_ID=<cfqueryparam value="#session.AgencyID#" cfsqltype="cf_sql_integer"> 
				AND Diagnosis.Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> 
				AND Diagnosis.Disabled=0 
               <cfif #arguments.Pathway_type# eq 'DME/supplies' or #arguments.Pathway_type# eq 'diet'> 			
				 	AND Diagnosis.Pathway_Type='#arguments.Pathway_type#'
				</cfif>				 
				<cfif #arguments.Pathway_type# eq 'diagnosis' OR #arguments.Pathway_type# eq '' > 			
					AND((Diagnosis.Pathway_Type <> 'DME/supplies' AND Diagnosis.Pathway_Type <> 'diet') OR Diagnosis.Pathway_Type is NULL OR Diagnosis.Pathway_Type = 'diagnosis') 
				</cfif>
				 ORDER BY Dig_Dx_Order ASC
    </cfquery> 
	<cfreturn Teach_diagnoses_grid />	
</cffunction>


<cffunction name="Teach_DME_Diet_list"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="patient_id" required="yes">
	<cfargument name="assessment_id" required="yes"> 
	<cfquery name="Teach_diagnoses_grid" datasource="#Application.DataSrc#">
			SELECT 
				Diagnosis.Diagnosis_ID as Dg_id, Diagnosis.Assessment_ID as Dg_Assessment_ID, Diagnosis.Assessment_Tracker_ID as Dg_Assessment_Tracker_ID, Diagnosis.Patient_ID as Dg_Patient_ID, Diagnosis.Agency_ID as Dg_Agency_ID,	Diagnosis.Diagnosis as Dg_Diagnosis, Diagnosis.ICD as Dg_ICD, Diagnosis.Pathway_Type as Dig_Pathway_Type, Diagnosis.Primary_Diagnosis as Dig_Primary_Diagnosis, Diagnosis.PDGM_Primary as Dg_PDGM_Primary, Diagnosis.Dx_Order as Dx_Order,Diagnosis.Severity as Dx_Severity,Diagnosis.PDGM_Subchapter as Dg_PDGM_Subchapter, Diagnosis.PDGM_Comorbidity as Dg_PDGM_Comorbidity, Diagnosis.Record_Creation_Date as Dg_Record_Creation_Date, Diagnosis.Record_Created_By as Dg_Record_Created_By, Diagnosis.Record_Mod_Date as Dg_Record_Mod_Date, Diagnosis.Record_Mod_By as Dg_Record_Mod_By, patient.First_Name_M0040, patient.Last_Name_M0040, patient.Middle_Initial_M0040, Assessment_New.Assessment_Reason_M0100, Assessment_New.Assessment_Completed_M0090,SuperUsers.Full_Name as super_user_name
			FROM 				
				#Request.prefix_db_agency#.Diagnosis		
				LEFT JOIN #Request.prefix_db_agency#.patient on patient.Patient_ID = Diagnosis.Patient_ID
				LEFT JOIN #Request.prefix_db_agency#.Assessment_New on Assessment_New.Assessment_ID = Diagnosis.Assessment_ID
				LEFT JOIN #Request.prefix_db_lookup#.SuperUsers on SuperUsers.User_ID = Diagnosis.Record_Created_By	
			WHERE 
				Diagnosis.Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> AND Diagnosis.Agency_ID=<cfqueryparam value="#session.AgencyID#" cfsqltype="cf_sql_integer"> AND Diagnosis.Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> AND Diagnosis.Disabled=0 				
				<cfif #arguments.Pathway_type# eq 'DME/supplies' or #arguments.Pathway_type# eq 'diet'> 			
				 	AND Diagnosis.Pathway_Type='#arguments.Pathway_type#' <!---ORDER BY Diagnosis.Dx_Order ASC--->
				</cfif>				 
				<cfif #arguments.Pathway_type# eq 'diagnosis' OR #arguments.Pathway_type# eq '' > 			
					AND((Diagnosis.Pathway_Type <> 'DME/supplies' AND Diagnosis.Pathway_Type <> 'diet') OR Diagnosis.Pathway_Type is NULL OR Diagnosis.Pathway_Type = 'diagnosis') <!---ORDER BY Diagnosis.Dx_Order ASC--->
				</cfif>
				ORDER BY Diagnosis.Dx_Order ASC	
    </cfquery> 
	<cfreturn Teach_diagnoses_grid />	
</cffunction>

<cffunction name="Get_Patients_list"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="patient_id" required="yes"> 
	<cfquery name="get_Patient" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_agency#.patient WHERE Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer"> AND Agency_ID=<cfqueryparam value="#arguments.AgencyID#" cfsqltype="cf_sql_integer">
    </cfquery> 
	<cfreturn get_Patient />	
</cffunction>

<cffunction name="Get_Superuser_Details"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="Created_By" required="yes"> 
	<cfquery name="get_super_user_name" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_lookup#.SuperUsers
         WHERE User_ID=<cfif arguments.Created_By eq ''>0<cfelse><cfqueryparam value="#arguments.Created_By#" cfsqltype="cf_sql_integer"></cfif>
	</cfquery>
	<cfreturn get_super_user_name />	
</cffunction>		

<cffunction name="Get_Employee_Details"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="Created_By" required="yes"> 
	<cfquery name="get_employee_name" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_lookup#.Employee WHERE Employee_ID=<cfif arguments.Created_By eq ''>0<cfelse><cfqueryparam value="#arguments.Created_By#" cfsqltype="cf_sql_integer"></cfif>
	</cfquery>
	<cfreturn get_employee_name />	
</cffunction>


<cffunction name="Get_Diagnosis_Details"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="diagnosis_id" required="yes"> 
	<cfset arguments.diagnosis_id= decrypt(#arguments.diagnosis_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />	
	<cfquery name="get_diagnosis_name" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_agency#.Diagnosis WHERE Diagnosis_ID=<cfqueryparam value="#arguments.diagnosis_id#" cfsqltype="cf_sql_integer">
	</cfquery>
	<cfreturn get_diagnosis_name />	
</cffunction>


<cffunction name="Get_Assessment_Details"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="assessment_id" required="yes">	
	<cfargument name="patient_id" required="yes">
	<cfquery name="get_assessment_name" datasource="#Application.DataSrc#">
		select * from #Request.prefix_db_agency#.Assessment_New where Assessment_ID=<cfqueryparam value="#arguments.assessment_id#" cfsqltype="cf_sql_integer"> and Agency_ID=<cfqueryparam value="#session.AgencyID#" cfsqltype="cf_sql_integer"> and Patient_ID=<cfqueryparam value="#arguments.patient_id#" cfsqltype="cf_sql_integer">
	</cfquery>	
	<cfreturn get_assessment_name />	
</cffunction>




<cffunction name="TeachingDiagnoses_list"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="text" required="yes">
	<cfquery name="get_TeachingDiagnoses_list" datasource="#Application.DataSrc#">
		SELECT vt.id  as  Dx_id,vt.Diagnosis,vt.ICD as Dx_ICD,vt.Diagnosis as Dx_Diagnosis, vt.Pathway as Dx_Pathway_ID,
                vt.PDGM as PDGM, vt.Comorbid as Comorbid
                    FROM  #Request.prefix_db_lookup#.vetted_190924 as vt 
                    JOIN  #Request.prefix_db_lookup#.CW_Coding_Class_PDGM  as cw ON  vt.Priority = cw.Priority
                    WHERE (vt.Diagnosis LIKE '%#arguments.text#%' OR vt.ICD LIKE '%#arguments.text#%') 
                    Order by vt.ICD  
        
                  <!--- SELECT vt.id  as  Dx_id,vt.Diagnosis,vt.ICD as Dx_ICD,vt.Diagnosis as Dx_Diagnosis, vt.Pathway as Dx_Pathway_ID,
                vt.PDGM as PDGM, vt.Comorbid as Comorbid
                    FROM  #Request.prefix_db_lookup#.CW_Coding_Class_PDGM  as cw
                    JOIN #Request.prefix_db_lookup#.vetted_190924 as vt ON  vt.Priority = cw.Priority
                    WHERE vt.Pathway = cw.Pathway_ID
                    AND (vt.Diagnosis LIKE '%#arguments.text#%' OR vt.ICD LIKE '%#arguments.text#%') 
                    Order by vt.ICD  --->
    </cfquery>
	<cfreturn get_TeachingDiagnoses_list />
</cffunction>



<cffunction name="Get_Diagnosis_type_based_Details"  access="remote" output="Yes" returnFormat= "JSON"> 	
	<cfargument name="type" required="yes">
	<cfquery name="get_diagnosis_type_details" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_lookup#.Dx_list_Procedures_Diet WHERE Type=<cfqueryparam value="#arguments.type#" cfsqltype="CF_SQL_VARCHAR">
	</cfquery>		
	<cfreturn get_diagnosis_type_details />	
</cffunction>



<cffunction name="Get_Library_type_based_Details"  access="remote" output="Yes" returnFormat= "JSON"> 	
	<cfquery name="get_library_type_details" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE title IS NOT NULL AND Deleted=0 GROUP BY title
	</cfquery>
	<cfreturn get_library_type_details />	
</cffunction>

		<!---							Get list from database	end					--->




<cffunction name="show_Diagnosis_edit"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 	
	<cfargument name="diagnosis_id" required="yes">
	<cfoutput>		
		<cfset arguments.diagnosis_id= decrypt(#arguments.diagnosis_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />			
		<cfset Encrypted_Diagnosis_id= encrypt(#arguments.diagnosis_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />		
	</cfoutput>								   
		<cfif arguments.diagnosis_id  neq 0>
			<cfquery name="Diagnosis_list" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.Diagnosis WHERE Diagnosis_ID=<cfqueryparam value = "#arguments.diagnosis_id#" CFSQLType ="CF_SQL_INTEGER">			
			</cfquery>					
			<cfsavecontent	variable = "html_diagnosis_list"> 			
				<cfoutput>
					<form name="EditDiagnosis_form" id="EditDiagnosis_form_id" action="" method="post">						
						<input type="hidden" name="editDiagnosis_tableID" id="editDiagnosis_table_ID"  value="#Encrypted_Diagnosis_id#"/>						
						<input type="hidden" name="editDiagnosis_PatientID" id="editDiagnosis_Patient_ID"  value="#arguments.patient_id#"/>				
						<input type="hidden" name="editDiagnosis_AssessmentID" id="editDiagnosis_Assessment_ID"  value="#arguments.assessment_id#"/>	
						<input type="hidden" name="editDiagnosis_AssessmentTrackerID" id="editDiagnosis_AssessmentTracker_ID"  value="#arguments.assesment_tracker_id#"/>							
						<div class="row">
							<div class="col-md-3">							
								<div class="form-group">
									<label class="control-label" style="text-align:center;margin-top: 13px;">Diagnosis:</label>			
								</div>	
							</div>
							<div class="col-md-9">
								<div class="form-group">
									<textarea name="Editdiagnosis_name" id="Editdiagnosis_id" type="text" value="" style="width: 100%;" class="form-control">#Diagnosis_list.Diagnosis#</textarea>										
								</div>						
							</div>				
						</div>
						<cfif Diagnosis_list.Pathway_Type eq "">						
							<div class="row">
								<div class="col-md-3">
									<div class="form-group">
										<div class="label-stable">
											<label>Primary?</label>
										</div>
									</div>
								</div>
								<div class="col-md-9">
									<div class="form-group">
										<div class="radio-list">
											<label style="display:unset;"><input type="radio" id="edit_Teach_Primary_yes" name="edit_Teach_Primary_chk" <cfif Diagnosis_list.Primary_Diagnosis eq 1> checked </cfif> value="1"> Yes</label>
											<label style="display:unset;"><input type="radio" id="edit_Teach_Primary_no" name="edit_Teach_Primary_chk" <cfif Diagnosis_list.Primary_Diagnosis eq 0> checked </cfif> value="0"> No</label>
										</div>
									</div>
								</div>			
							</div>						
						</cfif>						
					</form>		
				</cfoutput>	
			</cfsavecontent>	
			<cfreturn html_diagnosis_list />	
		</cfif>	
</cffunction>









<cffunction name="update_Diagnosis_details"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="patient_id" required="yes">
	<cfargument name="assessment_id" required="yes">
	<cfargument name="assessment_tracker_id" required="yes">
	<cfargument name="Diagnosisid" required="yes">
	<cfoutput>
		<cfset arguments.patient_id= decrypt(#arguments.patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
		<cfset arguments.assessment_id= decrypt(#arguments.assessment_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
		<cfset arguments.assessment_tracker_id= decrypt(#arguments.assessment_tracker_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
		<cfset arguments.Diagnosisid= decrypt(#arguments.Diagnosisid#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
	</cfoutput>	
	<cfquery name="Diagnosis_list_check" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_agency#.Diagnosis 
		WHERE 
			Primary_Diagnosis=1 AND Patient_ID=<cfqueryparam value = "#arguments.patient_id#" CFSQLType ="CF_SQL_INTEGER">  AND Assessment_ID=<cfqueryparam value = "#arguments.assessment_id#" CFSQLType ="CF_SQL_INTEGER"> AND Assessment_Tracker_ID=<cfqueryparam value = "#arguments.assessment_tracker_id#" CFSQLType ="CF_SQL_INTEGER"> AND Disabled <> 1 AND Diagnosis_ID <> <cfqueryparam value = "#arguments.Diagnosisid#" CFSQLType ="CF_SQL_INTEGER"> AND Pathway_Type=""	
	</cfquery>
	<cfif arguments.Primary_check eq 1>	
		<cfif Diagnosis_list_check.RecordCount>
			<cfquery  datasource="#Application.DataSrc#" name="update_Diagnosis_old">	
				UPDATE #Request.prefix_db_agency#.Diagnosis SET	
					Primary_Diagnosis = <cfqueryparam value = "0" CFSQLType ="CF_SQL_INTEGER">,
					Record_Mod_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
					Record_Mod_By = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
				WHERE Diagnosis_ID= <cfqueryparam value = "#Diagnosis_list_check.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>
		</cfif>
	</cfif>					
	<cfquery  datasource="#Application.DataSrc#" name="updateDiagnosis">	
		UPDATE #Request.prefix_db_agency#.Diagnosis SET			
			Diagnosis = <cfqueryparam value = "#arguments.Diagnosis_name#" CFSQLType ="CF_SQL_VARCHAR">,
			<cfif arguments.Primary_check neq "">	
				Primary_Diagnosis = <cfqueryparam value = "#arguments.Primary_check#" CFSQLType ="CF_SQL_INTEGER">,
			</cfif>
			Record_Mod_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
			Record_Mod_By = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
		WHERE Diagnosis_ID= <cfqueryparam value = "#arguments.Diagnosisid#" CFSQLType ="CF_SQL_INTEGER">
	</cfquery>
	<cfset Diagnosis_update = "Sucess" />	
	<cfreturn Diagnosis_update />		
</cffunction>



<cffunction name="delete_teachplan"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="patient_id" required="yes">
	<cfargument name="assessment_id" required="yes">
	<cfargument name="diagnosis_id" required="yes">							   
	   <cfif arguments.patient_id  neq 0>			  
		  <cfoutput>
			<cfset arguments.patient_id= decrypt(#arguments.patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
			<cfset arguments.assessment_id= decrypt(#arguments.assessment_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />						
			<cfset arguments.diagnosis_id= decrypt(#arguments.diagnosis_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />					
		  </cfoutput> 
			<cfquery  datasource="#Application.DataSrc#" name="deleteDiagnoses_teach">
				UPDATE #Request.prefix_db_agency#.Diagnosis set Diagnosis.Disabled = '#1#'
					WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.diagnosis_id#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>				
			<cfquery  datasource="#Application.DataSrc#" name="deleteDiagnoses_teach_skill">
                    DELETE FROM #Request.prefix_db_agency#.Teaching_Skills
					WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.diagnosis_id#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>	
                <cfquery  datasource="#Application.DataSrc#" name="deleteDiagnoses_teach_skill">
                     DELETE FROM #Request.prefix_db_agency#.Teaching_Skills_span
					 WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.diagnosis_id#" CFSQLType ="CF_SQL_INTEGER">
                 </cfquery>	
            <cfset delete_id = "Sucess" />						
			<cfreturn delete_id />	
		</cfif>	
</cffunction>

<cffunction name="show_Teachsteps_edit"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 	
	<cfargument name="Teachskillsid" required="yes">								   
		<cfif arguments.Teachskillsid  neq 0>				
			<cfquery name="TeachingSkills_list" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Skills WHERE Teaching_Skills.ID=<cfqueryparam value = "#arguments.Teachskillsid#" CFSQLType ="CF_SQL_INTEGER">			
			</cfquery>
			<cfsavecontent	variable = "html_list"> 			
				<form name="Teach_Skill_form" id="Teach_Skill_form_id" action="" method="post">						
					<input type="hidden" name="editTeach_Skills_ID" id="editTeach_SkillsID"  value="<cfoutput>#arguments.Teachskillsid#</cfoutput>"/>
					<input type="hidden" name="editDiagnosis_ID" id="edit_DiagnosisID"  value="<cfoutput>#TeachingSkills_list.Diagnosis_ID#</cfoutput>"/>
					<input type="hidden" name="edit_pathway_type" id="edit_pathway_type_id"  value="<cfoutput>#arguments.Pathway_Type#</cfoutput>"/>					
					<cfoutput>		
					<!--<div class="row">
						<div class="col-md-3">	
							<div class="form-group">		
								<label class="control-label" style="text-align:center;margin-top: 13px;">Step:</label>	
							</div>
						</div>
						<div class="col-md-3">	
							<div class="form-group">		
								<input type="number" class="form-control" name="step_no_name" id="step_no_id" value="#TeachingSkills_list.Step_ID#" style="">
							</div>	
						</div>	
					</div>-->					
					<div class="row">
						<div class="col-md-3">							
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Explanation:</label>			
							</div>	
						</div>
						<div class="col-md-9">
							<div class="form-group">
								<textarea name="explanation_name" id="explanation_id" type="text" value="" style="width: 100%;height: 185px;" class="form-control">#TeachingSkills_list.Explanation#</textarea>										
							</div>						

						</div>				
					</div>
					</cfoutput>						
					</form>			
			</cfsavecontent>	
			<cfreturn html_list />	
		</cfif>	
</cffunction>





<cffunction name="update_Teachskills"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="Teachskillsid" required="yes">
		<cfquery  datasource="#Application.DataSrc#" name="GetTeachSkills_all">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Skills WHERE ID=<cfqueryparam value = "#arguments.Teachskillsid#" CFSQLType ="CF_SQL_INTEGER"> 
		</cfquery>	
		
		<cfquery  datasource="#Application.DataSrc#" name="TeachSkills_Check">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Skills 
				WHERE Diagnosis_ID=<cfqueryparam value = "#GetTeachSkills_all.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER"> AND ID <> <cfqueryparam value = "#arguments.Teachskillsid#" CFSQLType ="CF_SQL_INTEGER">  AND <!---Step_ID=<cfqueryparam value = "#arguments.step_field#" CFSQLType ="CF_SQL_INTEGER"> AND---> Pathway_Type=<cfqueryparam value = "#arguments.Pathway_Type#" CFSQLType ="CF_SQL_VARCHAR"> LIMIT 1
		</cfquery>
		<cfif TeachSkills_Check.RecordCount eq 0>
			<cfquery  name="editTeachskill_update" datasource="#Application.DataSrc#">
				UPDATE #Request.prefix_db_agency#.Teaching_Skills SET
					<!---Step_ID = <cfqueryparam value = "#arguments.step_field#" CFSQLType ="CF_SQL_INTEGER">,	--->							
					Explanation = <cfqueryparam value = "#arguments.explanation_field#" CFSQLType ="CF_SQL_VARCHAR">,				
					Created_Date = <cfqueryparam value="#GetTeachSkills_all.Created_Date#" cfsqltype="cf_sql_date">,
					Created_by = <cfqueryparam value = "#GetTeachSkills_all.Created_by#" CFSQLType ="CF_SQL_INTEGER">,
					Updated_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
					Updated_by = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
				WHERE ID= <cfqueryparam value = "#arguments.Teachskillsid#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>
			<cfset teachskill_update = "Sucess" />	
		<cfelse>					
			<cfquery  name="Teachskill_old_update_step" datasource="#Application.DataSrc#">
				UPDATE #Request.prefix_db_agency#.Teaching_Skills SET
					<!---<cfif #GetTeachSkills_all.Step_ID# eq ''>
						Step_ID = <cfqueryparam value = "#GetTeachSkills_all.Step_ID#" null="#GetTeachSkills_all.Step_ID eq ""#" CFSQLType ="CF_SQL_INTEGER">,	
					<cfelse>
						Step_ID = <cfqueryparam value = "#GetTeachSkills_all.Step_ID#" CFSQLType ="CF_SQL_INTEGER">,	
					</cfif>		--->										
					Created_Date = <cfqueryparam value="#TeachSkills_Check.Created_Date#" cfsqltype="cf_sql_date">,
					Created_by = <cfqueryparam value = "#TeachSkills_Check.Created_by#" CFSQLType ="CF_SQL_INTEGER">,
					Updated_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
					Updated_by = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
				WHERE ID= <cfqueryparam value = "#TeachSkills_Check.ID#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>	
			<cfquery  name="Teachskill_new_update_step" datasource="#Application.DataSrc#">
				UPDATE #Request.prefix_db_agency#.Teaching_Skills SET
					<!---Step_ID = <cfqueryparam value = "#arguments.step_field#" CFSQLType ="CF_SQL_INTEGER">,		--->						
					Explanation = <cfqueryparam value = "#arguments.explanation_field#" CFSQLType ="CF_SQL_VARCHAR">,				
					Created_Date = <cfqueryparam value="#GetTeachSkills_all.Created_Date#" cfsqltype="cf_sql_date">,
					Created_by = <cfqueryparam value = "#GetTeachSkills_all.Created_by#" CFSQLType ="CF_SQL_INTEGER">,
					Updated_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
					Updated_by = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
				WHERE ID= <cfqueryparam value = "#arguments.Teachskillsid#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>					
			<cfset teachskill_update = "Sucess" />	
		</cfif>		
		<cfreturn teachskill_update />
</cffunction>

<cffunction name="delete_teachSkills"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="teachSkill_table_id" required="yes">							   
	   <cfif arguments.teachSkill_table_id  neq 0 and arguments.teachSkill_table_id neq ''>	 
			<cfquery  datasource="#Application.DataSrc#" name="GetTeachSkills_all">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Skills WHERE ID=<cfqueryparam value = "#arguments.teachSkill_table_id#" CFSQLType ="CF_SQL_INTEGER"> 
			</cfquery>	
			<cfif arguments.IdentityofRow eq 0>
				<cfoutput query="GetTeachSkills_all"> 								
					<cfquery  datasource="#Application.DataSrc#" name="delete_teach_skill_all">
						UPDATE 
							#Request.prefix_db_agency#.Teaching_Skills 
						SET 
							Teaching_Skills.Deleted = '#1#'
						WHERE  
							Diagnosis_ID=<cfqueryparam value = "#GetTeachSkills_all.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER"> 
							AND Patient_ID=<cfqueryparam value = "#GetTeachSkills_all.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
							AND Assessment_ID=<cfqueryparam value = "#GetTeachSkills_all.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER">
							AND Pathway_ID=<cfqueryparam value = "#GetTeachSkills_all.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER">
					</cfquery>
				</cfoutput>
			<cfelse>
				<cfquery  datasource="#Application.DataSrc#" name="delete_teach_skill">
					UPDATE #Request.prefix_db_agency#.Teaching_Skills set Teaching_Skills.Deleted = '#1#'
						WHERE  ID=<cfqueryparam value = "#arguments.teachSkill_table_id#" CFSQLType ="CF_SQL_INTEGER">
				</cfquery>	
			</cfif>				
			<cfset delete_id = "Sucess" />						
			<cfreturn delete_id />
		</cfif>	
</cffunction>


<cffunction name="Teachplan_Type_based_insert"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="Patient_id" required="yes">
	<cfargument name="Assessment_id" required="yes">
	<cfargument name="Procedures_Diet_id" required="yes">
		<cfoutput>
			<cfset arguments.Patient_id= decrypt(#arguments.Patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
			<cfset arguments.Assessment_id= decrypt(#arguments.Assessment_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
			<cfset arguments.Procedures_Diet_id= decrypt(#arguments.Procedures_Diet_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />			
		</cfoutput>										   
	   <cfif arguments.Patient_id  neq ''>
			<cfquery  datasource="#Application.DataSrc#" name="find_DME_supplies_list">
				SELECT * FROM #Request.prefix_db_lookup#.Dx_list_Procedures_Diet WHERE  ID=<cfqueryparam value = "#arguments.Procedures_Diet_id#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>	
			<cfquery  datasource="#Application.DataSrc#" name="get_Assessment_TrackerID">
				SELECT * FROM #Request.prefix_db_agency#.Assessment_New WHERE  Assessment_ID=<cfqueryparam value = "#arguments.Assessment_id#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>	
			<cfquery  datasource="#Application.DataSrc#" name="DME_Diet_type_check">
				SELECT * FROM #Request.prefix_db_agency#.Diagnosis WHERE  Patient_ID=<cfqueryparam value = "#arguments.Patient_id#" CFSQLType ="CF_SQL_INTEGER"> AND Assessment_ID=<cfqueryparam value = "#arguments.Assessment_id#" CFSQLType ="CF_SQL_INTEGER"> AND Assessment_Tracker_ID=<cfqueryparam value = "#get_Assessment_TrackerID.Assessment_Tracker_ID#" CFSQLType ="CF_SQL_INTEGER"> AND ICD=<cfqueryparam value="#find_DME_supplies_list.3Digit#" cfsqltype="CF_SQL_VARCHAR"> AND Disabled=0
			</cfquery>			
			<cfquery name="Get_Teach_diagnoses_order" datasource="#Application.DataSrc#">
					SELECT  MAX(Dx_Order) as diagnosis_order FROM #Request.prefix_db_agency#.Diagnosis WHERE Patient_ID=<cfqueryparam value="#arguments.Patient_id#" cfsqltype="cf_sql_integer"> AND Assessment_ID=<cfqueryparam value="#arguments.Assessment_id#" cfsqltype="cf_sql_integer"> AND Disabled=0 AND Assessment_Tracker_ID=<cfqueryparam value="#get_Assessment_TrackerID.Assessment_Tracker_ID#" cfsqltype="cf_sql_integer"> <!---<cfif #find_DME_supplies_list.Type# eq 'DME/supplies'> AND Pathway_Type='DME/supplies' <cfelseif #find_DME_supplies_list.Type# eq 'diet'> AND Pathway_Type='diet' </cfif>--->
			</cfquery>			
			<cfif DME_Diet_type_check.RecordCount>
				<cfset insert_action_fail="Failed" />	
				<cfreturn insert_action_fail />											
			<cfelse>
				<cfif Get_Teach_diagnoses_order.diagnosis_order eq 0 or Get_Teach_diagnoses_order.diagnosis_order eq ''>
					<cfset Diagnosis_Dx_order_count = "1">
				<cfelse>
					<cfset Diagnosis_Dx_order_count = Get_Teach_diagnoses_order.diagnosis_order+1>
				</cfif>
				<cfquery  datasource="#Application.DataSrc#" name="insertDiagnoses_teach">	
					INSERT INTO #Request.prefix_db_agency#.Diagnosis
					(
						Assessment_ID, Assessment_Tracker_ID, Patient_ID, Agency_ID, Diagnosis, ICD, Pathway_Type, Record_Creation_Date,  Record_Created_By, Record_Mod_Date, Record_Mod_By, Dx_Order
					) 
					VALUES
					(							
						<cfqueryparam value="#arguments.Assessment_id#" cfsqltype="CF_SQL_INTEGER">,							
						<cfqueryparam value="#get_Assessment_TrackerID.Assessment_Tracker_ID#" cfsqltype="CF_SQL_INTEGER">,							
						<cfqueryparam value="#arguments.Patient_id#" cfsqltype="CF_SQL_INTEGER">,
						<cfqueryparam value="#arguments.AgencyID#" cfsqltype="CF_SQL_INTEGER">,
						<cfqueryparam value="#find_DME_supplies_list.Diagnosis#" cfsqltype="CF_SQL_VARCHAR">,
						<cfqueryparam value="#find_DME_supplies_list.3Digit#" cfsqltype="CF_SQL_VARCHAR">,	
						<cfqueryparam value="#find_DME_supplies_list.Type#" cfsqltype="CF_SQL_VARCHAR">,	
						<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
						<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
						<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
						<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
						<cfqueryparam value ="#Diagnosis_Dx_order_count#" CFSQLType ="CF_SQL_INTEGER">							
					)
				</cfquery>
				<cfset Diagnosis_Dx_order_count = "0">			
				<cfquery name="last_insert_diagnoses_id_agency" datasource="#Application.DataSrc#">
					SELECT LAST_INSERT_ID() as diagnoses_id_agency
				</cfquery>	
				<cfquery name="select_Teach_Combo" datasource="#Application.DataSrc#">
					SELECT * FROM #Request.prefix_db_lookup#.vetted_190924	WHERE ICD=<cfqueryparam value="#find_DME_supplies_list.3Digit#" cfsqltype="CF_SQL_VARCHAR">  
                     AND Pathway IS NOT NULL GROUP BY  Pathway
				</cfquery>	
				<cfloop query="select_Teach_Combo">	
					<cfquery name="select_Teach_Prevention" datasource="#Application.DataSrc#">
						SELECT * FROM #Request.prefix_db_lookup#.Teaching_Prevention WHERE Pathway_ID=<cfqueryparam value="#select_Teach_Combo.Pathway#" cfsqltype="CF_SQL_INTEGER">  
					</cfquery>	
					<cfset teching_skill_order ="0">
					<cfset teching_skill_title_order_id_dme ="0">
					<cfoutput query="select_Teach_Prevention">						
						<cfset teching_skill_order =teching_skill_order+1>
						<cfset teching_skill_title_order_id_dme =teching_skill_title_order_id_dme+1>										
						<cfquery  datasource="#Application.DataSrc#" name="insert_Teaching_Skills">
							INSERT INTO #Request.prefix_db_agency#.Teaching_Skills 
							(
								Patient_ID, Assessment_ID, ICD, 3Digit, Pathway_Type, Pathway_ID, <cfif #select_Teach_Prevention.Step_ID# neq ''> Step_ID,</cfif> <cfif #select_Teach_Prevention.Line_ID# neq ''> Line_ID, </cfif> Explanation, Created_Date, Created_by, Updated_Date, Updated_by, Diagnosis_ID, Order_ID, Title_Order_ID
							)
							VALUES 
							(								
								<cfqueryparam value="#arguments.Patient_id#" cfsqltype="CF_SQL_INTEGER">,
								<cfqueryparam value="#arguments.Assessment_id#" cfsqltype="CF_SQL_INTEGER">,
								<cfqueryparam value = "#select_Teach_Combo.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
								<cfqueryparam value = "#select_Teach_Combo.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
								<cfqueryparam value = "#select_Teach_Prevention.Type#" CFSQLType ="CF_SQL_VARCHAR">,
								<cfqueryparam value="#select_Teach_Prevention.Pathway_ID#" cfsqltype="CF_SQL_INTEGER">,									
								<cfif #select_Teach_Prevention.Step_ID# neq ''>		
									<cfqueryparam value = "#select_Teach_Prevention.Step_ID#" CFSQLType ="CF_SQL_INTEGER">,		
								</cfif>						
								<cfif #select_Teach_Prevention.Line_ID# neq ''>		
									<cfqueryparam value = "#select_Teach_Prevention.Line_ID#" CFSQLType ="CF_SQL_INTEGER">,
								</cfif>		
								<cfqueryparam value = "#select_Teach_Prevention.Explanation#" CFSQLType ="CF_SQL_VARCHAR">,								
								<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
								<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
								<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value = "#last_insert_diagnoses_id_agency.diagnoses_id_agency#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value = "#teching_skill_order#" CFSQLType ="CF_SQL_INTEGER">	,
								<cfqueryparam value = "#teching_skill_title_order_id_dme#" CFSQLType ="CF_SQL_INTEGER">											
							)	
						</cfquery>								
					</cfoutput>												
				</cfloop>					
				<cfset teching_skill_order ="0">	
				<cfset teching_skill_title_order_id_dme ="0">			
				<cfset sucess_function="Sucess">
				<cfreturn sucess_function />
			</cfif>								
		</cfif>	
</cffunction>

<cffunction name="Symptoms_Order_change_update"  access="remote" output="Yes" returnFormat= "JSON"> 	
	<cfargument name="Skills_IDS" required="yes">	
	<cfif arguments.Skills_IDS  neq ''>	 
		<cfoutput>
			<cfset Skill_ID_STring = "#arguments.Skills_IDS#">	
			<cfset Array_Skill_ID = Skill_ID_STring.Split(",")>
		</cfoutput> 
		<cfset teachskills_order_count="0">	
			<cfloop array="#Array_Skill_ID#" index="idx">	
				<cfset teachskills_order_count = teachskills_order_count+1>				
				<!---<cfif ArrayLen(Array_Skill_ID) lt teachskills_order_count>
					<cfset teachskills_order_count="0">	
				<cfelse>
					<cfset teachskills_order_count="1">	
				</cfif>--->				
			   	<cfquery  datasource="#Application.DataSrc#" name="update_teach_skill">
					UPDATE #Request.prefix_db_agency#.Teaching_Skills set Teaching_Skills.Order_ID = '#teachskills_order_count#'
					WHERE ID=<cfqueryparam value = "#idx#" CFSQLType ="CF_SQL_INTEGER">
				</cfquery>			   
			</cfloop>				
		<cfset teachskills_order_count="0">				
	</cfif>	
	<cfset sucess = "Sucess" />
	<cfreturn sucess />		
</cffunction>

<cffunction name="Symptoms_Order_change_update_new"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="Skills_IDS" required="yes">
	<cfargument name="Table_type" required="yes">
	<cfif arguments.Skills_IDS  neq ''>	 		
		<cfoutput>
			<cfset Skill_ID_STring = "#arguments.Skills_IDS#">	
			<cfset Array_Skill_ID = Skill_ID_STring.Split(",")>
		</cfoutput> 			
		<cfif arguments.Table_type eq 'Teach_Table_sub'>
			<cfset teachskills_Title_order_count=0 />					
			<cfloop array="#Array_Skill_ID#" index="idx">	
				<cfset teachskills_Title_order_count = teachskills_Title_order_count+1 />															
			   	<!---<cfquery  datasource="#Application.DataSrc#" name="update_teach_skill">
					UPDATE #Request.prefix_db_agency#.Teaching_Skills set Teaching_Skills.Title_Order_ID = '#teachskills_Title_order_count#'
						WHERE ID=<cfqueryparam value = "#idx#" CFSQLType ="CF_SQL_INTEGER">
				</cfquery>--->	
				<cfquery name="select_Teach_skills" datasource="#Application.DataSrc#">
					SELECT * FROM #Request.prefix_db_agency#.Teaching_Skills WHERE ID=<cfqueryparam value = "#idx#" CFSQLType ="CF_SQL_INTEGER">
				</cfquery>				
				<cfoutput query="select_Teach_skills">
					<cfquery  datasource="#Application.DataSrc#" name="Multiple_update_teach_1">
						UPDATE 
							#Request.prefix_db_agency#.Teaching_Skills 
						SET 
							Teaching_Skills.Title_Order_ID = '#teachskills_Title_order_count#'
						WHERE 
							ID=<cfqueryparam value = "#select_Teach_skills.ID#" CFSQLType ="CF_SQL_INTEGER">							
					</cfquery>	
					<cfquery  datasource="#Application.DataSrc#" name="Multiple_update_teach_skill">
						UPDATE 
							#Request.prefix_db_agency#.Teaching_Skills 
						SET 
							Teaching_Skills.Title_Order_ID = '#teachskills_Title_order_count#'
						WHERE 
							Pathway_ID=<cfqueryparam value = "#select_Teach_skills.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER"> 
							AND Patient_ID=<cfqueryparam value = "#select_Teach_skills.Patient_ID#" CFSQLType ="CF_SQL_INTEGER">
							AND Assessment_ID=<cfqueryparam value = "#select_Teach_skills.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER">
							AND ICD=<cfqueryparam value = "#select_Teach_skills.ICD#" CFSQLType ="CF_SQL_VARCHAR">
							AND Deleted=0
							<cfif select_Teach_skills.Step_ID eq 129 and select_Teach_skills.Line_ID eq 0> 
								AND Pathway_Type='Teaching' 
							<cfelseif select_Teach_skills.Step_ID eq 0 and select_Teach_skills.Line_ID eq 0>
								AND Pathway_Type='symptom' 
							</cfif>
					</cfquery>				
				</cfoutput>						   
			</cfloop>				
			<cfset teachskills_Title_order_count="0">			
		<cfelseif arguments.Table_type eq 'Multiple_Explanation_table'>		
			<cfset teachskills_order_count="0">					
			<cfloop array="#Array_Skill_ID#" index="idx">	
				<cfset teachskills_order_count = teachskills_order_count+1>											
			   	<cfquery  datasource="#Application.DataSrc#" name="update_teach_skill">
					UPDATE #Request.prefix_db_agency#.Teaching_Skills 
					SET 
						Teaching_Skills.Order_ID = '#teachskills_order_count#'
					WHERE 
						ID=<cfqueryparam value = "#idx#" CFSQLType ="CF_SQL_INTEGER">
				</cfquery>			   
			</cfloop>				
			<cfset teachskills_order_count="0">			
		</cfif>				
	</cfif>	
	<cfset sucess = "Sucess" />
	<cfreturn sucess />		
</cffunction>


<cffunction name="Diagnosis_Order_change_update"  access="remote" output="Yes" returnFormat= "JSON"> 	
	<cfargument name="Diagnosis_IDS" required="yes">
	<cfif arguments.Diagnosis_IDS  neq ''>	 
		<cfoutput>
			<cfset Diagnosis_ID_STring = "#arguments.Diagnosis_IDS#">	
			<cfset Array_Diagnosis_ID = Diagnosis_ID_STring.Split(",")>
		</cfoutput> 
		<cfset teach_Diagnosis_order_count="0">	
			<cfloop array="#Array_Diagnosis_ID#" index="idx">	
				<cfset teach_Diagnosis_order_count = teach_Diagnosis_order_count+1>		
			   	<cfquery  datasource="#Application.DataSrc#" name="update_teach_skill">
					UPDATE #Request.prefix_db_agency#.Diagnosis set Diagnosis.Dx_Order = '#teach_Diagnosis_order_count#'
						WHERE Diagnosis_ID=<cfqueryparam value = "#idx#" CFSQLType ="CF_SQL_INTEGER">
				</cfquery>			   
			</cfloop>	
		<cfset teach_Diagnosis_order_count="0">
	</cfif>	
	<cfset sucess = "Sucess" />
	<cfreturn sucess />		
</cffunction>



<cffunction name="Add_item_teaching_insert"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 	
	<cfargument name="Diagnosis_IDS" required="yes">
	   <cfif arguments.Diagnosis_IDS  neq 0 and arguments.Diagnosis_IDS neq ''>	
	   		<cfquery  datasource="#Application.DataSrc#" name="Find_diagnosis_data">
				SELECT * FROM #Request.prefix_db_agency#.Diagnosis WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.Diagnosis_IDS#" CFSQLType ="CF_SQL_INTEGER">
				AND  Diagnosis.Disabled = 0 
			</cfquery>			
			<cfquery  datasource="#Application.DataSrc#" name="Find_skill_order_data">
				SELECT max(Order_ID) as maximun_order FROM #Request.prefix_db_agency#.Teaching_Skills WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.Diagnosis_IDS#" CFSQLType ="CF_SQL_INTEGER"> AND Patient_ID=<cfqueryparam value = "#Find_diagnosis_data.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> AND Assessment_ID=<cfqueryparam value = "#Find_diagnosis_data.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> AND ICD=<cfqueryparam value = "#Find_diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR"> AND Deleted=0
			</cfquery>
			<cfset Order_count_for_skill=#Find_skill_order_data.maximun_order#+1>						
			<cfquery  datasource="#Application.DataSrc#" name="insert_Teaching_Skills">
				INSERT INTO #Request.prefix_db_agency#.Teaching_Skills 
				(
					Patient_ID, Assessment_ID, ICD, 3Digit, Pathway_Type, Explanation, Created_Date, Created_by, Updated_Date, Updated_by, Diagnosis_ID, Order_ID
				)
				VALUES 
				(								
					<cfqueryparam value="#Find_diagnosis_data.Patient_ID#" cfsqltype="CF_SQL_INTEGER">,
					<cfqueryparam value="#Find_diagnosis_data.Assessment_ID#" cfsqltype="CF_SQL_INTEGER">,
					<cfqueryparam value = "#Find_diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
					<cfqueryparam value = "#Find_diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
					<cfqueryparam value = "teaching" CFSQLType ="CF_SQL_VARCHAR">,
					<cfqueryparam value="#arguments.explanation#" cfsqltype="CF_SQL_VARCHAR">,											
					<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
					<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
					<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value = "#arguments.Diagnosis_IDS#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value = "#Order_count_for_skill#" CFSQLType ="CF_SQL_INTEGER">												
				)	
			</cfquery>									
			<cfset sucess_id = "Sucess" />						
			<cfreturn sucess_id />				
		</cfif>	
</cffunction>


<cffunction name="TeachSkills_Type_item_insert"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 	
	<cfargument name="DiagnosisID" required="yes">				   
	   <cfif arguments.DiagnosisID  neq 0 and arguments.DiagnosisID neq ''>	 	   
	   		<cfquery  datasource="#Application.DataSrc#" name="Find_diagnosis_data">
				SELECT * FROM #Request.prefix_db_agency#.Diagnosis WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.DiagnosisID#" CFSQLType ="CF_SQL_INTEGER">
				AND  Diagnosis.Disabled = 0 
			</cfquery>	
			<cfquery  datasource="#Application.DataSrc#" name="Find_skill_order_data">
				SELECT max(Order_ID) as maximun_order FROM #Request.prefix_db_agency#.Teaching_Skills 
				WHERE  
					Diagnosis_ID=<cfqueryparam value = "#arguments.DiagnosisID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND Patient_ID=<cfqueryparam value = "#Find_diagnosis_data.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND Assessment_ID=<cfqueryparam value = "#Find_diagnosis_data.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND ICD=<cfqueryparam value = "#Find_diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
					AND Deleted=0
			</cfquery>	
			<cfquery  datasource="#Application.DataSrc#" name="Find_skill_all_data">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Skills 
				WHERE  
					Diagnosis_ID=<cfqueryparam value = "#arguments.DiagnosisID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND Patient_ID=<cfqueryparam value = "#Find_diagnosis_data.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND Assessment_ID=<cfqueryparam value = "#Find_diagnosis_data.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND ICD=<cfqueryparam value = "#Find_diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
					AND Deleted=0 
					AND <cfif #arguments.PathwayID# neq ''> Pathway_ID=<cfqueryparam value = "#arguments.PathwayID#" CFSQLType ="CF_SQL_INTEGER"> <cfelse> Pathway_ID IS NULL  </cfif>
					<!---AND Pathway_Type NOT LIKE 'Title%'---> 
					AND Pathway_Type NOT LIKE 'goal%' 
					AND Pathway_Type NOT LIKE 'intervention%' 
					AND Pathway_Type NOT LIKE 'Source%' 
					ORDER BY Step_ID DESC LIMIT 1
			</cfquery>	
						
			<cfif #arguments.Pathway_Type# neq "">
				<cfset Path_Way_Type = #arguments.Pathway_Type#/>	
			<cfelse>
				<cfset Path_Way_Type = "Teaching"/>
			</cfif>
			<cfif Find_skill_all_data.RecordCount>
				<!---<cfset Path_Way_Type = #Find_skill_all_data.Pathway_Type#/>		--->			
				<cfif #Find_skill_all_data.Step_ID# eq ''>
					<cfset Step_ID_data = "1"/>	
				<cfelse>
					<cfset Step_ID_data = #Find_skill_all_data.Step_ID#+1/>	
				</cfif>																
			<cfelse>
				<!---<cfset Path_Way_Type = "Teaching"/>--->	
				<cfset Step_ID_data = "1"/>
			</cfif>
			<cfset Order_count_for_skill=#Find_skill_order_data.maximun_order#+1>						
			<cfquery  datasource="#Application.DataSrc#" name="insert_Teaching_Skills">
				INSERT INTO #Request.prefix_db_agency#.Teaching_Skills 
				(
					Patient_ID, Assessment_ID, ICD, 3Digit, Pathway_Type, <cfif #arguments.PathwayID# neq ''>Pathway_ID,</cfif> Step_ID, Line_ID, Explanation, Created_Date, Created_by, Updated_Date, Updated_by, Diagnosis_ID, Order_ID
				)
				VALUES 
				(								
					<cfqueryparam value="#Find_diagnosis_data.Patient_ID#" cfsqltype="CF_SQL_INTEGER">,
					<cfqueryparam value="#Find_diagnosis_data.Assessment_ID#" cfsqltype="CF_SQL_INTEGER">,
					<cfqueryparam value = "#Find_diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
					<cfqueryparam value = "#Left(Find_diagnosis_data.ICD,3)#" CFSQLType ="CF_SQL_VARCHAR">,
					<cfqueryparam value = "#Path_Way_Type#" CFSQLType ="CF_SQL_VARCHAR">,
					<cfif #arguments.PathwayID# neq ''>
						<cfqueryparam value ="#arguments.PathwayID#" CFSQLType ="CF_SQL_INTEGER">,
					</cfif>
					<cfqueryparam value ="#Step_ID_data#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value ="1" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value="#arguments.explanation#" cfsqltype="CF_SQL_VARCHAR">,											
					<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
					<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
					<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value = "#arguments.DiagnosisID#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value = "#Order_count_for_skill#" CFSQLType ="CF_SQL_INTEGER">												
				)	
			</cfquery>	
			<cfset sucess_id = "Sucess" />						
			<cfreturn sucess_id />				
		</cfif>	
</cffunction>


<cffunction name="Add_library_teaching_insert"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="Diagnosis_IDS" required="yes" hint="Diagnosis_IDS" > 
		<cfoutput>
			<cfset arguments.Diagnosis_IDS= decrypt(#arguments.Diagnosis_IDS#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />			
		</cfoutput>							   
	   <cfif arguments.Diagnosis_IDS  neq 0 and arguments.Diagnosis_IDS neq ''>		   
	   		<cfquery  datasource="#Application.DataSrc#" name="Find_diagnosis_data">
				SELECT * FROM #Request.prefix_db_agency#.Diagnosis WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.Diagnosis_IDS#" CFSQLType ="CF_SQL_INTEGER">
				AND  Diagnosis.Disabled = 0 
			</cfquery>
			<cfquery  datasource="#Application.DataSrc#" name="Find_skill_order_data">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Skills 
                WHERE  Diagnosis_ID=<cfqueryparam value = "#arguments.Diagnosis_IDS#" CFSQLType ="CF_SQL_INTEGER"> 
                AND Patient_ID=<cfqueryparam value = "#Find_diagnosis_data.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
                AND Assessment_ID=<cfqueryparam value = "#Find_diagnosis_data.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> 
                AND ICD=<cfqueryparam value = "#Find_diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
                AND Deleted=0
			</cfquery>	
			<!---<cfquery  datasource="#Application.DataSrc#" name="Get_Library_data_chk">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE  Pathway_Type=<cfqueryparam value = "#arguments.library_type#" CFSQLType ="CF_SQL_VARCHAR"> AND Deleted=0
			</cfquery>--->			
			<cfquery  datasource="#Application.DataSrc#" name="Get_Library_ICD">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE  ICD=<cfqueryparam value = "#Find_diagnosis_data.ICD#" CFSQLType ="CF_SQL_VARCHAR"> AND Deleted=0
			</cfquery>			
			<cfif Get_Library_ICD.RecordCount>			
				<cfset update_return="">			
				<cfoutput>				
					<cfloop query="Find_skill_order_data">				
						<cfset Skill_diagnisis_name = #Find_skill_order_data.Explanation#>					
						<cfloop query="Get_Library_ICD">						
							<cfset Library_diagnisis_name = #Get_Library_ICD.Explanation#>						
							<cfif Get_Library_ICD.Teaching_Skills_ID eq Find_skill_order_data.ID>						
								<cfif Library_diagnisis_name neq Skill_diagnisis_name>	
									<cfset update_return="update">							
									<cfquery  datasource="#Application.DataSrc#" name="update_teach_library">
										UPDATE #Request.prefix_db_agency#.Teaching_Library set Explanation = '#Skill_diagnisis_name#'
										WHERE ID=<cfqueryparam value = "#Get_Library_ICD.ID#" CFSQLType ="CF_SQL_INTEGER">
									</cfquery>	
								</cfif>						
							</cfif>					
						</cfloop>
					</cfloop>	
				<cfif Get_Library_ICD.RecordCount lt Find_skill_order_data.RecordCount>						
					<cfset Skill_data_ids = ArrayNew(1)>
					<cfloop query="Find_skill_order_data">
						<cfset ArrayAppend(Skill_data_ids, #Find_skill_order_data.ID#)>
					</cfloop>				
					<cfloop query="Get_Library_ICD">
						<cfif ArrayContains(Skill_data_ids,#Get_Library_ICD.Teaching_Skills_ID#)>
							<cfscript>
								ArrayDelete(Skill_data_ids,#Get_Library_ICD.Teaching_Skills_ID#);
							</cfscript>
					   </cfif>	
					</cfloop>	
					<cfloop from="1" to="#arrayLen(Skill_data_ids)#" index="i">
					  <cfset data = Skill_data_ids[i]>					   
					   <cfquery  datasource="#Application.DataSrc#" name="Get_skillList">
							SELECT * FROM #Request.prefix_db_agency#.Teaching_Skills WHERE  ID=<cfqueryparam value = "#data#" CFSQLType ="CF_SQL_INTEGER">
						</cfquery>	
						<cfset update_return="update">		
						<cfquery  datasource="#Application.DataSrc#" name="update_Library">
							INSERT INTO #Request.prefix_db_agency#.Teaching_Library 
							(
								ICD, Three_Digit, Pathway_Type, <cfif #Get_skillList.Pathway_ID# neq ''> Pathway_ID,</cfif> <cfif #Get_skillList.Step_ID# neq ''> Step_ID,</cfif> <cfif #Get_skillList.Line_ID# neq ''> Line_ID, </cfif>  Explanation, Created_Date, Created_by, Updated_Date, Updated_by, Teaching_Skills_ID, Diagnosis_ID ,title<cfif #Get_skillList.Title_Order_ID# neq ''>, Title_Order_ID </cfif><cfif #Get_skillList.Order_ID# neq ''>, Order_ID</cfif> 
							)
							VALUES 
							(							
								<cfqueryparam value = "#Get_skillList.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
								<cfqueryparam value = "#Get_skillList.3Digit#" CFSQLType ="CF_SQL_VARCHAR">,
								<cfqueryparam value = "#Get_skillList.Pathway_Type#" CFSQLType ="CF_SQL_VARCHAR">,
								<cfif #Get_skillList.Pathway_ID# neq ''>		
									<cfqueryparam value = "#Get_skillList.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER">,		
								</cfif>					
								<cfif #Get_skillList.Step_ID# neq ''>		
									<cfqueryparam value = "#Get_skillList.Step_ID#" CFSQLType ="CF_SQL_INTEGER">,		
								</cfif>						
								<cfif #Get_skillList.Line_ID# neq ''>		
									<cfqueryparam value = "#Get_skillList.Line_ID#" CFSQLType ="CF_SQL_INTEGER">,
								</cfif>							
								<cfqueryparam value="#Get_skillList.Explanation#" cfsqltype="CF_SQL_VARCHAR">,	
								<cfqueryparam value="#now()#"  cfsqltype="cf_sql_timestamp">,
								<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value = "#now()#"  cfsqltype="cf_sql_timestamp">,
								<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value = "#Get_skillList.ID#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value = "#Get_skillList.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value = "#Get_Library_ICD.title#" CFSQLType ="CF_SQL_VARCHAR">	
								<cfif #Get_skillList.Title_Order_ID# neq ''>		
									,<cfqueryparam value = "#Get_skillList.Title_Order_ID#" CFSQLType ="CF_SQL_INTEGER">		
								</cfif>									                       
								<cfif #Get_skillList.Order_ID# neq ''>		
									,<cfqueryparam value = "#Get_skillList.Order_ID#" CFSQLType ="CF_SQL_INTEGER">		
								</cfif>																		
							)	
						</cfquery>						
					</cfloop>	
				</cfif>
				</cfoutput>				
				<cfif update_return eq ''>
					<cfset insert_action_fail="Failed" />
				<cfelse>
					<cfset insert_action_fail="Update" />
				</cfif>				
				<cfreturn insert_action_fail />											
			<cfelse>		
				<cfoutput query="Find_skill_order_data">
					<cfif 	Find_skill_order_data.Pathway_ID neq ''>
						<cfquery  datasource="#Application.DataSrc#" name="get_pathway_title">
							 SELECT * FROM  #Request.prefix_db_lookup#.pathway_list 
							 WHERE Pathway_ID = <cfqueryparam value = "#Find_skill_order_data.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER">
						 </cfquery>    
					</cfif>
					<cfquery  datasource="#Application.DataSrc#" name="insert_Teaching_Skills">
						INSERT INTO #Request.prefix_db_agency#.Teaching_Library 
						(
							ICD, Three_Digit, Pathway_Type, <cfif #Find_skill_order_data.Pathway_ID# neq ''> Pathway_ID,</cfif> <cfif #Find_skill_order_data.Step_ID# neq ''> Step_ID,</cfif> <cfif #Find_skill_order_data.Line_ID# neq ''> Line_ID, </cfif>  Explanation, Created_Date, Created_by, Updated_Date, Updated_by, Teaching_Skills_ID, Diagnosis_ID <!---<cfif get_pathway_title.RecordCount>--->,title <!---</cfif>---> <cfif #Find_skill_order_data.Title_Order_ID# neq ''>, Title_Order_ID </cfif>
                             <cfif #Find_skill_order_data.Order_ID# neq ''>, Order_ID</cfif> 
						)
						VALUES 
						(							
							<cfqueryparam value = "#Find_skill_order_data.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
							<cfqueryparam value = "#Find_skill_order_data.3Digit#" CFSQLType ="CF_SQL_VARCHAR">,
							<cfqueryparam value = "#Find_skill_order_data.Pathway_Type#" CFSQLType ="CF_SQL_VARCHAR">,
							<cfif #Find_skill_order_data.Pathway_ID# neq ''>		
								<cfqueryparam value = "#Find_skill_order_data.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER">,		
							</cfif>					
							<cfif #Find_skill_order_data.Step_ID# neq ''>		
								<cfqueryparam value = "#Find_skill_order_data.Step_ID#" CFSQLType ="CF_SQL_INTEGER">,		
							</cfif>						
							<cfif #Find_skill_order_data.Line_ID# neq ''>		
								<cfqueryparam value = "#Find_skill_order_data.Line_ID#" CFSQLType ="CF_SQL_INTEGER">,
							</cfif>							
							<cfqueryparam value="#Find_skill_order_data.Explanation#" cfsqltype="CF_SQL_VARCHAR">,	
							<cfqueryparam value="#now()#"  cfsqltype="cf_sql_timestamp">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value = "#now()#"  cfsqltype="cf_sql_timestamp">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value = "#Find_skill_order_data.ID#" CFSQLType ="CF_SQL_INTEGER">,
                            <cfqueryparam value = "#arguments.Diagnosis_IDS#" CFSQLType ="CF_SQL_INTEGER">
							<!---<cfif get_pathway_title.RecordCount>--->
								,<cfqueryparam value = "#Find_diagnosis_data.Diagnosis#" CFSQLType ="CF_SQL_VARCHAR">	
							<!---</cfif>	    --->     
							<cfif #Find_skill_order_data.Title_Order_ID# neq ''>		
								,<cfqueryparam value = "#Find_skill_order_data.Title_Order_ID#" CFSQLType ="CF_SQL_INTEGER">		
							</cfif>	                  
							<cfif #Find_skill_order_data.Order_ID# neq ''>		
								,<cfqueryparam value = "#Find_skill_order_data.Order_ID#" CFSQLType ="CF_SQL_INTEGER">		
							</cfif>																	
						)	
					</cfquery>					
				</cfoutput>								
				<cfset sucess_id = "Sucess" />						
				<cfreturn sucess_id />				
			</cfif>				
		</cfif>	
</cffunction>





<cffunction name="Library_Type_based_insert"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="Patient_id" required="yes">	
	<cfargument name="Assessment_id" required="yes">	
		<cfoutput>
			<cfset arguments.Patient_id= decrypt(#arguments.Patient_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
			<cfset arguments.Assessment_id= decrypt(#arguments.Assessment_id#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />					
		</cfoutput>						   
	   <cfif arguments.Library_type  neq ''>	
			<cfquery  datasource="#Application.DataSrc#" name="find_Lirary_list">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE  title=<cfqueryparam value = "#arguments.Library_type#" CFSQLType ="CF_SQL_VARCHAR">
			</cfquery>	
			<cfquery  datasource="#Application.DataSrc#" name="get_Assessment_TrackerID">
				SELECT * FROM #Request.prefix_db_agency#.Assessment_New WHERE  Assessment_ID=<cfqueryparam value = "#arguments.Assessment_id#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>
			<cfquery  datasource="#Application.DataSrc#" name="get_Diagnosis_list">
				SELECT * FROM #Request.prefix_db_agency#.Diagnosis WHERE  Diagnosis_ID=<cfqueryparam value = "#find_Lirary_list.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER">
				AND  Diagnosis.Disabled = 0 
			</cfquery>	
			<cfquery name="Get_Teach_diagnoses_order" datasource="#Application.DataSrc#">
				SELECT  MAX(Dx_Order) as diagnosis_order FROM #Request.prefix_db_agency#.Diagnosis WHERE Patient_ID=<cfqueryparam value="#arguments.Patient_id#" cfsqltype="cf_sql_integer"> AND Assessment_ID=<cfqueryparam value="#arguments.Assessment_id#" cfsqltype="cf_sql_integer"> AND Disabled=0 AND Assessment_Tracker_ID=<cfqueryparam value="#get_Assessment_TrackerID.Assessment_Tracker_ID#" cfsqltype="cf_sql_integer">
				AND  Diagnosis.Disabled = 0 
			</cfquery>
			<cfquery  datasource="#Application.DataSrc#" name="Diagnosis_exist_check">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Skills WHERE  Patient_ID=<cfqueryparam value = "#arguments.Patient_id#" CFSQLType ="CF_SQL_INTEGER"> AND Assessment_ID=<cfqueryparam value = "#arguments.Assessment_id#" CFSQLType ="CF_SQL_INTEGER"> AND ICD=<cfqueryparam value = "#get_Diagnosis_list.ICD#" CFSQLType ="CF_SQL_VARCHAR"> AND Deleted=0
			</cfquery>							
			<cfif Diagnosis_exist_check.RecordCount>
				<cfset insert_action="Failed" />	
				<cfreturn insert_action />											
			<cfelse>			
					<cfif Get_Teach_diagnoses_order.diagnosis_order eq 0 or Get_Teach_diagnoses_order.diagnosis_order eq ''>					
						<cfset Diagnosis_DX_Order_val = "1">
					<cfelse>
						<cfset Diagnosis_DX_Order_val = #Get_Teach_diagnoses_order.diagnosis_order#+1>
					</cfif>			
					<cfquery  datasource="#Application.DataSrc#" name="insertDiagnoses_teach">	
						INSERT INTO #Request.prefix_db_agency#.Diagnosis
						(
							Assessment_ID, Assessment_Tracker_ID, Patient_ID, Agency_ID, Diagnosis, ICD, Short_Diagnosis, <cfif #get_Diagnosis_list.Pathway_Type# neq ''>Pathway_Type, </cfif> Record_Creation_Date,  Record_Created_By, Record_Mod_Date, Record_Mod_By, Dx_Order, Primary_Diagnosis ,<cfif #get_Diagnosis_list.Primary_Diagnosis# eq 0> PDGM_Comorbidity <cfelse> PDGM_Primary,  PDGM_Subchapter </cfif>
						) 
						VALUES
						(							
							<cfqueryparam value="#arguments.Assessment_id#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value="#get_Assessment_TrackerID.Assessment_Tracker_ID#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value="#arguments.Patient_id#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value="#arguments.AgencyID#" cfsqltype="CF_SQL_INTEGER">,
							<cfqueryparam value="#get_Diagnosis_list.Diagnosis#" cfsqltype="CF_SQL_VARCHAR">,
							<cfqueryparam value="#get_Diagnosis_list.ICD#" cfsqltype="CF_SQL_VARCHAR">,
							<cfqueryparam value="#get_Diagnosis_list.Short_Diagnosis#" cfsqltype="CF_SQL_VARCHAR">,		
							<cfif #get_Diagnosis_list.Pathway_Type# neq ''>
								<cfqueryparam value="#get_Diagnosis_list.Pathway_Type#" cfsqltype="CF_SQL_VARCHAR">,
							</cfif>					
							<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
							<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
							<cfqueryparam value ="#Diagnosis_DX_Order_val#" CFSQLType ="CF_SQL_INTEGER">,							
							<cfqueryparam value ="#get_Diagnosis_list.Primary_Diagnosis#" CFSQLType ="CF_SQL_INTEGER">,
							<cfif #get_Diagnosis_list.Primary_Diagnosis# eq 0> 
								<cfqueryparam value="#get_Diagnosis_list.PDGM_Comorbidity#" cfsqltype="CF_SQL_VARCHAR">
							<cfelse> 
								<cfqueryparam value="#get_Diagnosis_list.PDGM_Primary#" cfsqltype="CF_SQL_VARCHAR">,
								<cfqueryparam value="#get_Diagnosis_list.PDGM_Subchapter#" cfsqltype="CF_SQL_VARCHAR">
							</cfif>
						)
					</cfquery>				
					<cfset Diagnosis_DX_Order_val = "0">						
					<cfquery name="last_insert_diagnoses_id_agency" datasource="#Application.DataSrc#">
						select LAST_INSERT_ID() as diagnoses_id_agency
					</cfquery>
					<cfoutput query="find_Lirary_list">			
						<cfquery  datasource="#Application.DataSrc#" name="insert_teach_Skills">
							INSERT INTO #Request.prefix_db_agency#.Teaching_Skills 
							(
								Patient_ID, Assessment_ID, ICD, 3Digit, Pathway_Type, <cfif #find_Lirary_list.Pathway_ID# neq ''>Pathway_ID,</cfif> <cfif #find_Lirary_list.Step_ID# neq ''> Step_ID,</cfif> <cfif #find_Lirary_list.Line_ID# neq ''> Line_ID, </cfif> Explanation, Created_Date, Created_by, Updated_Date, Updated_by, Diagnosis_ID, Order_ID <cfif #find_Lirary_list.Title_Order_ID# neq ""> , Title_Order_ID </cfif>
							)
							VALUES 
							(
								<cfqueryparam value ="#arguments.Patient_id#" cfsqltype="CF_SQL_INTEGER">,
								<cfqueryparam value ="#arguments.Assessment_id#" cfsqltype="CF_SQL_INTEGER">,
								<cfqueryparam value ="#find_Lirary_list.ICD#" CFSQLType ="CF_SQL_VARCHAR">,
								<cfqueryparam value ="#find_Lirary_list.3Digit#" CFSQLType ="CF_SQL_VARCHAR">,
								<cfqueryparam value ="#find_Lirary_list.Pathway_Type#" CFSQLType ="CF_SQL_VARCHAR">,
								<cfif #find_Lirary_list.Pathway_ID# neq ''>		
									<cfqueryparam value ="#find_Lirary_list.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER">,	
								</cfif>																	
								<cfif #find_Lirary_list.Step_ID# neq ''>		
									<cfqueryparam value ="#find_Lirary_list.Step_ID#" CFSQLType ="CF_SQL_INTEGER">,	
								</cfif>								
								<cfif #find_Lirary_list.Line_ID# neq ''>		
									<cfqueryparam value ="#find_Lirary_list.Line_ID#" CFSQLType ="CF_SQL_INTEGER">,
								</cfif>									
								<cfqueryparam value ="#find_Lirary_list.Explanation#" CFSQLType ="CF_SQL_VARCHAR">,								
								<cfqueryparam value ="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
								<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value ="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
								<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value ="#last_insert_diagnoses_id_agency.diagnoses_id_agency#" CFSQLType ="CF_SQL_INTEGER">,
								<cfqueryparam value = "#find_Lirary_list.Order_ID#" CFSQLType ="CF_SQL_INTEGER">
								<cfif #find_Lirary_list.Title_Order_ID# neq ""> 
									,<cfqueryparam value = "#find_Lirary_list.Title_Order_ID#" CFSQLType ="CF_SQL_INTEGER">	
								</cfif>
							)	
						</cfquery>	
					</cfoutput>	
					<cfset insert_action="Sucess" />	
					<cfreturn insert_action />
			</cfif>									
		</cfif>		
</cffunction>






<cffunction name="GET_Teaching_Library_dataALL"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 						
		<cfset response_key = [] />
		<cfset exp_all = []/>
		<cfparam name="obj" default="">
		<cfparam name="Explanation_obj" default="">				 
		<cfquery  datasource="#Application.DataSrc#" name="get_Pathwaylist_all_groupby">
			SELECT * FROM  #Request.prefix_db_lookup#.pathway_list WHERE Deleted=0 GROUP BY Pathway_ID 
		</cfquery>	
		<!---<cfloop query="get_Pathwaylist_all_groupby">				
			<cfquery  datasource="#Application.DataSrc#" name="get_Pathwaylist_data">
				SELECT * FROM  #Request.prefix_db_lookup#.pathway_list 
				WHERE Pathway_ID=<cfqueryparam value = "#get_Pathwaylist_all_groupby.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER"> 
			</cfquery>						
			<cfoutput query="get_Pathwaylist_data">
					<cfset Explanation_obj  = {"M0_Answer" = #get_Pathwaylist_data.M0_Answer#, "Type" = #get_Pathwaylist_data.Type#, "Item_ID" = #get_Pathwaylist_data.Item_ID#, "Description" = #get_Pathwaylist_data.Description# , "Pathway_ID"  = #get_Pathwaylist_data.Pathway_ID#, "ID" = #get_Pathwaylist_data.id# }  />
					<cfset arrayAppend(exp_all,Explanation_obj) />					
			</cfoutput>					
			<cfset obj  = {"Data_All" = exp_all }  />
			<cfset arrayAppend(response_key,obj) />					
			<cfset exp_all = []>
			<cfset obj = "">
			<cfset Explanation_obj = "">	
		</cfloop>	
		<cfreturn  serializeJSON(response_key) > --->		
		<cfreturn  get_Pathwaylist_all_groupby>
</cffunction>


<cffunction name="GET_LibraryDATA_all"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="Pathway_ID" required="yes">	
	<cfoutput>
		<!---<cfset arguments.Pathway_ID= decrypt(#arguments.Pathway_ID#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />	--->			
	</cfoutput>					
		<cfset response_key = [] />
		<cfset exp_all = []/>
		<cfparam name="obj" default="">
		<cfparam name="Explanation_obj" default="">							
		<cfquery  datasource="#Application.DataSrc#" name="get_Pathwaylist_data">
			SELECT * FROM  #Request.prefix_db_lookup#.pathway_list 
			WHERE Pathway_ID=<cfqueryparam value = "#arguments.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER"> AND Deleted=0
		</cfquery>						
		<cfoutput query="get_Pathwaylist_data">			
				<cfif #get_Pathwaylist_data.Created_by# neq ''>
					<cfquery name="get_super_user_name" datasource="#Application.DataSrc#">
						SELECT * FROM #Request.prefix_db_lookup#.SuperUsers WHERE User_ID=<cfqueryparam value="#get_Pathwaylist_data.Created_by#" cfsqltype="cf_sql_integer">
					</cfquery>
						<cfset created_by_name = #get_super_user_name.Full_Name# />
						<cfset created_date_field = #DateFormat(get_Pathwaylist_data.Created_Date,"mm/dd/yyyy")# />
				<cfelse>
						<cfset created_by_name = '' />
						<cfset created_date_field = '' />
				</cfif>				
				<cfif #get_Pathwaylist_data.Updated_by# neq ''>
					<cfquery name="get_updated_super_user_name" datasource="#Application.DataSrc#">
						SELECT * FROM #Request.prefix_db_lookup#.SuperUsers WHERE User_ID=<cfqueryparam value="#get_Pathwaylist_data.Updated_by#" cfsqltype="cf_sql_integer">
					</cfquery>
						<cfset updated_by_name = #get_updated_super_user_name.Full_Name# />							
						<cfset updated_date_field = #DateFormat(get_Pathwaylist_data.Updated_Date,"mm/dd/yyyy")# />	
				<cfelse>
						<cfset updated_by_name = '' />
						<cfset updated_date_field = '' />
				</cfif>		
				<cfset Explanation_obj  = {"M0_Answer" = #get_Pathwaylist_data.M0_Answer#, "Type" = #get_Pathwaylist_data.Type#, "Item_ID" = #get_Pathwaylist_data.Item_ID#, "Description" = #get_Pathwaylist_data.Description# , "Pathway_ID"  = #get_Pathwaylist_data.Pathway_ID#, "ID" = #get_Pathwaylist_data.id#, "Created_Date" = #created_date_field#, "Created_by" = #created_by_name#, "Updated_Date" = #updated_date_field#, "Updated_by" = #updated_by_name# }  />
				<cfset arrayAppend(exp_all,Explanation_obj) />					
		</cfoutput>					
		<cfset obj  = {"Data_All" = exp_all }  />
		<cfset arrayAppend(response_key,obj) />	
		<cfset exp_all = []>
		<cfset obj = "">
		<cfset Explanation_obj = "">	
		<cfreturn  serializeJSON(response_key) > 
</cffunction>

<cffunction name="show_Library_dataSteps_edit"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="Table_ID" required="yes">
		<cfif arguments.Table_ID  neq 0>
			<cfquery name="Teaching_Library_list" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_lookup#.pathway_list WHERE id=<cfqueryparam value = "#arguments.Table_ID#" CFSQLType ="CF_SQL_INTEGER">			
			</cfquery>					
			<cfsavecontent	variable = "html_list"> 			
				<form name="Library_data_form" id="Library_edit_form_id" action="" method="post">
					<input type="hidden" name="edit_Library_data_ID" id="edit_Library_dataID"  value="<cfoutput>#arguments.Table_ID#</cfoutput>"/>
					<input type="hidden" name="edit_Library_data_Pathway_ID" id="edit_Library_data_PathwayID"  value="<cfoutput>#Teaching_Library_list.Pathway_ID#</cfoutput>"/>
					<cfoutput>	
					<div class="row">
						<div class="col-md-6">							
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Pathway ID:</label>	
								<input type="number" class="form-control" name="pathway_ID_name" id="pathway_ID_id" value="#Teaching_Library_list.Pathway_ID#" style="">	
							</div>
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Mobile Answer:</label>	
								<textarea name="Library_MO_Answer_name" id="Library_MO_Answer_id" type="text" value="" style="width: 100%;" class="form-control">#Teaching_Library_list.M0_Answer#</textarea>		
							</div>															
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Description:</label>	
								<textarea name="Library_description_name" id="Library_description_id" type="text" value="" style="width: 100%;height: 135px;" class="form-control">#Teaching_Library_list.Description#</textarea>		
							</div>	
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Skill:</label>	
								<input type="text" class="form-control" name="Skill_name" id="Skill_id" value="#Teaching_Library_list.Skill#" style="width: 100%">
							</div>							
						</div>						
						<div class="col-md-6">
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Pathway Type:</label>	
								<input type="text" class="form-control" name="pathway_type_name" id="pathway_type_id" value="#Teaching_Library_list.Type#" style="">	
							</div>	
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Mobile Description:</label>	
								<textarea name="Library_MO_description_name" id="Library_MO_description_id" type="text" value="" style="width: 100%;" class="form-control">#Teaching_Library_list.Mobile_Desc#</textarea>		
							</div>	
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Copy Into Progress Note:</label>	
								<textarea name="CopyIntoProgressNote_name" id="CopyIntoProgressNote_id" type="text" value="" style="width: 100%;height: 135px;" class="form-control">#Teaching_Library_list.CopyIntoProgressNote#</textarea>		
							</div>	
						</div>		
								
					</div>
					</cfoutput>	
					</form>			
			</cfsavecontent>	
			<cfreturn html_list />	
		</cfif>	
</cffunction>


<cffunction name="update_Edit_Library_data"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="Table_id" required="yes">
		<cfquery  datasource="#Application.DataSrc#" name="Get_library_all">
			SELECT * FROM #Request.prefix_db_lookup#.pathway_list WHERE id=<cfqueryparam value = "#arguments.Table_id#" CFSQLType ="CF_SQL_INTEGER"> 
		</cfquery>	
		<cfset Order_Calc_value = 0 />
		<cfif #arguments.Pathway_ID# neq #Get_library_all.Pathway_ID#>			
			<cfquery  datasource="#Application.DataSrc#" name="Get_library_pathway_chk">
				SELECT * FROM #Request.prefix_db_lookup#.pathway_list WHERE Pathway_ID=<cfqueryparam value = "#arguments.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER"> AND Deleted=0 LIMIT 1
			</cfquery>			
			<cfif Get_library_pathway_chk.RecordCount>
				<cfset Order_Calc_value = #Get_library_pathway_chk.Order_Calc# />											
			<cfelse>
				<cfquery  datasource="#Application.DataSrc#" name="Get_MAX_library_order_value">
					SELECT MAX(Order_Calc) as Max_Order_Calc FROM #Request.prefix_db_lookup#.pathway_list
				</cfquery>
				<cfset Order_Calc_value = #Get_MAX_library_order_value.Max_Order_Calc#+1 />	
			</cfif>			
		<cfelse>
			<cfset Order_Calc_value = #Get_library_all.Order_Calc# />	
		</cfif>
		<cfquery  name="editTeachskill_update" datasource="#Application.DataSrc#">
			UPDATE 
				#Request.prefix_db_lookup#.pathway_list 
			SET	
				Pathway_ID = <cfqueryparam value = "#arguments.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER">,
				Type = <cfqueryparam value = "#arguments.Pathway_type#" CFSQLType ="CF_SQL_VARCHAR">,				
				Description = <cfqueryparam value = "#arguments.Description_field#" CFSQLType ="CF_SQL_VARCHAR">,
				Mobile_Desc = <cfqueryparam value = "#arguments.Mo_description#" CFSQLType ="CF_SQL_VARCHAR">,
				M0_Answer = <cfqueryparam value = "#arguments.Mo_Answer#" CFSQLType ="CF_SQL_VARCHAR">,				
				Skill = <cfqueryparam value = "#arguments.Skill#" CFSQLType ="CF_SQL_VARCHAR">,
				CopyIntoProgressNote = <cfqueryparam value = "#arguments.Copy_Into_Progress_Note#" CFSQLType ="CF_SQL_VARCHAR">,	
				Order_Calc = <cfqueryparam value = "#Order_Calc_value#" CFSQLType ="CF_SQL_INTEGER">,													
				<cfif Get_library_all.Created_Date neq ''>		
					Created_Date = <cfqueryparam value="#Get_library_all.Created_Date#" cfsqltype="cf_sql_date">,
				</cfif>
				<cfif Get_library_all.Created_by neq ''>
					Created_by = <cfqueryparam value = "#Get_library_all.Created_by#" CFSQLType ="CF_SQL_INTEGER">,
				</cfif>
				Updated_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
				Updated_by = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
			WHERE 
				id = <cfqueryparam value = "#arguments.Table_id#" CFSQLType ="CF_SQL_INTEGER">
		</cfquery>
		<cfset library_data_update = "Sucess" />			
		<cfreturn library_data_update />
</cffunction>


<cffunction name="Library_dataSteps_delete"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 	
	<cfargument name="Table_ID" required="yes">						   
	   <cfif arguments.Table_ID neq ''>	 
			<cfquery  datasource="#Application.DataSrc#" name="delete_library_data">
				UPDATE 
					#Request.prefix_db_lookup#.pathway_list 
				SET 
					Deleted = '#1#'
				WHERE 
					id=<cfqueryparam value = "#arguments.Table_ID#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>			
			<cfset delete_id = "Sucess" />						
			<cfreturn delete_id />
		</cfif>	
</cffunction>


<cffunction name="Library_data_all_delete"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="Pathway_ID" required="yes">
	<cfoutput>
		<cfset arguments.Pathway_ID= decrypt(#arguments.Pathway_ID#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />				
	</cfoutput>								   
	   <cfif arguments.Pathway_ID neq ''>	 
			<cfquery  datasource="#Application.DataSrc#" name="delete_library_data">
				UPDATE 
					#Request.prefix_db_lookup#.pathway_list 
				SET 
					Deleted = '#1#'
				WHERE 
					Pathway_ID=<cfqueryparam value = "#arguments.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>			
			<cfset delete_id = "Sucess" />						
			<cfreturn delete_id />
		</cfif>	
</cffunction>


<cffunction name="show_Library_dataALL_edit"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="Pathway_ID" required="yes">
	<cfoutput>
		<cfset arguments.Pathway_ID= decrypt(#arguments.Pathway_ID#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />				
	</cfoutput>										   
		<cfif arguments.Pathway_ID  neq ''>
			<cfquery name="Teaching_Library_list" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_lookup#.pathway_list WHERE Pathway_ID=<cfqueryparam value = "#arguments.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER"> AND Deleted=0	GROUP BY Pathway_ID		
			</cfquery>					
			<cfsavecontent	variable = "html_list"> 			
				<form name="LibraryALL_data_form" id="LibraryALL_edit_form_id" action="" method="post">
					<input type="hidden" name="edit_LibraryALL_data_Pathway_ID" id="edit_LibraryALL_data_PathwayID"  value="<cfoutput>#Teaching_Library_list.Pathway_ID#</cfoutput>"/>
					<cfoutput>	
					<div class="row">
						<div class="col-md-3">							
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Pathway:</label>			
							</div>	
						</div>
						<div class="col-md-9">
							<div class="form-group">
								<textarea name="LibraryALL_description_name" id="LibraryALL_description_id" type="text" value="" style="width: 100%;height: 185px;" class="form-control">#Teaching_Library_list.M0_Answer#</textarea>										
							</div>	
						</div>				
					</div>
					</cfoutput>	
					</form>			
			</cfsavecontent>	
			<cfreturn html_list />	
		</cfif>	
</cffunction>

<cffunction name="update_Edit_LibraryALL_data"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="Pathway_ID" required="yes">
		<cfquery  datasource="#Application.DataSrc#" name="Get_library_all">
			SELECT * FROM #Request.prefix_db_lookup#.pathway_list WHERE Pathway_ID=<cfqueryparam value = "#arguments.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER"> AND Deleted=0
		</cfquery>			
		<cfloop query="Get_library_all">	
			<cfquery  name="editTeachskill_update" datasource="#Application.DataSrc#">
				UPDATE 
					#Request.prefix_db_lookup#.pathway_list 
				SET					
					M0_Answer = <cfqueryparam value = "#arguments.Description_field#" CFSQLType ="CF_SQL_VARCHAR">,					
					<cfif Get_library_all.Created_Date neq ''>		
						Created_Date = <cfqueryparam value="#Get_library_all.Created_Date#" cfsqltype="cf_sql_date">,
					</cfif>
					<cfif Get_library_all.Created_by neq ''>
						Created_by = <cfqueryparam value = "#Get_library_all.Created_by#" CFSQLType ="CF_SQL_INTEGER">,
					</cfif>
					Updated_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
					Updated_by = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
				WHERE 
					id = <cfqueryparam value = "#Get_library_all.id#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>
		</cfloop>
		<cfset library_data_update = "Sucess" />			
		<cfreturn library_data_update />
</cffunction>


<cffunction name="Add_Library_form_data"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="Pathway_ID" required="yes">
		<cfquery  datasource="#Application.DataSrc#" name="Get_library_Pathway_data">
			SELECT * FROM #Request.prefix_db_lookup#.pathway_list WHERE Pathway_ID=<cfqueryparam value = "#arguments.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER"> AND Deleted=0 LIMIT 1
		</cfquery>			
		<cfquery  datasource="#Application.DataSrc#" name="Get_MAX_library_item_id_value">
			SELECT MAX(Item_ID) as Max_Item_ID FROM #Request.prefix_db_lookup#.pathway_list
		</cfquery>	
		<cfset Order_Calc_value = 0 />
		<cfset Item_ID_value = #Get_MAX_library_item_id_value.Max_Item_ID#+1 />
		<cfif Get_library_Pathway_data.RecordCount>			
			<cfset Order_Calc_value = #Get_library_Pathway_data.Order_Calc#>									
		<cfelse>
			<cfquery  datasource="#Application.DataSrc#" name="Get_MAX_library_order_value">
				SELECT MAX(Order_Calc) as Max_Order_Calc FROM #Request.prefix_db_lookup#.pathway_list
			</cfquery>
			<cfset Order_Calc_value = #Get_MAX_library_order_value.Max_Order_Calc#+1 />	
		</cfif>	
		<cfquery  datasource="#Application.DataSrc#" name="insert_add_library_data">
			INSERT INTO #Request.prefix_db_lookup#.pathway_list 
			(
				CopyIntoProgressNote, Description, M0_Answer, Item_ID, Order_Calc, Pathway_ID, Skill, Type, Mobile_Desc, Created_Date, Created_by, Updated_Date, Updated_by
			)
			VALUES 
			(
				<cfqueryparam value ="#arguments.Copy_Into_Progress_Note#" CFSQLType ="CF_SQL_VARCHAR">,
				<cfqueryparam value ="#arguments.Description_field#" CFSQLType ="CF_SQL_VARCHAR">,
				<cfqueryparam value ="#arguments.Mo_Answer#" CFSQLType ="CF_SQL_VARCHAR">,
				<cfqueryparam value ="#Item_ID_value#" CFSQLType ="CF_SQL_INTEGER">,				
				<cfqueryparam value ="#Order_Calc_value#" CFSQLType ="CF_SQL_INTEGER">,
				<cfqueryparam value ="#arguments.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER">,
				<cfqueryparam value ="#arguments.Skill#" CFSQLType ="CF_SQL_VARCHAR">,
				<cfqueryparam value ="#arguments.Pathway_type#" CFSQLType ="CF_SQL_VARCHAR">,
				<cfqueryparam value ="#arguments.Mo_description#" CFSQLType ="CF_SQL_VARCHAR">,	
				<cfqueryparam value ="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
				<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
				<cfqueryparam value ="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
				<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
			)	
		</cfquery>	
		<cfset library_data_update = "Sucess" />			
		<cfreturn library_data_update />
</cffunction>


<cffunction name="Get_Library_data_for_print"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="Pathway_ID" required="yes">
	<cfset arguments.Pathway_ID= decrypt(#arguments.Pathway_ID#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />	
	<cfquery name="get_Pathway_list" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_lookup#.pathway_list WHERE Pathway_ID=<cfqueryparam value="#arguments.Pathway_ID#" cfsqltype="cf_sql_integer"> AND Deleted=0 GROUP BY Pathway_ID
	</cfquery>
	<cfreturn get_Pathway_list />	
</cffunction>


<cffunction name="GET_Agency_Teaching_Library_data"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfquery  datasource="#Application.DataSrc#" name="get_Pathwaylist_all_groupby">
		SELECT * FROM  #Request.prefix_db_agency#.Teaching_Library WHERE Deleted=0 GROUP BY ICD ORDER BY Library_List_Order ASC
	</cfquery>					
	<cfreturn  get_Pathwaylist_all_groupby>
</cffunction>


<cffunction name="GET_AgencyLibraryDATA_all"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 	
	<cfargument name="Three_Digit" required="yes">				
		<cfset response_key = [] />
		<cfset exp_all = []/>
		<cfparam name="obj" default="">
		<cfparam name="Explanation_obj" default="">							
		<cfquery  datasource="#Application.DataSrc#" name="get_Pathwaylist_data">
			SELECT * FROM  #Request.prefix_db_agency#.Teaching_Library 
			WHERE 
				Three_Digit=<cfqueryparam value = "#arguments.Three_Digit#" CFSQLType ="CF_SQL_VARCHAR"> 
				AND Deleted=0
				AND Pathway_Type NOT LIKE 'goal%' 
                AND Pathway_Type NOT LIKE 'intervention%'
                AND Pathway_Type NOT LIKE 'Source%' 
				GROUP BY Pathway_ID ORDER BY Title_Order_ID ASC
		</cfquery>			
		<cfloop query="get_Pathwaylist_data">		
			<cfquery  datasource="#Application.DataSrc#" name="get_Pathwaylist_data_convert">
				SELECT * FROM  #Request.prefix_db_agency#.Teaching_Library 
				WHERE 
					Three_Digit=<cfqueryparam value = "#arguments.Three_Digit#" CFSQLType ="CF_SQL_VARCHAR"> 
					AND Deleted=0
					AND Pathway_Type NOT LIKE 'goal%' 
					AND Pathway_Type NOT LIKE 'intervention%'
					AND Pathway_Type NOT LIKE 'Source%' 
					AND  <cfif #get_Pathwaylist_data.Pathway_ID# neq ''>Pathway_ID = '#get_Pathwaylist_data.Pathway_ID#' <cfelse> Pathway_ID IS NULL </cfif>
					ORDER BY Order_ID ASC
			</cfquery>					
			<cfoutput query="get_Pathwaylist_data_convert">						
				<cfset Explanation_obj  = {"Order_ID" = #get_Pathwaylist_data_convert.Order_ID#, "Pathway_ID"  = #get_Pathwaylist_data_convert.Pathway_ID#, "Pathway_Type" = #get_Pathwaylist_data_convert.Pathway_Type#, "Diagnosis_ID" = #get_Pathwaylist_data_convert.Diagnosis_ID#, "Step_ID" = #get_Pathwaylist_data_convert.Step_ID#, "Explanation" = #get_Pathwaylist_data_convert.Explanation# , "ICD" = #get_Pathwaylist_data_convert.ICD#, "Three_Digit" = #get_Pathwaylist_data_convert.Three_Digit#, "ID" = #get_Pathwaylist_data_convert.ID# }  />
				<cfset arrayAppend(exp_all,Explanation_obj) />
			</cfoutput>			
			<cfset Title_get = '' />
			<cfoutput query="get_Pathwaylist_data_convert">						
				<cfif #get_Pathwaylist_data_convert.Pathway_Type# contains 'Title'>
					<cfset Title_get = #get_Pathwaylist_data_convert.Pathway_Type# />						
				</cfif>	
			</cfoutput>			
			<cfset obj  = {"title" = #Title_get# , "Data_All" = exp_all }  />
			<cfset arrayAppend(response_key,obj) />			
			<cfset exp_all = []>
			<cfset obj = "">
			<cfset Explanation_obj = "">
		</cfloop>	
		<cfreturn  serializeJSON(response_key) > 
</cffunction>



<cffunction name="show_Agency_Library_dataALL_edit"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="Three_Digit" required="yes">
	<cfoutput>
		<cfset arguments.Three_Digit= decrypt(#arguments.Three_Digit#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />				
	</cfoutput>										   
		<cfif arguments.Three_Digit  neq ''>
			<cfquery name="Teaching_Library_list" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE Three_Digit=<cfqueryparam value = "#arguments.Three_Digit#" CFSQLType ="CF_SQL_VARCHAR"> AND Deleted=0 GROUP BY title		
			</cfquery>				 	
			<cfsavecontent	variable = "html_list"> 			
				<form name="LibraryALL_data_form" id="LibraryALL_edit_form_id" action="" method="post">
					<input type="hidden" name="edit_LibraryALL_data_Three_Digit" id="edit_Library_data_Three_Digit"  value="<cfoutput>#Teaching_Library_list.Three_Digit#</cfoutput>"/>
					<cfoutput>	
					<div class="row">
						<div class="col-md-3">							
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Pathway:</label>			
							</div>	
						</div>
						<div class="col-md-9">
							<div class="form-group">
								<textarea name="LibraryALL_description_name" id="LibraryALL_description_id" type="text" value="" style="width: 100%;height: 185px;" class="form-control">#Teaching_Library_list.title#</textarea>										
							</div>	
						</div>				
					</div>
					</cfoutput>	
					</form>			
			</cfsavecontent>	
			<cfreturn html_list />	
		</cfif>	
</cffunction>

<cffunction name="update_Edit_Agency_LibraryALL_data"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="Three_Digit" required="yes">
		<cfquery  datasource="#Application.DataSrc#" name="Get_library_all">
			SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE Three_Digit=<cfqueryparam value = "#arguments.Three_Digit#" CFSQLType ="CF_SQL_VARCHAR"> AND Deleted=0
		</cfquery>			
		<cfloop query="Get_library_all">	
			<cfquery  name="editTeachskill_update" datasource="#Application.DataSrc#">
				UPDATE 
					#Request.prefix_db_agency#.Teaching_Library 
				SET					
					title = <cfqueryparam value = "#arguments.Description_field#" CFSQLType ="CF_SQL_VARCHAR">,					
					<cfif Get_library_all.Created_Date neq ''>		
						Created_Date = <cfqueryparam value="#Get_library_all.Created_Date#" cfsqltype="cf_sql_date">,
					</cfif>
					<cfif Get_library_all.Created_by neq ''>
						Created_by = <cfqueryparam value = "#Get_library_all.Created_by#" CFSQLType ="CF_SQL_INTEGER">,
					</cfif>
					Updated_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
					Updated_by = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
				WHERE 
					ID = <cfqueryparam value = "#Get_library_all.ID#" CFSQLType ="CF_SQL_INTEGER">
			</cfquery>
		</cfloop>
		<cfset library_data_update = "Sucess" />			
		<cfreturn library_data_update />
</cffunction>

<cffunction name="Agency_Library_data_all_delete"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="Three_Digit" required="yes">
	<cfoutput>
		<cfset arguments.Three_Digit= decrypt(#arguments.Three_Digit#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />				
	</cfoutput>								   
	   <cfif arguments.Three_Digit neq ''>	 
			<cfquery  datasource="#Application.DataSrc#" name="delete_library_data">
				UPDATE 
					#Request.prefix_db_agency#.Teaching_Library 
				SET 
					Deleted = '#1#'
				WHERE 
					Three_Digit=<cfqueryparam value = "#arguments.Three_Digit#" CFSQLType ="CF_SQL_VARCHAR">
			</cfquery>			
			<cfset delete_id = "Sucess" />						
			<cfreturn delete_id />
		</cfif>	
</cffunction>

<cffunction name="show_Agency_Library_dataSteps_edit"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 		
	<cfargument name="ID" required="yes">					   
		<cfif arguments.ID  neq 0>
			<cfquery name="Teaching_Library_list" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE ID=<cfqueryparam value = "#arguments.ID#" CFSQLType ="CF_SQL_INTEGER">			
			</cfquery>					
			<cfsavecontent	variable = "html_list"> 			
				<form name="Teach_Skill_form" id="Teach_Skill_form_id" action="" method="post">
						
					<input type="hidden" name="editLibrary__ID" id="edit_Library_ID"  value="<cfoutput>#arguments.ID#</cfoutput>"/>
					<input type="hidden" name="editLibrary_Three_Digit" id="edit_Library_Three_Digit"  value="<cfoutput>#arguments.Three_Digit#</cfoutput>"/>
					<input type="hidden" name="editLibrary_pathway_type" id="edit_Library_pathway_type_id"  value="<cfoutput>#arguments.Pathway_Type#</cfoutput>"/>					
					<cfoutput>						
					<div class="row">
						<div class="col-md-3">							
							<div class="form-group">
								<label class="control-label" style="text-align:center;margin-top: 13px;">Explanation:</label>			
							</div>	
						</div>
						<div class="col-md-9">
							<div class="form-group">
								<textarea name="Library_Explanation_name" id="Library_Explanation_id" type="text" value="" style="width: 100%;height: 185px;" class="form-control">#Teaching_Library_list.Explanation#</textarea>										
							</div>
						</div>				
					</div>
					</cfoutput>						
					</form>			
			</cfsavecontent>		
			<cfreturn html_list />	
		</cfif>	
</cffunction>



<cffunction name="update_Agency_TeachLibrary"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="ID" required="yes">
	<cfif #arguments.ID# neq ''>
		<cfquery  datasource="#Application.DataSrc#" name="GetTeachSkills_all">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE ID=<cfqueryparam value = "#arguments.ID#" CFSQLType ="CF_SQL_INTEGER"> 
		</cfquery>			
		<cfquery  name="editTeachskill_update" datasource="#Application.DataSrc#">
			UPDATE 
				#Request.prefix_db_agency#.Teaching_Library 
			SET							
				Explanation = <cfqueryparam value = "#arguments.Explanation_field#" CFSQLType ="CF_SQL_VARCHAR">,				
				Created_Date = <cfqueryparam value="#GetTeachSkills_all.Created_Date#" cfsqltype="cf_sql_date">,
				Created_by = <cfqueryparam value = "#GetTeachSkills_all.Created_by#" CFSQLType ="CF_SQL_INTEGER">,
				Updated_Date = <cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">, 
				Updated_by = <cfqueryparam value = "#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">
			WHERE ID= <cfqueryparam value = "#arguments.ID#" CFSQLType ="CF_SQL_INTEGER">
		</cfquery>
		<cfset teachskill_update = "Sucess" />						
		<cfreturn teachskill_update />	
	<cfelse>
		<cfset teachskill_update = "Failed" />						
		<cfreturn teachskill_update />	
	</cfif>.		
</cffunction>



<cffunction name="Delete_Agency_TeachLibrary"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	<cfargument name="ID" required="yes">
	<cfargument name="IdentityofRow" required="yes">						   
	   <cfif arguments.ID  neq 0 and arguments.ID neq ''>	
			<cfquery  datasource="#Application.DataSrc#" name="GetTeachSkills_all">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE ID=<cfqueryparam value = "#arguments.ID#" CFSQLType ="CF_SQL_INTEGER"> 
			</cfquery>				
			<cfif arguments.IdentityofRow eq 0>
				<cfoutput query="GetTeachSkills_all"> 								
					<cfquery  datasource="#Application.DataSrc#" name="delete_teach_skill_all">
						UPDATE 
							#Request.prefix_db_agency#.Teaching_Library 
						SET 
							Deleted = '#1#'
						WHERE  							
							Three_Digit=<cfqueryparam value = "#GetTeachSkills_all.Three_Digit#" CFSQLType ="CF_SQL_VARCHAR">
							AND Pathway_ID=<cfqueryparam value = "#GetTeachSkills_all.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER">
					</cfquery>
				</cfoutput>
			<cfelse>
				<cfquery  datasource="#Application.DataSrc#" name="delete_teach_skill">
					UPDATE 
						#Request.prefix_db_agency#.Teaching_Library 
					SET 
						Deleted = '#1#'
					WHERE  
						ID=<cfqueryparam value = "#arguments.ID#" CFSQLType ="CF_SQL_INTEGER">
				</cfquery>	
			</cfif>			
			<cfset delete_id = "Sucess" />						
			<cfreturn delete_id />
		</cfif>	
</cffunction>


<cffunction name="TeachLibrary_Type_item_insert"  access="remote" output="Yes" returnFormat= "JSON">   
	<cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 	
	<cfargument name="ID" required="yes">		   
	   <cfif arguments.ID  neq 0 and arguments.ID neq ''>	 
	   		<cfquery  datasource="#Application.DataSrc#" name="Find_diagnosis_data">
				SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE ID=<cfqueryparam value = "#arguments.ID#" CFSQLType ="CF_SQL_INTEGER"> 
			</cfquery>				
			<cfquery  datasource="#Application.DataSrc#" name="Find_skill_order_data">
				SELECT 
					max(Order_ID) as maximun_order 
				FROM 
					#Request.prefix_db_agency#.Teaching_Library 
				WHERE  
					Three_Digit=<cfqueryparam value = "#arguments.Three_Digit#" CFSQLType ="CF_SQL_VARCHAR"> 					
					AND Pathway_ID=<cfqueryparam value = "#Find_diagnosis_data.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER"> 
					AND Deleted=0
			</cfquery>
			<cfquery  datasource="#Application.DataSrc#" name="Find_skill_all_data">
				SELECT * 
				FROM 
					#Request.prefix_db_agency#.Teaching_Library 
				WHERE  					
					Three_Digit=<cfqueryparam value = "#Find_diagnosis_data.Three_Digit#" CFSQLType ="CF_SQL_VARCHAR"> 
					AND Deleted=0 
					AND <cfif #arguments.PathwayID# neq ''> Pathway_ID=<cfqueryparam value = "#arguments.PathwayID#" CFSQLType ="CF_SQL_INTEGER"> <cfelse> Pathway_ID IS NULL  </cfif>
					AND Pathway_Type NOT LIKE 'Title%' 
					AND Pathway_Type NOT LIKE 'goal%' 
					AND Pathway_Type NOT LIKE 'intervention%' 
					AND Pathway_Type NOT LIKE 'Source%' ORDER BY Step_ID DESC LIMIT 1
			</cfquery>	
			<cfif Find_skill_all_data.RecordCount>
				<cfset Path_Way_Type = #Find_skill_all_data.Pathway_Type#/>					
				<cfif #Find_skill_all_data.Step_ID# eq ''>
					<cfset Step_ID_data = "1"/>	
				<cfelse>
					<cfset Step_ID_data = #Find_skill_all_data.Step_ID#+1/>	
				</cfif>																
			<cfelse>
				<cfset Path_Way_Type = "Teaching"/>	
				<cfset Step_ID_data = "1"/>
			</cfif>	
			<cfset Order_count_for_skill=#Find_skill_order_data.maximun_order#+1>						
			<cfquery  datasource="#Application.DataSrc#" name="insert_Teaching_Skills">
				INSERT INTO #Request.prefix_db_agency#.Teaching_Library 
				(
					ICD, Three_Digit, Pathway_Type, <cfif #arguments.PathwayID# neq ''>Pathway_ID,</cfif> Step_ID, Line_ID, Explanation, Created_Date, Created_by, Updated_Date, Updated_by, Diagnosis_ID, Order_ID, title
				)
				VALUES 
				(								
					<cfqueryparam value="#Find_diagnosis_data.ICD#" cfsqltype="CF_SQL_VARCHAR">,
					<cfqueryparam value="#Left(Find_diagnosis_data.Three_Digit,60)#" cfsqltype="CF_SQL_VARCHAR">,
					<cfqueryparam value = "#Path_Way_Type#" CFSQLType ="CF_SQL_VARCHAR">,
					<cfif #arguments.PathwayID# neq ''>
						<cfqueryparam value ="#arguments.PathwayID#" CFSQLType ="CF_SQL_INTEGER">,
					</cfif>
					<cfqueryparam value ="#Step_ID_data#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value ="1" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value="#arguments.Explanation#" cfsqltype="CF_SQL_VARCHAR">,											
					<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
					<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value="#dateFormat(now(),'yyyy-mm-dd')#" cfsqltype="cf_sql_date">,
					<cfqueryparam value ="#session.employeeid#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value = "#Find_diagnosis_data.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value = "#Order_count_for_skill#" CFSQLType ="CF_SQL_INTEGER">,
					<cfqueryparam value = "#Find_diagnosis_data.title#" CFSQLType ="CF_SQL_VARCHAR">											
				)	
			</cfquery>	
			<cfset sucess_id = "Sucess" />						
			<cfreturn sucess_id />				
		</cfif>	
</cffunction>



<cffunction name="Library_Order_change_update"  access="remote" output="Yes" returnFormat= "JSON"> 	
	<cfargument name="Three_Digit_ids" required="yes">	
	<cfif arguments.Three_Digit_ids  neq ''>	
		<cfoutput>
			<cfset Three_Digit_ID_STring = "#arguments.Three_Digit_ids#">	
			<cfset Array_Three_Digit_ID = Three_Digit_ID_STring.Split(",")>
		</cfoutput> 		
		<cfset teach_Library_order_count="0">	
			<cfloop array="#Array_Three_Digit_ID#" index="idx">	
				<cfset teach_Library_order_count = teach_Library_order_count+1>	
			   	<cfquery  datasource="#Application.DataSrc#" name="update_teach_skill">
					UPDATE 
						#Request.prefix_db_agency#.Teaching_Library 
					SET 
						Library_List_Order = '#teach_Library_order_count#'
					WHERE 
						Three_Digit=<cfqueryparam value = "#idx#" CFSQLType ="CF_SQL_VARCHAR">
				</cfquery>			   
			</cfloop>	
		<cfset teach_Library_order_count="0">
	</cfif>	
	<cfset sucess = "Sucess" />
	<cfreturn sucess />		
</cffunction>



<cffunction name="Library_Symptoms_Order_update"  access="remote" output="Yes" returnFormat= "JSON"> 
	<cfargument name="Skills_IDS" required="yes">
	<cfif arguments.Skills_IDS  neq ''>	 		
		<cfoutput>
			<cfset Skill_ID_STring = "#arguments.Skills_IDS#">	
			<cfset Array_Skill_ID = Skill_ID_STring.Split(",")>
		</cfoutput> 		
		<cfif arguments.Table_type eq 'library_data_Table_sub'>
			<cfset teachskills_Title_order_count="0">					
			<cfloop array="#Array_Skill_ID#" index="idx">	
				<cfset teachskills_Title_order_count = teachskills_Title_order_count+1>					
				<cfquery name="select_Teach_skills" datasource="#Application.DataSrc#">
					SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE ID=<cfqueryparam value = "#idx#" CFSQLType ="CF_SQL_INTEGER">
				</cfquery>				
				<cfoutput query="select_Teach_skills">
					<cfquery  datasource="#Application.DataSrc#" name="Multiple_update_teach_skill">
						UPDATE 
							#Request.prefix_db_agency#.Teaching_Library 
						SET 
							Title_Order_ID = '#teachskills_Title_order_count#'
						WHERE 
							Pathway_ID=<cfqueryparam value = "#select_Teach_skills.Pathway_ID#" CFSQLType ="CF_SQL_INTEGER"> 
							AND ICD=<cfqueryparam value = "#select_Teach_skills.ICD#" CFSQLType ="CF_SQL_VARCHAR">
							AND Deleted=0
					</cfquery>				
				</cfoutput>						   
			</cfloop>				
			<cfset teachskills_Title_order_count="0">			
		<cfelseif arguments.Table_type eq 'Multiple_Explanation_table'>		
			<cfset teachskills_order_count="0">					
			<cfloop array="#Array_Skill_ID#" index="idx">	
				<cfset teachskills_order_count = teachskills_order_count+1>											
			   	<cfquery  datasource="#Application.DataSrc#" name="update_teach_skill">
					UPDATE 
						#Request.prefix_db_agency#.Teaching_Library 
					SET 
						Order_ID = '#teachskills_order_count#'
					WHERE 
						ID=<cfqueryparam value = "#idx#" CFSQLType ="CF_SQL_INTEGER">
				</cfquery>			   
			</cfloop>				
			<cfset teachskills_order_count="0">			
		</cfif>				
	</cfif>	
	<cfset sucess = "Sucess" />
	<cfreturn sucess />		
</cffunction>

<cffunction name="Get_AgencyLibrary_data_print"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="three_digit" required="yes">
	<cfset arguments.three_digit= decrypt(#arguments.three_digit#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />	
	<cfquery name="get_Pathway_list" datasource="#Application.DataSrc#">
		SELECT * FROM #Request.prefix_db_agency#.Teaching_Library WHERE Three_Digit=<cfqueryparam value="#arguments.three_digit#" cfsqltype="CF_SQL_VARCHAR"> AND Deleted=0 GROUP BY Three_Digit
	</cfquery>
	<cfreturn get_Pathway_list />	
</cffunction>

<cffunction name="Pathway_ID_based"  access="remote" output="Yes"  returntype="query">  
	<cfargument name="Patient_ID" required="yes">
	<cfargument name="Assessment_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#.Diagnosis 
                    WHERE  Patient_ID = <cfqueryparam value = "#arguments.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
                    AND  Assessment_ID = <cfqueryparam value = "#arguments.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> 
                    AND ICD = <cfqueryparam value = "#arguments.ICD#" CFSQLType ="CF_SQL_VARCHAR">
                    AND Disabled = 0 
                </cfquery>
                 <cfloop query ="GET_Diagnosis_data">
                         <cfset check_recordcfc = CreateObject("Component", "checkrecord") />
                         <cfif GET_Diagnosis_data.Pathway_Type EQ 'DME/supplies'  OR GET_Diagnosis_data.Pathway_Type 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>
                         <cfset Teach_symptoms_chk = check_recordcfc.check_teaching_skills(#arguments.Patient_ID#,#arguments.Assessment_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,'symptom' ) />
                         <cfset Teach_prevention_chk = check_recordcfc.check_teaching_skills(#arguments.Patient_ID#,#arguments.Assessment_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,'Teaching' ) />
                         <cfset Teach_symptoms_span = check_recordcfc.check_teaching_skills(#arguments.Patient_ID#,#arguments.Assessment_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,'symptom','span' ) />
                         <cfset Teach_prevention_span = check_recordcfc.check_teaching_skills(#arguments.Patient_ID#,#arguments.Assessment_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,'Teaching','span' ) />
                         <cfif Teach_prevention_chk neq 'success'>
                               <cfset insert_prevention = check_recordcfc.insert_preventions(#arguments.Patient_ID#,#arguments.Assessment_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,#variables.path_ID#,'eng' ) />	
                         </cfif>
                         <cfif Teach_prevention_span neq 'success'>
                               <cfset insert_prevention = check_recordcfc.insert_preventions(#arguments.Patient_ID#,#arguments.Assessment_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,#variables.path_ID#,'span' ) />	
                          </cfif>
                          <cfif Teach_symptoms_chk neq 'success'>
                                <cfset insert_sym = check_recordcfc.insert_symptoms(#arguments.Patient_ID#,#arguments.Assessment_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,#variables.path_ID#,'eng' ) />	
                           </cfif>
                           <cfif Teach_symptoms_span neq 'success'>
                               <cfset insert_sym_span = check_recordcfc.insert_symptoms(#arguments.Patient_ID#,#arguments.Assessment_ID#,#arguments.Diagnosis_ID#,#arguments.ICD#,#variables.path_ID#,'span' ) />	
                            </cfif> 
                      </cfloop>
         
         </cfif>
	<cfquery  datasource="#Application.DataSrc#" name="get_TeachSkills_type_1">
		<!---SELECT Pathway_ID FROM #Request.prefix_db_agency#.Teaching_Skills
		WHERE 
		Patient_ID=<cfqueryparam value = "#arguments.Patient_ID#" CFSQLType ="CF_SQL_INTEGER"> 
		AND Assessment_ID=<cfqueryparam value = "#arguments.Assessment_ID#" CFSQLType ="CF_SQL_INTEGER"> 
		AND Diagnosis_ID=<cfqueryparam value = "#arguments.Diagnosis_ID#" CFSQLType ="CF_SQL_INTEGER"> 
		AND ICD=<cfqueryparam value = "#arguments.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
		AND Deleted=0 AND Pathway_Type NOT LIKE 'goal%' 
		AND  Pathway_Type NOT LIKE 'intervention%'
		AND  Pathway_Type NOT LIKE 'Source%' 
		AND Title_Order_ID IS NOT NULL 
		GROUP BY Pathway_ID 
		ORDER BY Title_Order_ID ASC	--->
		
		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.Assessment_ID=<cfqueryparam value = "#arguments.Assessment_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
		
		
        <!---SELECT Pathway as Pathway_ID,Pathway FROM #Request.prefix_db_lookup#.vetted_190924
		WHERE ICD=<cfqueryparam value = "#arguments.ICD#" CFSQLType ="CF_SQL_VARCHAR"> 
		ORDER BY Pathway ASC--->	
	</cfquery>
	<cfreturn get_TeachSkills_type_1 />	
</cffunction>

<cffunction name="Teaching_Library_3digit_based"  access="remote" output="Yes" returnFormat= "JSON">  
	<cfargument name="Three_Digit" required="yes">	
	<cfquery  datasource="#Application.DataSrc#" name="get_Library_type">
		SELECT * FROM  #Request.prefix_db_agency#.Teaching_Library 
		WHERE 
			Three_Digit=<cfqueryparam value = "#arguments.Three_Digit#" CFSQLType ="CF_SQL_VARCHAR"> 
			AND Deleted=0
			AND Pathway_Type NOT LIKE 'goal%' 
			AND Pathway_Type NOT LIKE 'intervention%'
			AND Pathway_Type NOT LIKE 'Source%' 
			GROUP BY Pathway_ID ORDER BY Title_Order_ID ASC
	</cfquery>	
	<cfreturn get_Library_type />	
</cffunction>

	
<cffunction name="patientrecall_report"  access="remote" output="Yes" returnFormat= "JSON" hint="For Prepare Patient Recall Sheet">  
     <cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	 <cfargument name="patient_id" required="yes">
	 <cfargument name="assessment_id" required="yes">
     <cfargument name="report_type" hint="report" default="0">
     <cfquery  datasource="#Application.DataSrc#" name="get_coding_scrub">
            SELECT * FROM #Request.prefix_db_agency#.Coding_Scrub
            WHERE Patient_ID = <cfqueryparam value = "#arguments.patient_id#" cfsqltype="cf_sql_integer" > 
            AND Assessment_ID = <cfqueryparam value = "#arguments.assessment_id#"  cfsqltype="cf_sql_integer" > 
         <cfif arguments.report_type EQ 'SN'>  AND Coding_Scrub.Risk = 'SN'
         <cfelseif arguments.report_type eq "OT">AND  Coding_Scrub.Risk = 'OT'
         <cfelseif arguments.report_type eq "PT">AND Coding_Scrub.Risk = 'PT'
         </cfif>
            -- AND Message_ID = 76
         ORDER BY Message_ID ASC
	</cfquery>	
    <cfreturn get_coding_scrub />	
</cffunction>

<cffunction name="oasis_review"  access="remote" output="Yes" returnFormat= "JSON" hint="For Prepare Patient Recall Sheet">  
     <cfargument name="AgencyID" required="yes" hint="AgencyID" default="#session.agencyid#"> 
	 <cfargument name="patient_id" required="yes">
     <cfquery  datasource="#Application.DataSrc#" name="get_coding_results">
        SELECT * FROM #Request.prefix_db_agency#.Coding_Results
        WHERE Patient_ID =<cfqueryparam value = "#arguments.patient_id#" cfsqltype="cf_sql_integer"> 
        AND Message_ID = <cfqueryparam value = "78"  cfsqltype="cf_sql_integer" > 
	</cfquery>	
    <cfreturn get_coding_results />	
</cffunction>

</cfcomponent>