xml form generator (version from 1/28/2011)
[openemr.git] / contrib / forms / xmlformgen / xslt / common_objects.xslt
blob40a12cfd660224e5e8f5a89f4335582dbe05401c
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!-- Generated by Hand -->
3 <!--
4 Copyright (C) 2011 Julia Longtin <julia.longtin@gmail.com>
6 This program is free software; you can redistribute it and/or
7 Modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 -->
11 <xsl:stylesheet version="1.0"
12 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
13 <!-- this file contains code written in php, used before the <html> tag -->
14 <!-- this code is generated for each date field in the form, to split the time of day from the date in question, for display purposes -->
15 <xsl:template match="field[@type='date']" mode="split_timeofday">
16 <xsl:text disable-output-escaping="yes"><![CDATA[if ($]]></xsl:text>
17 <xsl:value-of select="$fetchrow"/>
18 <xsl:text disable-output-escaping="yes"><![CDATA[[']]></xsl:text>
19 <xsl:value-of select="@name"/>
20 <xsl:text disable-output-escaping="yes"><![CDATA['] != '') {
21 $dateparts = split(' ', $]]></xsl:text>
22 <xsl:value-of select="$fetchrow"/>
23 <xsl:text disable-output-escaping="yes"><![CDATA[[']]></xsl:text>
24 <xsl:value-of select="@name"/>
25 <xsl:text disable-output-escaping="yes"><![CDATA[']);
26 $]]></xsl:text>
27 <xsl:value-of select="$fetchrow"/>
28 <xsl:text disable-output-escaping="yes"><![CDATA[[']]></xsl:text>
29 <xsl:value-of select="@name"/>
30 <xsl:text disable-output-escaping="yes"><![CDATA['] = $dateparts[0];
32 ]]></xsl:text>
33 </xsl:template>
34 <!-- generate php code for fetching form contents, regardless of table format. -->
35 <xsl:template match="table[@type='form']" mode="fetch">
36 <xsl:text disable-output-escaping="yes"><![CDATA[/* Use the formFetch function from api.inc to load the saved record */
37 $]]></xsl:text>
38 <xsl:value-of select="$fetchrow"/>
39 <xsl:text disable-output-escaping="yes"><![CDATA[ = formFetch($table_name, $_GET['id']);
41 ]]></xsl:text>
42 </xsl:template>
43 <xsl:template match="table[@type='extended']" mode="fetch">
44 <xsl:text disable-output-escaping="yes"><![CDATA[/* use the sqlQuery function from sql.inc to load the saved record. */
45 /* if we were passed an ID, pull it in specifically. otherwise, pull in the newest. */
47 /* use the pid from the session to find the newest version of this form. */
48 if ($_GET['id']=='')
50 $sql = 'select * from '.$table_name." where pid='".$pid."'";
51 ]]></xsl:text>
52 <xsl:choose>
53 <xsl:when test="//signature">
54 <xsl:text disable-output-escaping="yes"><![CDATA[ /* use sqlStatement to get multiple rows */
55 $signature_fields = sqlStatement("select * from signatures where formname=']]></xsl:text>
56 <xsl:value-of select="/form/safename"/>
57 <xsl:text disable-output-escaping="yes"><![CDATA[' order by level ASC");
59 $current_level= '';
61 while ($signature_field = sqlFetchArray($signature_fields)) {
62 $current_signature_field=$signature_field['fieldname'];
63 $current_signature_comparison_operator=$signature_field['relationship'];
64 $current_signature_comparison_value=$signature_field['constant'];
65 $last_level=$current_level;
66 $current_level=$signature_field['level'];
67 $current_level_subordinate_relationship=$signature_field['subordinaterelationship'];
68 $current_level_peer_relationship=$signature_field['peerrelationship'];
69 if (strcmp($current_level, $last_level) != 0) {
70 /* we changed levels */
71 if (strcmp($last_level, '') == 0) {
72 /* current is our first level */
73 $sql .= ' AND ( (';
75 else
77 /* current is not our first level */
78 $sql .= ')';
79 if (strcmp($current_level_subordinate_relationship, 'AND') == 0) {
80 $sql .= ' AND';
82 else {
83 $sql .= ' OR';
85 $sql .= ' ( ';
87 $sql .= $current_signature_field.' ';
88 if (strcmp($current_signature_comparison_operator,'not-equal') == 0) {
89 $sql .= '<> ';
91 else
93 $sql .= '= ';
95 $sql .= '''.$current_signature_comparison_value.'' ';
97 else
99 /* same level */
100 $sql .= $current_level_peer_relationship.' ';
101 $sql .= $current_signature_field.' ';
102 if (strcmp($current_signature_comparison_operator,'not-equal') == 0) {
103 $sql .= '<> ';
105 else
107 $sql .= '= ';
109 $sql .= "'".$current_signature_comparison_value."' ";
112 $sql .= ') ) order by effective_date DESC limit 0,1';
114 ]]></xsl:text>
115 </xsl:when>
116 <xsl:otherwise>
117 <xsl:text disable-output-escaping="yes"><![CDATA[
118 $sql .= ' order by date DESC limit 0,1';
119 ]]></xsl:text>
120 </xsl:otherwise>
121 </xsl:choose>
122 <xsl:text disable-output-escaping="yes"><![CDATA[$]]></xsl:text>
123 <xsl:value-of select="$fetchrow"/>
124 <xsl:text disable-output-escaping="yes"><![CDATA[ = sqlQuery($sql);
126 else
128 $]]></xsl:text>
129 <xsl:value-of select="$fetchrow"/>
130 <xsl:text disable-output-escaping="yes"><![CDATA[= sqlQuery('select * from '.$table_name." where pid='".$pid."' and id='".$_GET['id']."' order by date DESC limit 0,1");
132 ]]></xsl:text>
133 </xsl:template>
134 <xsl:template match="table">
135 <xsl:if test="$fetchrow!=''">
136 <xsl:text disable-output-escaping="yes"><![CDATA[/** CHANGE THIS - name of the database table associated with this form **/
137 $table_name = ']]></xsl:text>
138 <xsl:value-of select="./text()" />
139 <xsl:text disable-output-escaping="yes"><![CDATA[';
141 ]]></xsl:text>
142 </xsl:if>
143 </xsl:template>
144 <xsl:template match="acl">
145 <xsl:text disable-output-escaping="yes"><![CDATA[/* Check the access control lists to ensure permissions to this page */
146 $thisauth = acl_check(']]></xsl:text>
147 <xsl:value-of select="@table" />
148 <xsl:text disable-output-escaping="yes"><![CDATA[', ']]></xsl:text>
149 <xsl:value-of select="./text()" />
150 <xsl:text disable-output-escaping="yes"><![CDATA[');]]></xsl:text>
151 <xsl:if test="@table='patients'">
152 <xsl:text disable-output-escaping="yes"><![CDATA[
153 if (!$thisauth) {
154 die($form_name.': Access Denied.');
156 /* perform a squad check for pages touching patients, if we're in 'athletic team' mode */
157 if ($GLOBALS['athletic_team']!='false') {
158 $tmp = getPatientData($pid, 'squad');
159 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
160 $thisauth = 0;
162 ]]></xsl:text>
163 </xsl:if>
164 <xsl:if test="$page='new' or $page='view'">
165 <xsl:text disable-output-escaping="yes"><![CDATA[
166 if ($thisauth != 'write' && $thisauth != 'addonly')
167 die($form_name.': Adding is not authorized.');
168 ]]></xsl:text>
169 </xsl:if>
170 </xsl:template>
171 <!-- default layout object -->
172 <xsl:template match="layout">
173 <xsl:if test="$page='show'">
174 <xsl:text disable-output-escaping="yes"><![CDATA[<!-- display the form's layouts based fields -->
175 <table border='0' cellpadding='0' width='100%'>
176 <?php
177 display_layout_rows(']]></xsl:text>
178 <xsl:value-of select="@name"/>
179 <xsl:text disable-output-escaping="yes"><![CDATA[', $]]></xsl:text>
180 <xsl:value-of select="$fetchrow"/>
181 <xsl:text disable-output-escaping="yes"><![CDATA[);
183 </table>
184 ]]></xsl:text>
185 </xsl:if>
186 <xsl:if test="$page='new' or $page='view'">
187 <xsl:text disable-output-escaping="yes"><![CDATA[<!-- display the form's layouts based fields -->
188 <?php
189 while ($frow = sqlFetchArray($fres)) {
190 $this_group = $frow['group_name'];
191 $titlecols = $frow['titlecols'];
192 $datacols = $frow['datacols'];
193 $data_type = $frow['data_type'];
194 $field_id = $frow['field_id'];
195 $list_id = $frow['list_id'];
196 $currvalue = isset($result[$field_id]) ? $result[$field_id] : '';
198 // Handle a data category (group) change.
199 if (strcmp($this_group, $last_group) != 0) {
200 end_group();
201 $group_seq = substr($this_group, 0, 1);
202 $group_name = substr($this_group, 1);
203 $last_group = $this_group;
204 echo "<div><span class='sectionlabel'><input type='checkbox' id='form_cb_$group_seq' value='1' " .
205 "onclick='return divclick(this,\"$field_id\");'";
206 if (strcmp($check_first_section, 'true')) echo " checked='checked'";
208 // Modified 6-09 by BM - Translate if applicable
209 echo ' />' . xl_layout_label($group_name) . '</span>' . PHP_EOL;
211 echo "<div id='".$field_id."' class='section'>" . PHP_EOL;
212 echo " <table border='0' cellpadding='0'>" . PHP_EOL;
213 /* setting this to false here turns it off for the rest of the sections. */
214 $check_first_section = 'false';
217 // Handle starting of a new row.
218 if (($titlecols > 0 && $cell_count >= $cells_per_row) || $cell_count == 0) {
219 end_row();
220 echo ' <tr>';
223 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
225 // Handle starting of a new label cell.
226 if ($titlecols > 0) {
227 end_cell();
228 echo "<td colspan='$titlecols' valign='top'";
229 echo ($frow['uor'] == 2) ? " class='required'" : " class='label'";
230 if ($cell_count == 2) echo " style='padding-left:10pt'";
231 echo '>';
232 $cell_count += $titlecols;
235 ++$item_count;
237 /* Modified 6-09 by BM - Translate if applicable */
238 if ($frow['title']) echo (xl_layout_label($frow['title']));
240 // Handle starting of a new data cell.
241 if ($datacols > 0) {
242 end_cell();
243 echo "<td colspan='$datacols' class='text'";
244 if ($cell_count > 0) echo " style='padding-left:5pt'";
245 echo '>';
246 $cell_count += $datacols;
249 ++$item_count;
250 generate_form_field($frow, $currvalue);
253 end_group();
256 ]]></xsl:text>
257 </xsl:if>
258 </xsl:template>
259 <!-- default style object -->
260 <xsl:template match="style">
261 <xsl:if test="//layout">
262 <xsl:text disable-output-escaping="yes"><![CDATA[/* set some style related variables for the layouts code */
263 /* if this is true, check the check box on the first section, and none of the others. */
264 $check_first_sections='true';
266 /* how many cells to draw on each row. */
267 $cells_per_row=]]></xsl:text>
268 <xsl:value-of select="@cells_per_row" />
269 <xsl:text disable-output-escaping="yes"><![CDATA[;
270 ]]></xsl:text>
271 </xsl:if>
272 </xsl:template>
273 <xsl:template match="manual" mode="head">
274 <xsl:if test="$page='show' or $page='view' or $page='new'">
275 <xsl:if test="//manual//field[@type='checkbox_list' or @type='exams' or @type='textbox' or @type='textarea' or @type='provider' or @type='date' or @type='textfield' or @type='dropdown_list']">
276 <xsl:text disable-output-escaping="yes"><![CDATA[/* in order to use the layout engine's draw functions, we need a fake table of layout data. */
277 $manual_layouts = array(
278 ]]></xsl:text>
279 <xsl:for-each select="//manual//field[@type='checkbox_list' or @type='exams' or @type='textbox' or @type='textarea' or @type='provider' or @type='date' or @type='textfield' or @type='dropdown_list']">
280 <xsl:text disable-output-escaping="yes"><![CDATA[ ']]></xsl:text>
281 <xsl:value-of select="@name" />
282 <xsl:text disable-output-escaping="yes"><![CDATA[' =>
283 array( 'field_id' => ']]></xsl:text>
284 <xsl:value-of select="@name" />
285 <xsl:if test="@type='checkbox_list'">
286 <xsl:text disable-output-escaping="yes"><![CDATA[',
287 'data_type' => '21',
288 'fld_length' => '0',
289 'description' => ']]></xsl:text>
290 </xsl:if>
291 <xsl:if test="@type='exams'">
292 <xsl:text disable-output-escaping="yes"><![CDATA[',
293 'data_type' => '23',
294 'fld_length' => '0',
295 'description' => ']]></xsl:text>
296 </xsl:if>
297 <xsl:if test="@type='textbox'">
298 <xsl:text disable-output-escaping="yes"><![CDATA[',
299 'data_type' => '2',
300 'fld_length' => '0',
301 'description' => ']]></xsl:text>
302 </xsl:if>
303 <xsl:if test="@type='textarea'">
304 <xsl:text disable-output-escaping="yes"><![CDATA[',
305 'data_type' => '3',
306 'fld_length' => ']]></xsl:text>
307 <xsl:choose>
308 <xsl:when test="@columns">
309 <xsl:value-of select="@columns"/>
310 </xsl:when>
311 <xsl:otherwise>
312 <xsl:text disable-output-escaping="yes"><![CDATA[40]]></xsl:text>
313 </xsl:otherwise>
314 </xsl:choose>
315 <xsl:text disable-output-escaping="yes"><![CDATA[',
316 'max_length' => ']]></xsl:text>
317 <xsl:choose>
318 <xsl:when test="@rows">
319 <xsl:value-of select="@rows"/>
320 </xsl:when>
321 <xsl:otherwise>
322 <xsl:text disable-output-escaping="yes"><![CDATA[4]]></xsl:text>
323 </xsl:otherwise>
324 </xsl:choose>
325 <xsl:text disable-output-escaping="yes"><![CDATA[',
326 'description' => ']]></xsl:text>
327 </xsl:if>
328 <xsl:if test="@type='provider'">
329 <xsl:text disable-output-escaping="yes"><![CDATA[',
330 'data_type' => '10',
331 'fld_length' => '0',
332 'description' => ']]></xsl:text>
333 </xsl:if>
334 <xsl:if test="@type='date' and @name!='effective_date'">
335 <xsl:text disable-output-escaping="yes"><![CDATA[',
336 'data_type' => '4',
337 'fld_length' => '0',
338 'description' => ']]></xsl:text>
339 </xsl:if>
340 <xsl:if test="@type='textfield'">
341 <xsl:text disable-output-escaping="yes"><![CDATA[',
342 'data_type' => '2',
343 'fld_length' => ']]></xsl:text>
344 <xsl:choose>
345 <xsl:when test="@size">
346 <xsl:value-of select="@size"/>
347 </xsl:when>
348 <xsl:otherwise>
349 <xsl:text disable-output-escaping="yes"><![CDATA[10]]></xsl:text>
350 </xsl:otherwise>
351 </xsl:choose>
352 <xsl:text disable-output-escaping="yes"><![CDATA[',
353 'max_length' => ']]></xsl:text>
354 <xsl:value-of select="@maxlength" />
355 <xsl:text disable-output-escaping="yes"><![CDATA[',
356 'description' => ']]></xsl:text>
357 </xsl:if>
358 <xsl:if test="@type='dropdown_list'">
359 <xsl:text disable-output-escaping="yes"><![CDATA[',
360 'data_type' => '1',
361 'fld_length' => '0',
362 'description' => ']]></xsl:text>
363 </xsl:if>
364 <xsl:value-of select="@hoverover" />
365 <xsl:text disable-output-escaping="yes"><![CDATA[',
366 'list_id' => ']]></xsl:text>
367 <xsl:variable name="i" select="@list"/>
368 <xsl:value-of select="//list[@name=$i]/@id" />
369 <xsl:text disable-output-escaping="yes"><![CDATA[' )]]></xsl:text>
370 <xsl:if test="following-sibling::field or ../following-sibling::section/field">
371 <xsl:text disable-output-escaping="yes"><![CDATA[,]]></xsl:text>
372 </xsl:if>
373 <xsl:text disable-output-escaping="yes"><![CDATA[
374 ]]></xsl:text>
375 </xsl:for-each>
376 <xsl:text disable-output-escaping="yes"><![CDATA[ );
377 ]]></xsl:text>
378 </xsl:if>
379 </xsl:if>
380 </xsl:template>
381 <xsl:template match="layout" mode="head">
382 <xsl:if test="$page!='show'">
383 <xsl:text disable-output-escaping="yes"><![CDATA[/* Functions for generating the layout based form fields */
384 function end_cell() {
385 global $item_count, $cell_count;
386 if ($item_count > 0) {
387 echo '</td>';
388 $item_count = 0;
392 function end_row() {
393 global $cell_count, $cells_per_row;
394 end_cell();
395 if ($cell_count > 0) {
396 for (; $cell_count < $cells_per_row; ++$cell_count) echo '<td></td>';
397 echo '</tr>' . PHP_EOL;
398 $cell_count = 0;
402 function end_group() {
403 global $last_group;
404 if (strlen($last_group) > 0) {
405 end_row();
406 echo ' </table>' . PHP_EOL;
407 echo '</div>' . PHP_EOL;
411 /* global variables used by the previous functions */
412 $last_group = '';
413 $cell_count = 0;
414 $item_count = 0;
416 /* Retreive the layout engine based form information. */
417 $fres = sqlStatement('SELECT * FROM layout_options ' .
418 "WHERE form_id = ']]></xsl:text>
419 <xsl:value-of select="@name" />
420 <xsl:text disable-output-escaping="yes"><![CDATA[' AND uor > 0 " .
421 'ORDER BY group_name, seq');
422 ]]></xsl:text>
423 </xsl:if>
424 </xsl:template>
425 <xsl:template match="safename">
426 <xsl:text disable-output-escaping="yes"><![CDATA[/** CHANGE THIS to match the folder you created for this form. **/
427 $form_folder = ']]></xsl:text>
428 <xsl:value-of select="./text()" />
429 <xsl:text disable-output-escaping="yes"><![CDATA[';
431 ]]></xsl:text>
432 </xsl:template>
433 <xsl:template match="RealName">
434 <xsl:text disable-output-escaping="yes"><![CDATA[/** CHANGE THIS name to the name of your form. **/
435 $form_name = ']]></xsl:text>
436 <xsl:value-of select="./text()" />
437 <xsl:text disable-output-escaping="yes"><![CDATA[';
439 ]]></xsl:text>
440 </xsl:template>
441 <xsl:template name="generate_chkdata">
442 <xsl:text disable-output-escaping="yes"><![CDATA[
443 /* define check field functions. used for translating from fields to html viewable strings */
444 ]]></xsl:text>
445 <xsl:if test="//field[@type='date']">
446 <xsl:text disable-output-escaping="yes"><![CDATA[
447 function chkdata_Date(&$record, $var) {
448 return htmlspecialchars($record{"$var"},ENT_QUOTES);
450 ]]></xsl:text>
451 </xsl:if>
452 <xsl:if test="//field[@type='textarea' or @type='textfield']">
453 <xsl:text disable-output-escaping="yes"><![CDATA[
454 function chkdata_Txt(&$record, $var) {
455 return htmlspecialchars($record{"$var"},ENT_QUOTES);
457 ]]></xsl:text>
458 </xsl:if>
459 <xsl:if test="//checkbox">
460 <xsl:text disable-output-escaping="yes"><![CDATA[
461 function chkdata_CB(&$record, $nam, $var) {
462 if (preg_match("/Negative.*$var/",$record{$nam})) {return;} else {return 'checked="checked"';}
464 ]]></xsl:text>
465 </xsl:if>
466 <xsl:if test="//button">
467 <xsl:text disable-output-escaping="yes"><![CDATA[
468 function chkdata_Radio(&$record, $nam, $var) {
469 if (strpos($record{$nam},$var) !== false) {return 'checked="checked"';}
471 ]]></xsl:text>
472 </xsl:if>
473 <xsl:if test="//option">
474 <xsl:text disable-output-escaping="yes"><![CDATA[
475 function chkdata_PopOrScroll(&$record, $nam, $var) {
476 if (preg_match("/Negative.*$var/",$record{$nam})) {return;} else {return 'selected';}
478 ]]></xsl:text>
479 </xsl:if>
480 </xsl:template>
481 </xsl:stylesheet>