Talk:OpenClinica User Manual/VarsFromHeader

Great article, regarding the last line about the date of birth not being usable, I adapted an example from [1] to convert the header date format yyyy-MM-dd to the OpenClinica format dd-MMM-yyyy, and added it as an optional chunk of code. There's a regex to pick up the event date too.

I was also thinking that if you happen to not be in the habit of using the Person ID field for anything important, it could be used to kludge some study arm logic. For example, a patient on a Hepatitis C Study (HPS), Arm A (A), study number 103 (103): HPS103A; which can then be trimmed to return just the 'A' for the sake of a CRF field which shows questions only relevant to subjects on Arm A. Below I've added an optional chunk for that trim, adapted from [2].

[1] http://www.webdevelopersnotes.com/tips/html/javascript_date_and_time.php3 [2] http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/344850/get-the-last-character-of-string-with-javascript

jQuery(document).ready(function($) {   var fieldEvent = $("#event").parent.parent.find("input");   fieldEvent.attr("readonly", true);   if(fieldEvent.val===""){      var event = $("#CRF_infobox_open").find("table :first").children("tr:nth-child(2)"). find("table:first").find("tbody:first").children("tr:nth-child(1)").children("td:nth-child(2)").text;      event = $.trim(event);

// 1 optional chunk for reformatting event date or date of birth to OpenClinica date format, delete if target is not event date or date of birth.

var event = event.match( new RegExp( "[0-9]{4}-[0-9]{2}-[0-9]{2}", "" ),"$1"); var d = new Date(event); var d_day = d.getDate; var d_mon = d.getMonth; var d_year = d.getFullYear; var d_months = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); var event = d_day + "-" + d_months[d_mon] + "-" + d_year;

// 1 end optional chunk for date formatting.

// 2 optional chunk for returning the last character of person ID, if you're using it to designate what study arm a subject belongs to.

var event = event.charAt( event.length-1 );

// 2 end optional chunk for last character of person ID.

fieldEvent.val(event); fieldEvent.change; } });

Lindsay.stevens (discuss • contribs) 01:31, 17 December 2012 (UTC)