Using Ruby On Rails™ to Develop A Web Interface: A Research-Based Exemplar with a Computerized Physical Activity Reporter Jacquelyn W. BLAZ and Patricia F. PEARCE University of Utah College of Nursing, Salt Lake City, UT, USA Abstract. The world is becoming increasingly web-based. Health care institutions are utilizing the web for personal health records, surveillance, communication, and education; health care researchers are finding value in using the web for research subject recruitment, data collection, and follow-up. Programming languages, such as Java, require knowledge and experience usually found only in software engineers and consultants. The purpose of this paper is to demonstrate Ruby on Rails™ as a feasible alternative for programming questionnaires for use on the web. Ruby on Rails™ was specifically designed for the development, deployment, and maintenance of database-backed web applications. It is flexible, customizable, and easy to learn. With a relatively little initial training, a novice programmer can create a robust web application in a small amount of time, without the need of a software consultant. The translation of the Children’s Computerized Physical Activity Reporter (C-CPAR) from a local installation in Microsoft Access to a web-based format utilizing Ruby on Rails™ is given as an example. Keywords. Internet, Questionnaires, Database, Software Design 1.Introduction
The world is becoming more and more web-based, including health care institutions. Web-based applications are becoming more prevalent in healthcare, including the use of web-based personal health records (PHR), such as MyHealtheVet [1], surveillance [2], information management [3], communication across healthcare sites [4], and education [5]. Clinicians and educators are increasingly involved in web-based professional activities, and health care research is also utilizing the web in order to recruit subjects, expedite data collection, and for follow-up [6]. A common, proven and well-accepted solution for programming database-backed web pages, such as those used in research, education, and clinical practice, is to utilize the Java programming language with PHP. However, programming in Java comes with challenges in knowledge, programming experience, and time commitment, and often requires an outside consultant which can be costly. Implementing a Java-based format can be time-consuming and frustrating for the novice. An alternative solution that is as stable and secure as Java, but may be less challenging and less time-intensive for the novice to implement is Ruby on Rails™ [7]. 1.1. Ruby on RailsTM Ruby is “a dynamic, open source programming language with a focus on simplicity and productivity”[8] developed by Yukihiro Matsumoto. He developed an object-oriented programming language that is terse, not verbose like Java. Fans of the Ruby language call it “a beautiful, artful language,” yet it is functional and practical [9]. Ruby was publicly released in 1995, the same year as Java. Unlike Java, Ruby didn’t receive “mass acceptance”in the larger programming community until after David Heinemeier
Hansson released Ruby on Rails™ (RoR) in 2005 [9, 10]. RoR is a framework written in Ruby. It is a collection of libraries, meaning a set of pre-programmed modules, written in the overarching software, Ruby. RoR has been designed specifically for programming database-backed web applications. MySQL, PostgreSQL, Oracle, and DB2 are among the commonly used databases that are easily integrated interfaces developed with RoR. Additionally, RoR is effectively used with a variety of webservers, including Apache [7]. RoR makes development, deployment, and maintenance of web applications easier, especially database-backed web applications. RoR has become the language of choice for new Web 2.0 applications [7]. RoR is flexible and completely customizable. Moreover, it is easy to learn. With a bit of programming knowledge and a familiarity of HTML, a person can be developing web applications within a few days. 1.2. Children’s Computerized Physical Activity Reporter The Children’s Computerized Physical Activity Reporter (C-CPAR) is a computerized questionnaire designed for self-report of their activities by children and adolescents [11]. The C-CPAR was developed with children eleven to fifteen years old, emphasizing children’s, rather than adults’, understanding of physical activity, and children’s specific needs for self-reporting their activities. Description of this process is provided elsewhere [12]. All information is completed using drop-down menus, including an extensive database of activity items (N=160), time parameters (N=8), and report-generating mechanism. The tool was developed using a local installation of Microsoft Access— a proprietary relational database available to most educators, clinicians, and researchers. The C-CPAR was utilized to measure self-reported physical activity in junior high school students during a recent research study [13]. For this study, a copy of the C-CPAR in Microsoft Access was installed locally on ten laptops that were used by the students for questionnaire completion. At the end of the study, a cumbersome process to concatenate data from the 10 laptops was developed, to move data into SAS statistical software [14] for analysis. This unwieldy process inspired the research team to develop a web-based application of the C-CPAR that would allow subjects to enter data into a centralized database at the same time, from anywhere with a network connection via the World Wide Web. 2. Objective This paper will present RoR as a feasible alternative for translating a questionnaire for use on the World Wide Web, using a recently completed transfer of the Children’s Computerized Physical Activity Reporter from Microsoft Access will be used as an example. 3. Materials and Methods 3.1. Programmer The programmer for this study is a statistician with minimal training in computer software programming beyond Visual Basic for Applications within Access and statistical programs, such as the SAS system. She attended a seven-day intensive course to learn Ruby and RoR that was designed with the novice programmer in mind [15].
After this short course, the programmer was sufficiently prepared to create the web based application. 3.2. Translation of the Application The Access-based C-CPAR was carefully designed with children, for children, and fidelity to the original design parameters was critical in the transfer from the original in Access to web-based system. Cascading style sheets utilizing the background colors, font styles, and font colors from the C-CPAR were developed to make style uniform across the three pages of the questionnaire. The structure of the individual pages of the questionnaire was recreated using HTML within RoR. Initially, scaffolds in RoR were used to generate the HTML for each page. A scaffold is a standard framework generated by RoR with a portion of the functionality of the web application pre-built [7]. For example, hyperlinks are automatically created that will support (a) creation of a new record in the database, (b) subsequent editing of that record, or (c) record deletion. Pages created using scaffolds have a simple layout that is generic and functional, but not aesthetically pleasing. Therefore, the HTML generated by the scaffolds in this application was edited to create pages that were similar in layout to the original C-CPAR. Thus, pages with no standard formatting and text boxes for data input were changed to have the same formatting as seen in the original Microsoft Access application with drop down menus for data input. This process ensured the fidelity of the original design parameters. Validation routines were used to ensure the integrity of the data being entered into the C-CPAR. RoR includes a built-in collection of methods, or commands, for validation of data, including initiation of constraints. For example, validation is done at the record level, i.e. on creation of the record or update of the record. These provide automatic constraints, disallowing a record to be entered into the database without certain key elements, such as age or birth date. Custom validations were also created in order to ensure high level data integrity as data were entered into each field on a page. Thus, for a field requiring identification of whether the user was a boy or girl, the only values that could be entered into the gender field were “boy”and “girl.”Customized and clear error messages were written to notify a user when one of these situations occurred so that corrections could be made by the user at the time of data entry. The final application was tested for compatibility on both Microsoft Windows and Mac OS X operating systems with multiple browsers, including Internet Explorer and Firefox. No compatibility issues were encountered during testing. 4. Results The C-CPAR was successfully and easily translated from a local, Microsoft Access application to a web-based application written in RoR. Approximately 40 hours of programming time were needed for a novice programmer to complete the translation. This is significantly less than if JAVA were chosen as the programming language. Tight fidelity to the original design format and intrinsic processes (e.g., drop-down menus) was maintained easily utilizing cascading style sheets and basic HTML programming, tools that are built into the RoR framework. Constraints were integrated without problem utilizing built in and custom validation routines in RoR.
5. Discussion Translation of the C-CPAR was easily accomplished using RoR with a reasonably small amount of time invested, including training time and programming time. Issues of security and authentication need to be addressed before the web-based C-CPAR can go live. However, it is expected that this process will be quick and not beyond the capabilities of the novice programmer. Deployment of the web-based C-CPAR will allow a wide range of users to access it. Because it is web-based, it is not necessary to install software locally, allowing use from any computer with access to the internet. Future updates to the database or the design of the questionnaire will be handled centrally. Thus, it will not be necessary to update local installations on multiple machines. Healthcare is beginning to realize the potential of RoR as a feasible solution for webbased applications. A recent PubMed search for “Ruby on Rails”yielded three articles concerning the development of web-based solutions in health care, as compared to a search for “JAVA programming web” that yields 122 articles. As awareness of the simplicity of RoR for the novice developer spreads, more web applications will be seen in the healthcare arena. 6. Conclusion RoR is an elegant programming language that is easy to learn and easy to implement. With increasing use of web-based questionnaires and other web-based tools, RoR can be used to expedite movement of or development of questionnaires and screening tools to a web-based format – easily, quickly, and with minimal cost. A selection of databases can be used with RoR to support a robust overall application. References [1] [2]
[3] [4]
[5] [6] [7] [8] [9] [10] [11]
[12] [13] [14]
http://www.health-evet.va.gov/ (last accessed Jan 30, 2009). Wang Y, Tao Z, Cross PK, Le LH, Steen PM, Babcock GD, et al. Development of a web-based integrated birth defects surveillance system in New York State. J Public Health Manag Pract2008 NovDec;14(6):E1-E10. Mandal A, Asthana AK, Aggarwal LM. Development of an electronic radiation oncology patient information management system. J Cancer Res Ther2008 Oct-Dec;4(4):178-85. Arnold CW, Bui AA, Morioka C, El-Saden S, Kangarloo H. Informatics in radiology: A prototype Web-based reporting system for onsite-offsite clinician communication. Radiographics2007 JulAug;27(4):1201-11. Demir SS. Interactive cell modeling web-resource, iCell, as a simulation-based teaching and learning tool to supplement electrophysiology education. Ann Biomed Eng2006 Jul;34(7):1077-87. http://www.project-redcap.org/ (last accessed Jan 30, 2009). Thomas D, Hansson D, Breedt L, Clark M, Davidson JD, Gehtland J, et al. Agile web development with rails. 2nd ed. Raleigh, NC: The Pragmatic Bookshelf; 2007. http://www.ruby-lang.org/en/ (last accessed Jan 30, 2009). http://www.ruby-lang.org/en/about/ (last accessed Jan 30, 2009). http://www.rubyonrails.org/ (last accessed Jan 30, 2009). Pearce PF, Williamson J, Harrell JS, Wildemuth BM, Solomon P. The children's computerized physical activity reporter: children as partners in the design and usability evaluation of an application for selfreporting physical activity. Comput Inform Nurs2007 Mar-Apr;25(2):93-105. Pearce PF, Harrell JS, McMurray RG. Middle-school children's understanding of physical activity: "if you're moving, you're doing physical activity". J Pediatr Nurs2008 Jun;23(3):169-82. Pearce PF, Reel JJ. The Children's Computerized Physical Activity Reporter (C-CPAR): Reliability and Validity. NIH/NINR; 2007. SAS [computer program]. Version 9.1.3 ed. Cary (NC): SAS Institute Inc.; 2002-2003.
[15] http://www.bignerdranch.com/classes/ruby_ruby_on_rails.shtml (last accessed January 30, 2009).
Email address for correspondence
[email protected]