<!--- Send error email for woundvitalinsert.cfm failures. --->
<cfparam name="wviErrorCatch" default="" />
<cfset wviMailTo = "velmurugan@myhomecarebiz.com" />
<cfif isDefined("request.send_errors_to") AND len(trim(request.send_errors_to))>
  <cfset wviMailTo = request.send_errors_to />
</cfif>
<cfset wviMailFrom = "error@myhomecarebiz.com" />
<cfif isDefined("request.from") AND len(trim(request.from))>
  <cfset wviMailFrom = request.from />
</cfif>
<cfset wviAssmtId = "" />
<cfif isDefined("Assmt_ID")>
  <cfset wviAssmtId = Assmt_ID />
<cfelseif isDefined("form.assid")>
  <cfset wviAssmtId = form.assid />
</cfif>
<cfset wviPatientId = "" />
<cfif isDefined("Patient_ID")>
  <cfset wviPatientId = Patient_ID />
<cfelseif isDefined("form.patid")>
  <cfset wviPatientId = form.patid />
</cfif>
<cfset wviAdmitId = "" />
<cfif isDefined("getass") AND isQuery(getass) AND getass.recordcount GT 0 AND listFindNoCase(getass.columnList, "Admit_ID")>
  <cfset wviAdmitId = getass.Admit_ID />
</cfif>
<cfset wviAssessReason = "" />
<cfif isDefined("assessment_reason")>
  <cfset wviAssessReason = assessment_reason />
<cfelseif isDefined("getass") AND isQuery(getass) AND getass.recordcount GT 0 AND listFindNoCase(getass.columnList, "F26")>
  <cfset wviAssessReason = getass.F26 />
</cfif>
<cfset wviAgencyId = (isDefined("Request.Agency_ID") ? Request.Agency_ID : (isDefined("session.AgencyId") ? session.AgencyId : "")) />
<cfset wviAgencySchema = (isDefined("Request.prefix_db_agency") ? Request.prefix_db_agency : "") />
<cfset wviErrMsg = structKeyExists(wviErrorCatch, "message") ? wviErrorCatch.message : "" />
<cfset wviErrDetail = structKeyExists(wviErrorCatch, "detail") ? wviErrorCatch.detail : "" />
<cfset wviErrType = structKeyExists(wviErrorCatch, "type") ? wviErrorCatch.type : "" />
<cfset wviErrSql = "" />
<cfif structKeyExists(wviErrorCatch, "Sql")>
  <cfset wviErrSql = wviErrorCatch.Sql />
<cfelseif structKeyExists(wviErrorCatch, "sql")>
  <cfset wviErrSql = wviErrorCatch.sql />
</cfif>
<cfset wviErrQueryErr = "" />
<cfif structKeyExists(wviErrorCatch, "queryError")>
  <cfset wviErrQueryErr = wviErrorCatch.queryError />
<cfelseif structKeyExists(wviErrorCatch, "QueryError")>
  <cfset wviErrQueryErr = wviErrorCatch.QueryError />
</cfif>
<cfset wviErrTemplate = "/patientadmin_new/patient/woundvitalinsert.cfm" />
<cfset wviErrLine = "" />
<cfif structKeyExists(wviErrorCatch, "TagContext") AND isArray(wviErrorCatch.TagContext) AND arrayLen(wviErrorCatch.TagContext) GT 0>
  <cfif structKeyExists(wviErrorCatch.TagContext[1], "TEMPLATE") AND len(trim(wviErrorCatch.TagContext[1].TEMPLATE))>
    <cfset wviErrTemplate = wviErrorCatch.TagContext[1].TEMPLATE />
  </cfif>
  <cfif structKeyExists(wviErrorCatch.TagContext[1], "LINE")>
    <cfset wviErrLine = wviErrorCatch.TagContext[1].LINE />
  </cfif>
</cfif>
<cfset wviServerName = (isDefined("Application.ServerName") ? Application.ServerName : cgi.server_name) />

<cftry>
  <cfmail to="#wviMailTo#"
          from="#wviMailFrom#"
          subject="#wviServerName# Error: woundvitalinsert.cfm"
          type="html">
    <h3 style="color:red;">woundvitalinsert.cfm failed</h3>
    <p><strong>Timestamp:</strong> #dateFormat(now(), "mm/dd/yyyy")# #timeFormat(now(), "HH:mm:ss")#</p>
    <p><strong>Server:</strong> #htmlEditFormat(cgi.server_name)#</p>
    <p><strong>IP:</strong> #htmlEditFormat(cgi.remote_addr)#</p>
    <p><strong>Request:</strong> #htmlEditFormat(structKeyExists(cgi, "script_name") ? cgi.script_name : "")#</p>
    <p><strong>Query string:</strong> #htmlEditFormat(structKeyExists(cgi, "query_string") ? cgi.query_string : "")#</p>
    <hr>
    <p><strong>Assmt_ID:</strong> #htmlEditFormat(wviAssmtId)#</p>
    <p><strong>Patient_ID:</strong> #htmlEditFormat(wviPatientId)#</p>
    <p><strong>Admit_ID:</strong> #htmlEditFormat(wviAdmitId)#</p>
    <p><strong>Assessment reason (F26):</strong> #htmlEditFormat(wviAssessReason)#</p>
    <p><strong>Agency ID:</strong> #htmlEditFormat(wviAgencyId)#</p>
    <p><strong>Agency schema:</strong> #htmlEditFormat(wviAgencySchema)#</p>
    <hr>
    <p><strong>Error type:</strong> #htmlEditFormat(wviErrType)#</p>
    <p><strong>Template:</strong> #htmlEditFormat(wviErrTemplate)#</p>
    <cfif len(trim(wviErrLine))>
      <p><strong>Line:</strong> #htmlEditFormat(wviErrLine)#</p>
    </cfif>
    <p><strong>Message:</strong> #htmlEditFormat(wviErrMsg)#</p>
    <cfif len(trim(wviErrDetail))>
      <p><strong>Detail:</strong> #htmlEditFormat(wviErrDetail)#</p>
    </cfif>
    <cfif len(trim(wviErrQueryErr))>
      <p><strong>Query error:</strong> #htmlEditFormat(wviErrQueryErr)#</p>
    </cfif>
    <cfif len(trim(wviErrSql))>
      <p><strong>SQL:</strong></p>
      <pre style="background:##f5f5f5;padding:8px;white-space:pre-wrap;">#htmlEditFormat(wviErrSql)#</pre>
    </cfif>
  </cfmail>
  <cfcatch type="any"></cfcatch>
</cftry>
