Image Based Forms

From OpenEMR Project Wiki
Revision as of 04:04, 21 February 2011 by Julia Longtin (talk | contribs) (first draft)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation

This is documenting Tony's new image-based form API. Its an additional API similar to the 'object oriented' API that has been deprecated.

New Files

Tony's patch adds several files to OpenEMR, to allow form developers to write graphically intensive forms, with a selections from an optionlist in random locations. We're going to call this the 'image based' approach, to contrast it with the object-oriented approach (which this builds on), and the 'normal' approach.

C_AbstractClickmapModel.php

This file contains the C_AbstractClickmap class. This class extends the Controller class, which is used to control the smarty templating engine.

Variables

The C_AbstractClickmap class extends the Controller class by adding the following variables:

Variable Use
template_dir the directory the template file is stored in.
template_mod the name of the module, for the purposes of finding the template file.

Functions

The C_AbstractClickmap class provides the following function members:

Function Use
createModel Virtual placeholder for a public function, that creates a AbstractClickmapModel derived object (which we refer to as Model). To be supplied later by the class deriving from this one.
getImage Virtual placeholder for a function returning the path to the image backing the form, relative to the template. To be supplied later by the class deriving from this one.
getOptionsLabel Virtual placeholder for a function returning the label to use for drop down boxes on this form. To be supplied later by the class deriving from this one.
getOptionsList Virtual placeholder for a function returning a list of option=>value pairs to be used in dropdown boxes on this form. To be supplied later by the class deriving from this one.
set_context This function sets up the passed in Model object to model the form. It initializes the passed in Model's saveAction, template_dir, image, optionlist, optionsLabel, data, and hideNav members.
default_action This function is called in the case that we are creating a new form. It creates a Model, assigns the smarty value for 'form' from the model, calls set_context to set up the model, then makes smarty generate an html document from the template.
view_action This function is called in the case that we are viewing/editing an existing form. It creates a Model passing in a form_id, assigns the smarty value for 'form' from the model, calls set_context to set up the model, then makes smarty generate an html document from the template.
report_action This function is called in the case that we are rendering a form for a report. It creates a Model, assigns the smarty value for 'form' from the model, calls set_context to set up the model, disables the navigation items, then makes smarty generate an html document from the template.
default_action_process This function is called in the case that we have had form contents submitted. It check to make sure there was a 'process' variable submitted with the form, creates a Model, calls this classes's parent's populate_object to store all the form data in the Model. it then uses the Model's persist to store the contents to the database, and calls addform if the form isn't already part of this encounter.

AbstractClickmapModel.php

This file contains the AbstractClickmapModel class. This class extends the ORDataObject class, to model the contents of an image-based form.

Variables

The AbstractClickmapModel class extends the ORDataObject by adding the following variables:

Variable Use
id The unique identifier of this form.
date The date this form is being saved(?). Initialized to today's date.
pid The unique identifier of the patient this form belongs to. Initialized to $GLOBALS['pid'].
user
groupname
authorized
activity
data The contents of this form. Initialized to an empty value.

Functions

The AbstractClickmapModel class provides the following function members:

Function Use
getTitle This is a virtual function, provided later by the class extending this class. its supposed to return the title of this form.
getCode This is a virtual function, provided later by the class extending this class.
populate Fill in the structure's members with the contents from the database representing the stored form. This implementatio just calls the parent's populate() member.
persist Store the current structure members representing the form into the database.

In addition to these, it provides pairs of get/set functions for setting each of the following variables. each of these functions is named either "set_<VARIABLE>" or "get_<VARIABLE>", where <VARIABLE> is the name of the variable being read/written.

Variable Notes
id The set function has a filter, and aborts if called with a non-numeric or empty value.
pid The set function has a filter, and aborts if called with a non-numeric or empty value.
activity The set function has a filter, and aborts if called with a non-numeric or empty value.
date The set function has a filter, and aborts if called with an empty value.
user The set function has a filter, and aborts if called with an empty value.
data The set function has a filter, and aborts if called with an empty value.

Required or Conventional Behaviors of Form Code

When writing a form utilizing the new 'image based approach', the following is the typical structure and behaviors expected of the form.

C_Form<FORMNAME>.class.php

This file defines the C_Form<FORMNAME> object, where '<FORMNAME>' represents the name of the form. This object extends the C_AbstractClickmap object, from C_AbstractClickmap.php. It is expected to call its parent's initializer, and at a minimum define createModel, getImage, getOptionList and getOptionsLabel functions. This file is expected to include the Form<FORMNAME>.class.php file, so that createModel can instantiate the Form<FORMNAME> object.

createModel

createModel is called by C_AbstractClickmap's members to instantiate a Model object. createModel is expected to instantiate the Form<FORMNAME> class from Form<FORMNAME>.class.php, and return it as a Model.

getImage

getImage is expected to return the path to the backing image relative to the webroot.

getOptionsLabel

getOptionsLabel is supposed to return a label for the optionboxes on the form, as a string.


getOptionList

getOptionList is supposed to return a php array of key:value pairs, to be used as options in dropdown fields on this form.


Form<FORMNAME>.php

This file defines the Form<FORMNAME> class, instantiated to hold the form's data by C_Form<FORMNAME>.php. This class is an extension of the AbstractClickmapModel class. It is required to have a variable member for storing the table name, as well a initializer, a getTitle function, and a getCode function.

TABLE_NAME

The TABLE_NAME variable member stores the name of the table this form persists data in.