Template:CPOE Orderset >

Template:CPOE Orderset

    Table of contents
    No headers
    var p = __request.args.pageid ? wiki.getpage(num.cast(__request.args.pageid)) : page;
    var contact, contact_output;  
    
    // order must match what is on the page
    var headings = [ 'keywords', 'site', 'licensing', 'description', 'age', 'specialty', 'contact' ];
    
    var custom_property_prefix = string.trim(global('custom_property_prefix'));
    var cpoe_tags_site         = string.trim(global('cpoe_tags_site'));
    var cpoe_tags_licensing    = string.trim(global('cpoe_tags_licensing'));
    var cpoe_tags_age          = string.trim(global('cpoe_tags_age'));
    var cpoe_tags_specialty    = string.trim(global('cpoe_tags_specialty'));
    var path_contact           = string.trim(global('cpoe_contact_list_path'));
    var heading_site           = string.trim(global('cpoe_contact_list_heading_site'));
    var heading_contact        = string.trim(global('cpoe_contact_list_heading_primary_contact'));
    var heading_email          = string.trim(global('cpoe_contact_list_heading_email'));
    var heading_phone          = string.trim(global('cpoe_contact_list_heading_phone'));
    
    var table_contact          = tableparse2.recordlist(wiki.getpage(path_contact).xml, 'text', "//table" );
    var location               = [], licensing = [], age = [], specialty = [];
    
    // create lists from the page tags (required by the rendering process)
    foreach( var t in map.keys(p.tags) ){
        let t = string.split( t, ":" );
        
        switch( t[0] )
        {
            case (cpoe_tags_site):
                let location ..= [ string.ToCamelCase(string.replace( t[1],'_',' ' )) ];
            case (cpoe_tags_licensing):
                let licensing ..= [ string.ToCamelCase(string.replace( t[1],'_',' ' )) ];
            case (cpoe_tags_age):
                let age ..= [ string.ToCamelCase(string.replace( t[1],'_',' ' )) ];
            case (cpoe_tags_specialty):
                let specialty ..= [ string.ToCamelCase(string.replace( t[1],'_',' ' )) ];
        }
    }
    
    
    // for each location, look up the corresponding details on the Setup/Contact List page
    foreach( var site in location )
    {
        // now, find the row that matches the indicated locations
        foreach( var row in table_contact )
        {
            if( string.compare( string.trim(row[heading_site]), string.trim(site), true ) == 0 )
            { 
                let contact ..= [ {
                    site: row[heading_site],
                    primary_contact: row[ heading_contact ],
                    contact_email: #row[ heading_email ] > 0 ? row[ heading_email] : null,
                    contact_phone: #row[ heading_phone ] > 0 ? row[ heading_phone ] : null
                } ];
            }
        }           
    }
    
    
    // format the location information to be rendered in the table
    foreach( var contact_site in contact )
    {
        let contact_output ..= [ 
            "<p><b>" .. contact_site.site .. "</b><br />" .. 
            contact_site.primary_contact .. "<br />" ..
            (contact_site.contact_email != null ? "<a href=\"mailto:" .. contact_site.contact_email .. "\">" .. contact_site.contact_email .. "</a>" : "") ..
            (contact_site.contact_email && contact_site.contact_phone ? " | " : "") ..
            (contact_site.contact_phone != null ? contact_site.contact_phone : null) ..
            "</p>" 
            ];
    }
    
    // update the page property
    
    var update_property = function( property ){
        var the_result = true;
        var p_api = Deki.Env.PageApi + '/properties';
        var custom_property_prefix = {{ custom_property_prefix }};
    
        $.each( property, function ( key, value ){
            Deki.Api.ReadPageProperty(null, custom_property_prefix + key, function(result) {
                if(result.etag) {    // page property exists, write over it.
                    Deki.Api.UpdatePageProperty(result.href, value, result.etag, function() {
                        // success
                        the_result = true;
                        
                    }, function(result) {
                 alert('An error occurred trying to update the page property. Please alert support (status: ' + result.status + ' - ' + result.text + ')');
                 the_result = false;
             });
         }
            }, function(result) {
                alert('An error occurred trying to read the page property (status: ' + result.status + ' - ' + result.text + ')');
                the_result = false;
            });    
        });
        return the_result;
    };
    
    
    var reloadTags = function( field, new_value ) {
        // update the page (saves re-loading to display the new tags)
        // massage the field name to remove any trailing colon
        var field_name = (field.charAt( field.length - 1 ) == ':') ? field.substring(0, field.length - 1) : field;
        field_name = field_name.split('_')[1];
        $('#orderset_info #' + field_name).text( new_value );
        
        // problem: doesn't return a nice list, AND if we're updating contact info. need to re-load it
        return true;
    };
    
    
    // update the page tags
    var editTags = function(titleID, params, title) {
        dialog2.prototype = new DekiWiki.Dialog();
        function dialog2() {
            // call supserconstructor
            console.log('arguments '+arguments);
            DekiWiki.Dialog.apply( this, arguments );
        }
        
        
        dialog2.prototype.reloadtags = function( field, new_value ) {
            // update the page (saves re-loading to display the new tags)
            // massage the field name to remove any trailing colon
            var field_name = (params.field.charAt( params.field.length - 1 ) == ':') ? params.field.substring(0, params.field.length - 1) : params.field;
            $('#orderset_info #' + params.field).text( new_properties );    
        };
            
        var dialog = new dialog2({
           
            src: '/CHI_custom/popups/tag_selection_dialog.php?titleID=' + titleID + '&title=' + YAHOO.lang.JSON.stringify( title ),
            //src: 'https://infocentral.infoway-inforoute.ca/NYGH_custom/popups/tag_selection_dialog.php?titleID=' + titleID + '&title=' + YAHOO.lang.JSON.stringify( title ),
            width: '380px',
            height: '250px',
            buttons: [
                DekiWiki.Dialog.BTN_OK,
                DekiWiki.Dialog.BTN_CANCEL
            ],
            args: params,
            callback : function(params) {
                // change params so it's what the function expects
                Deki.Plugin.PageTags.BulkSave(params.params, function(data) {
                    Deki.Plugin.PageTags.Refresh('view');      
                });
    //            reloadTags( params.field, params.newtags );
    //            reloadPage();
                alert("You must reload the page to view your changes.");
            }
        });
      
        dialog.render();
        dialog.show();
        return false;
    };
    
    // support editing of fields for users who have edit capability
    var update = false;
    if( wiki.pagepermissions().update )
    {
        dekiapi();
        
        var cpoe_tags_site = string.trim(global('cpoe_tags_site'));
        var cpoe_tags_licensing = string.trim(global('cpoe_tags_licensing'));
        var cpoe_tags_age = string.trim(global('cpoe_tags_age'));
        var cpoe_tags_specialty = string.trim(global('cpoe_tags_specialty'));
        var options_page = wiki.getpage( string.trim(global('cpoe_options_path')) ).path;
    
    
        // grab the lists to use in the Add Orderset form
        var site_list = xml.list( wiki.page(options_page, 'site'), '//li');
        var licensing_list = xml.list( wiki.page(options_page, 'licensing'), '//li');
        var age_list = xml.list( wiki.page( options_page, 'age groups'), '//li');
        var specialty_list = xml.list( wiki.page(options_page, 'specialties'), '//li');
    
        // grab the desired sort-order for the lists (alphabetical or as-entered)
        var sort = {
            site : bool.cast(xml.text( wiki.page(options_page, 'sort-site'))),
            licensing : bool.cast(xml.text( wiki.page(options_page, 'sort-licensing'))),
            age : bool.cast(xml.text( wiki.page(options_page, 'sort-age groups'))),
            specialty : bool.cast(xml.text( wiki.page(options_page, 'sort-specialties')))
        };
        
        let age_list = (sort.age ? list.sort(age_list) : age_list);
          
        
    <script type="text/javascript">"
        var headings = " .. json.emit( headings ) .. ";
        var page_title = " .. json.emit( page.title ) .. ";
        var parent_path = " .. json.emit( page.parent.path ) .. ";
        
        $(document).ready( function() {
        // clean up the table CSS and add the edit column
        $('#orderset_info').css('border-right','none');
        $('#orderset_info').css('border-top','none');
        $('#orderset_info').css('border-bottom','none');    
        $('#orderset_info tr').each( function() {
            $(this).append('<td></td>');
        });
        
        $('#orderset_info tr td:last-child').each( function( index, value ) {
            $(this).attr('id','edit_' + headings[index]);
            $(this).css('width','30px');
            $(this).css('border','none');
            $(this).click( function() {
                switch( $(this).attr('id') )
                {
                    case( 'edit_keywords' ):
                        new_properties = prompt( 'Please enter the desired keywords (separate each entry with a comma and a space): ', $('#orderset_info #keywords').text() );
                        if(new_properties) {
                            if( update_property({'cpoe_keywords' : new_properties }) ) $('#orderset_info #keywords').text( new_properties );
                        }
                        break;
                      
                    case( 'edit_site' ):
                        var title = 'Set Location(s)';
                        var params = {
                            prompt: 'Identify the location(s) associated with this order set: ',
                            lookup: " ..json.emit( cpoe_tags_site .. ':' ).. ",
                            list: " ..json.emit( site_list ).. "
                        };
                        editTags( Deki.PageId, params, title );
                        break;
                      
                    case( 'edit_licensing' ):
                        var title = 'Set Licensing';
                        var params = {
                            prompt: 'Identify the licensing associated with this order set: ',
                            lookup: " ..json.emit( cpoe_tags_licensing .. ':' ).. ",
                            list: " ..json.emit( licensing_list ).. "
                        };
                        editTags( Deki.PageId, params, title );
                        break;
                      
                    case( 'edit_description' ):
                        new_properties = prompt( 'Please enter the desired description: ', $('#orderset_info #description').text() );
                        if(new_properties) {
                            if( update_property( {'cpoe_description' : new_properties }) ) $('#orderset_info #description').text( new_properties );
                        }
                        break;
                      
                    case( 'edit_age' ):
                        var title = 'Set Age Group(s)';
                        var params = {
                            prompt: 'Identify the age(s) associated with this order set: ',
                            lookup: " ..json.emit( cpoe_tags_age .. ':' ).. ",
                            list: " ..json.emit( age_list ).. "
                        };
                        editTags( Deki.PageId, params, title );
                        break;
                      
                    case( 'edit_specialty' ):
                        var title = 'Set Specialty(ies)';
                        var params = {
                            prompt: 'Identify the specialty(ies) associated with this order set: ',
                            lookup: " ..json.emit( cpoe_tags_specialty .. ':' ).. ",
                            list: " ..json.emit( specialty_list ).. "
                        };
                        editTags( Deki.PageId, params, title );
                        break;
                      
                    case( 'edit_contact' ):
                         alert('Please modify the global order set contact list found in the Setup folder.');
                         break;
                    default:
                }
            });
        });
    
        
        $('#orderset_info tr').hover(function() {
            $(this).children().last().addClass('hover_edit');
        }, function() {
            $(this).children().last().removeClass('hover_edit');
        });
        
        var reload_page = function() {
     //       window.location.reload(true);
     alert('Please note: you must reload the current page to see your changes.');
            // return false or else the edit dialog won't disappear
            return false;
        };
        
        var store_properties = function( page_name, page_path, props, custom_property_prefix ) {
            var p_api = MindTouch.Deki.GetPageApi(Deki.Env.SiteApi, page_path + '/' + page_name);
            var currentProps = props;
            
            if($.isPlainObject(currentProps))
            {
                var the_result = true;
    
                $.each( currentProps, function( key, value ) {
                    var prop_name = custom_property_prefix + key;
                
                    $.ajax({
                        // add parameter to only list properties that match the requested name
                        // add parameters to convert response to JSON and
                        async: false,
                        url: p_api + '/properties?dream.out.format=json&names=' + Deki.url.encode(prop_name),    
                        type: 'GET',
                        cache: false,
                        complete: function(xhr) {
                            
                            if(xhr.status == 200)
                            {
                                // property exists already
                                var data = eval('(' + xhr.responseText + ')');
      
                                // read property href and ETag
                                var href = data.property && data.property.contents['@href'];
                                var etag = data.property && data.property['@etag'];
                        
                                // check if the value was found
                                if(href && etag)
                                {
                                    // send AJAX request to update the property
                                    $.ajax({
                                        url: href + '?dream.in.verb=PUT',
                                        type: 'POST',
                                        data: value,
                                        contentType: 'text/plain',
                                        processData: false,
          
                                        // add the 'ETag' header which checks if the property was modified since we read it
                                        beforeSend: function(xhr) {
                                        
                                            // NOTE: remove content-encoding added by Apache mod_deflate
                                            etag = etag.replace('-gzip', '').replace('-bzip2', '').replace('-zip', '');
                                            xhr.setRequestHeader('ETag', etag);
                                            return true;
                                        },
                                        complete: function(xhr) {
                                            if(xhr.status == 200) {
                                                // property successfully updated
                                                the_result = true;
                                            } else {
                                                alert('Error: unable to update the property (' + property_name + '). It may no longer exist (try recreating it), it may have been changed, or you don\\'t have permission to update it.');
                                            }
                                        }
                                    });
                                } else {
                                    $.ajax({
                                        url: p_api + '/properties',
                                        type: 'POST',
                                        data: value,
                                        contentType: 'text/plain',
                                        processData: false,
           
                                        beforeSend: function(xhr) {
                                        
                                            xhr.setRequestHeader('Slug', property_name);
                                            return true;
                                        },
           
                                        complete: function(xhr) {
                                            if(xhr.status == 200) {
                                                // property successfully created
                                                the_result = true;
                                            } else {
                                                alert('Error: unable to create the property (' + property_name + '). It may already exist (try deleting it) or you don\\'t have permission to create it.');
                                            }
                                        }
                                    });
                                }
                            } else {
                                // don't have permission to read property
                                alert('Error: you don\\'t have permission to read the property (' + property_name + ') and so can\\'t determine whether it already exists.');
                            }
                        }   
                    });
                });
            }
        };
        
            
    });    
        
    "</script>
    
    }
    
    .hover_edit {
        background: URL(/skins/beech/pale/images/icon-edit-page.gif) no-repeat 50% 50%;
    }
    
    .hover_edit:hover {
        cursor: pointer;
    }
    
    #orderset_info th {
        vertical-align: top;
    }
    Keywords {{ page.properties.cpoe_keywords.text }}
    Site {{ template('utilities/list', [ location ]) }}
    Licensing {{ template('utilities/list', [ licensing] ) }}
    Description {{ page.properties.cpoe_description.text }}
    Age Group(s) {{ template('utilities/list', [ age ] ) }}
    Specialty(ies) {{ template('utilities/list', [ specialty ] ) }}
    Contact {{ template("utilities/list", [ contact_output ] ) }}

     

    {{page.id}}

    Files (0)

     

    Comments (0)

    You must login to post a comment.