Sample Source Code
Scheduler: ResourceList_Sel.cfm

About the Program

Sharecare is an online application for behavioral healthcare programs and providers. It includes access, clinical, fiscal, and reporting subsystems.

The Scheduler component keeps track of todo items, availability, scheduled events, and clinical appointments. Its functionality is similar to the Outlook calendar, but with extended availability and overlap definitions, more complex recurrence patterns, and both clinical and fiscal validations.

About the Code

This file provides a list of all resources at a facility. The user selects a facility, and then sees a list of resources, with several details. Clicking on a resource would then navigate to an edit page for that resource.

The Interface

sample of the Resource List user interface

The Code

<!---
    List of all resources at a facility.
--->

<!--- Include common constants --->
<cfinclude template="scheduler_constants.cfi">

<!--- Declare page parameters --->
<cfparam name="URL.facility_id" type="numeric" default="0">
<cfparam name="URL.ActionPerformed" type="string" default="">

<!--- Declare form parameters --->
<cfparam name="Form.facility_id" type="numeric" default="0">

<!---
===== Declare constants and local variables
--->

<cfscript>
    // ===== Declare constants
    CS_EDIT_URL = "ResourceEdit_Sel.cfm";
    CS_LONGEST_DESC = 40;

    // ===== Declare local variables
    lsCookieFacilityId = "";
    lnFacilityId = 0;
    lsFacilityName = "";
    lbCriteriaGiven = false;
    lsDescription = "";
    lsRowStyle = "";
</cfscript>

<!---
===== Select the facility to filter resources by
--->

<!--- Retrieve the persistent facility selection --->
<cf_emgGetCookieToken cookieName="Scheduler" key="FacilityId" resultVar="lsCookieFacilityId">

<!--- Determine facility based on parameters and cookies --->
<cfscript>
    // apply precedence rules: url, form, cookie, then nothing
    if ( URL.facility_id neq 0 )
        lnFacilityId = URL.facility_id;
    else if ( Form.facility_id neq 0 )
        lnFacilityId = Form.facility_id;
    else if ( IsNumeric( lsCookieFacilityId ) and ( lsCookieFacilityId neq "0" ) )
        lnFacilityId = lsCookieFacilityId;
    else
        lnFacilityId = 0;
</cfscript>

<!--- If it's changed (even to zero), update the persistent facility selection --->
<cfif lsCookieFacilityId neq "#lnFacilityId#">
    <cf_emgSetCookieToken cookieName="Scheduler" key="FacilityId" value="#lnFacilityId#">
</cfif>

<!--- Compute the "display or not" boolean --->
<cfset lbCriteriaGiven = IIf( lnFacilityId neq 0, DE("YES"), DE("NO"))>

<!---
===== Retrieve resources and facility name from the database
--->

<!--- If criteria has been selected... --->
<cfif lbCriteriaGiven>
    <!--- Retrieve the name of the facility --->
    <cfquery name="QGetFacilityName" datasource="#ShareCareDataSource#" maxrows="1">
        SELECT
            facility_name
        FROM
            facility
        WHERE
            -- at the given facility
            facility_id = #lnFacilityId#
            -- disallow "bogus" zero records
            AND NOT ( facility_id = 0 )
    </cfquery>
    <cfset lsFacilityName = QGetFacilityName.facility_name>

    <!--- Retrieve the resources at that facility --->
    <cfquery name="QGetResources" datasource="#ShareCareDataSource#">
        SELECT
            sch_resource_id,
            name,
            capacity,
            description
        FROM
            sch_resource
        WHERE
            -- at the given facility
            facility_id = #lnFacilityId#
            -- disallow "bogus" zero records
            AND NOT ( sch_resource_id = 0 )
        ORDER BY
            name
    </cfquery>
</cfif>

<!---
===== Start document output
--->

<cfoutput>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>Scheduler Resource List</title>
    <link href="scheduler.css" rel="stylesheet" type="text/css">

    <!-- Include JavaScript utility functions -->
    <script src="scheduler.js" language="JavaScript" type="text/javascript"></script>
    <script src="forms.js" language="JavaScript" type="text/javascript"></script>

    <script language="JavaScript" type="text/javascript">

        // Submit the facility selection form
        function SubmitSelection( facility_id, form_name )
        {
            var f = document.forms[ form_name ];
            message( 'Please wait... loading resources for ' + f.facility_primary1.value + '...' );
            f.submit();
        }

        // Indicate the current selections on the info bar
        function InitInfoBar()
        {
            var descriptions = "";
            var data = "";

            // display the selected facility
            <cfif lnFacilityId neq 0>
                descriptions += "Facility,";
                data += "#lsFacilityName#,";
            </cfif>

            // update the info bar
            infoBar( descriptions, data );
        }
        ChainEventHandler( "window.onload", "InitInfoBar()" );

        <!--- If returning from a poster... --->
        <cfif Len( URL.ActionPerformed ) gt 0>
            // describe what action was performed
            ChainEventHandler( "window.onload", "message( '#URL.ActionPerformed#' )" );
        </cfif>
    </script>
</head>
<body>
</cfoutput>
<cf_emgSchedulerFlagSet tab="Maintenance" flag="Resources">

<div class="smallSpacer">&nbsp;</div>

<!---
===== Output the button bar forms and facility selector
--->

<cfoutput>
<div align="center">

<!--- The button for inserting a new resource --->
<form name="New" action="#CS_EDIT_URL#" method="POST">
<input type="submit" value="New" class="buttonbar">
</form>

<!--- The facility selector --->
<form name="SelectFacility" action="ResourceList_Sel.cfm" method="POST">
<table class="lookupTable">
<tbody>
    <cf_UniversalLookup lookup="Facility" name="facility" id="#lnFacilityId#" primary1="#lsFacilityName#" primary2="#lnFacilityId#" function="SubmitSelection( 'SelectFacility' )">
</tbody>
</table>
</form>

<hr>

</div>
</cfoutput>

<!---
===== Output the table of resources
--->

<div align="center">

<!--- If criteria has been selected... --->
<cfif lbCriteriaGiven>

    <!--- Provide column headings --->
    <table class="listTable" cellspacing="0">
    <thead>
        <tr>
            <th>Resource Name</th>
            <th>Capacity</th>
            <th>Description</th>
        </tr>
    </thead>

    <cfif QGetResources.RecordCount gt 0>
        <!--- Output all records that matched --->
        <tbody>
            <cfoutput query="QGetResources">

            <!--- Truncate the description --->
            <cfset lsDescription = description>
            <cfif Len( description ) gt CS_LONGEST_DESC>
                <cfset lsDescription = Left( description, CS_LONGEST_DESC - 3 ) & "...">
            </cfif>

            <cfset lsRowStyle = IIf( QGetResources.CurrentRow mod 2, DE("oddRow"), DE("evenRow") )>
            <tr class="#lsRowStyle#">
                <td>
                    <a href="#CS_EDIT_URL#?sch_resource_id=#sch_resource_id#">#name#</a>
                </td>
                <td>#capacity#</td>
                <td title="#description#">#lsDescription#</td>
            </tr>

            </cfoutput>
        </tbody>

    <cfelse>
        <!--- Output a message that no records matched --->
        <tbody class="infoMessages">
            <tr>
                <td colspan="3">(no resources defined for this facility)</td>
            </tr>
        </tbody>
    </cfif>
    </table>

<!--- ...otherwise (no criteria selected)... --->
<cfelse>
    <p class="needCriteriaMessage">Please select a facility.</p>
</cfif>

</div>

</cf_emgSchedulerFlagSet>
</body>
<cf_EndPage>
</html>