OpenClinica User Manual/VarsFromHeader

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Introduction[edit | edit source]

On rare occasions you may want to copy some of the contents of the CRF header into your CRF. For example the Site name, or Age at Enrollment. This information is all in the header of the CRF, but most of the time it is not visible, because the header is collapsed. When you click on the link CRF Header Info, a table is displayed with information.

information in the header

How to get it?[edit | edit source]

The way to get this info in your CRF is by using JavaScript. Let's look at the script for getting the Event-name. First you identify the CRF-item that will hold the Event name from the header, in our case we call the item "Event". For the JavaScript to recognise this input as the one we want to work with, we add a div tag to the LEFT_ITEM_TEXT with <div id="event">Event from header</div>

In the RIGHT_ITEM_TEXT we put the script.

XL with JavaScript

How does it work?[edit | edit source]

The script is

<script src="includes/jmesa/jquery.min.js"></script>
jQuery(document).ready(function($) { 
   var fieldEvent = $("#event").parent().parent().find("input");
   fieldEvent.attr("readonly", true);

      var event = $(".tablebox_center").find("tbody:first").children("tr:nth-child(1)").children("td:nth-child(2)").text();
      event = $.trim(event);

What this does is that it finds the input to use, by looking at the parent of the parent of the element we called "event" and then look for an input.
Then it sets this input to readonly.
Then it checks if the input is empty and if so, it goes to first element with class "tablebox_center", which is the box containing the complete header.
From there it looks for the first table body, which contains the elements of interest (this all has to do with the way the header was designed).
For the Event we are almost there: it's on the first row, in the second td.

And the other variables?[edit | edit source]

The other variables can be found in a remarkably similar way:
Event occurrence number: children("tr:nth-child(2)").children("td:nth-child(2)").text(); (but it's not on the image)
Sex: children("tr:nth-child(1)").children("td:nth-child(4)").text();
Age at enrollment: children("tr:nth-child(2)").children("td:nth-child(4)").text();
Study: children("tr:nth-child(3)").children("td:nth-child(2)").text();
Date of birth: children("tr:nth-child(3)").children("td:nth-child(4)").text();
Site: children("tr:nth-child(4)").children("td:nth-child(2)").text();
Person ID: children("tr:nth-child(4)").children("td:nth-child(4)").text();

Remember that you define in your Study-build which of these variables are shown in your header. Furthermore the Date of birth is not in the standard date format, so you cannot treat it as DATA_TYPE DATE.