0

We currently accept HL7 data through mirth and one of the field we process is date of birth, which we receive in PID.7.1 segment of HL7. Currently we just capture it like -

var vDOB = formatDate(msg['PID.7.1'].toString(),"yyyyMMdd");

How can I validate day , month and year component in the date. And also like it should be greater than today's date.

Thanks

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

1 Answers1

0

You can include a function like this:

var dateChecker = function(dateStr){
    if(date.length !=8 && !date.match('[0-9]{8}')) return false;//should be number and length 8
    var year = date.substr(0,4);
    var month = date.substr(4,2);
    var day = date.substr(6,2);
    var dateObj = new Date(year,month,day);
    if (dateObj == 'Invalid Date') return false;
    if(dateObj.getTime() - Date.now() > 0) return false;//compare epoch to check if date is less than current date/time
    return true;
}

and then dateChecker(vDOB) should return true/false depending on whether the date is valid or invalid.

Parijat Purohit
  • 921
  • 6
  • 16