3 * Copyright Medical Information Integration,LLC info@mi-squared.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * @file C_AbstractClickmap.php
11 * @brief This file contains the C_AbstractClickmap class, used to control smarty.
14 /* for encounter','fileroot','pid','srcdir','style','webroot']
15 * remember that include paths are calculated relative to the including script, not this file.
16 * to lock the path to this script (so if called from different scripts) use the dirname(FILE) variable
18 require_once(dirname(__FILE__
).'/../globals.php');
20 /* For the addform() function */
21 require_once ($GLOBALS['srcdir'] . '/forms.inc');
24 * @class C_AbstractClickmap
26 * @brief This class extends the Controller class, which is used to control the smarty templating engine.
29 abstract class C_AbstractClickmap
extends Controller
{
31 * the directory to find our template file in.
38 * @brief Initialize a newly created object belonging to this class
41 * template module name, passed to Controller's initializer.
43 function __construct($template_mod = "general") {
44 parent
::__construct();
45 $returnurl = 'encounter_top.php';
46 $this->template_mod
= $template_mod;
47 $this->template_dir
= $GLOBALS['fileroot'] . "/interface/clickmap/template/";
48 $this->assign("DONT_SAVE_LINK",$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl");
49 $this->assign("FORM_ACTION", $GLOBALS['webroot']);
50 $this->assign("STYLE", $GLOBALS['style']);
54 * @brief Override this abstract function with your implementation of createModel.
57 * An optional id of a form, to populate data from.
60 * An AbstractClickmapModel derived Object.
62 abstract public function createModel($form_id="");
65 * @brief Override this abstract function with your implememtation of getImage
67 * @return The path to the image backing this form relative to the webroot.
69 abstract function getImage();
72 * @brief Override this abstract function to return the label of the optionlists on this form.
74 * @return The label used for all dropdown boxes on this form.
76 abstract function getOptionsLabel();
79 * @brief Override this abstract functon to return a hash of the optionlist (key=>value pairs).
81 * @return A hash of key=>value pairs, representing all the possible options in the dropdown boxes on this form.
83 abstract function getOptionList();
86 * @brief set up the passed in Model object to model the form.
88 private function set_context( $model ) {
89 $root = $GLOBALS['webroot'] . "/interface/clickmap";
90 $model->saveAction
= $GLOBALS['webroot'] . "/interface/forms/" . $model->getCode() . "/save.php";
91 $model->template_dir
= $root . "/template";
92 $model->image
= $this->getImage();
93 $optionList = $this->getOptionList();
94 $model->optionList
= $optionList != null ?
json_encode($optionList) : "null";
95 $optionsLabel = $this->getOptionsLabel();
96 $model->optionsLabel
= isset($optionsLabel) ?
"'" . $optionsLabel . "'" : "null";
98 $data = $model->get_data();
99 $model->data
= $data != "" ?
"'" . $data . "'" : "null";
100 $model->hideNav
= "false";
104 * @brief generate an html document from the 'new form' template
106 * @return the result of smarty's fetch() operation.
108 function default_action() {
109 $model = $this->createModel();
110 $this->assign("form", $model);
111 $this->set_context($model);
112 return $this->fetch($this->template_dir
. $this->template_mod
. "_new.html");
116 * @brief generate an html document from the 'new form' template, populated with form data from the passed in form_id.
119 * The id of the form to populate data from.
121 * @return the result of smarty's fetch() operation.
123 function view_action($form_id) {
124 $model = $this->createModel($form_id);
125 $this->assign("form",$model);
126 $this->set_context($model);
127 return $this->fetch($this->template_dir
. $this->template_mod
. "_new.html");
131 * @brief generate a fragment of an HTML document from the 'new form' template, populated with form data from the passed in form_id.
134 * The id of the form to populate data from.
136 * @return the result of smarty's fetch() operation.
138 function report_action($form_id) {
139 $model = $this->createModel($form_id);
140 $this->assign("form",$model);
141 $this->set_context($model);
142 $model->hideNav
= "true";
143 return $this->fetch($this->template_dir
. $this->template_mod
. "_new.html");
147 * @brief called to store the submitted form's contents to the database, adding the form to the encounter if necissary.
149 function default_action_process() {
150 if ($_POST['process'] != "true") {
153 $this->model
= $this->createModel($_POST['id']);
154 parent
::populate_object($this->model
);
155 $this->model
->persist();
156 if ($GLOBALS['encounter'] == "") {
157 $GLOBALS['encounter'] = date("Ymd");
159 if(empty($_POST['id'])) {
160 addForm($GLOBALS['encounter'],
161 $this->model
->getTitle(),
163 $this->model
->getCode(),
165 $_SESSION['userauthorized']
167 $_POST['process'] = "";