Created
March 25, 2014 18:03
-
-
Save josh-padnick/9767567 to your computer and use it in GitHub Desktop.
Compute Estimated Gestational Age from Due Date (Javascript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: computeEGA(2014, 4, 14); | |
// Computes the Estimated Gestational Age of a patient based on today's date and her Expected Due Date (EDD) | |
// Sample data | |
var iDueDateYear = 2014; | |
var iDueDateMonth = 4; | |
var iDueDateDay = 14; | |
function computeEGA( iDueDateYear, iDueDateMonth, iDueDateDay ) { | |
var dToday = new Date(); | |
var dDueDate = new Date( iDueDateYear, iDueDateMonth-1, iDueDateDay ); | |
var iDaysUntilDueDate = (dDueDate - dToday) / (1000 * 60 * 60 * 24 ); | |
var iTotalDaysInPregnancy = 40*7; | |
var iGestationalAgeInDays = iTotalDaysInPregnancy - iDaysUntilDueDate; | |
var fGestationalAgeInWeeks = iGestationalAgeInDays / 7; | |
var iEGAWeeks = Math.floor( fGestationalAgeInWeeks ); | |
var iEGADays = ((fGestationalAgeInWeeks % 1)*7).toFixed(0) | |
console.log( iEGAWeeks + " weeks" ); | |
console.log( iEGADays + " days" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment