Пример #1
0
function dataSetupAge(selectedData) {
  // calculate age based on date of first visit
  let personVisits = _.supergroup(selectedData.visit_occurrence, 'PERSON_ID');
  let ages = {};
  selectedData.person.forEach(p => {
    let person = personVisits.lookup(p.PERSON_ID);
    if (person) {
      let firstVisit = new Date(
            _.chain(person.records).map('VISIT_START_DATE')
                .map(d=>d.replace(/(....)(..)(..)/,"$1-$2-$3"))
                .sort().first().value());
      let age = Math.floor(
        (firstVisit - 
        new Date(`${p.YEAR_OF_BIRTH}-${p.MONTH_OF_BIRTH}-${p.DAY_OF_BIRTH}`))
        / (1000 * 60 * 60 * 24 * 365.25));
      ages[p.PERSON_ID] = age;
      p.age = age;
    }
  });

  let prepd = [];
  prepd = 
    _.chain(selectedData)
      .map((recs, label)=>{
          return _.chain(recs).map(rec=>{
                      if (typeof ages[rec.PERSON_ID] !== "undefined") {
                        return { age: ages[rec.PERSON_ID], label: label };
                      }
                   }).compact().value();
      })
      .flatten()
      .value()
  prepd.push(... 
    _.supergroup(selectedData.person, ['age', 'PERSON_ID'])
     .leafNodes()
     .map(d=>{return {label:'patient_count',age:d.parent.valueOf()}}));

  let pcrecs = _.supergroup(prepd.filter(d=>typeof d.age !== "undefined"), ['age','label'])
    .map(age=>{
      let pcrec={age:age.valueOf()}; 
      let patcnt = age.lookup('patient_count').records.length;
      age.children.forEach(lbl=>{
        pcrec[lbl]=lbl.records.length
        if (lbl.toString() !== 'patient_count') {
          pcrec[lbl]=Math.round(lbl.records.length / patcnt);
        }
      });
      return pcrec
    });
  return pcrecs;
}
Пример #2
0
function dataSetup(selectedData) {
  if (LINEBY === 'age')
    return dataSetupAge(selectedData);
  let prepd = [];
  prepd = 
    _.chain(selectedData)
      .map((recs, label)=>{
        if (label === "condition_occurrence") // manufacture data quality problem
                                              // delete conditions in last quarter 2008
          recs = recs.filter(
            d => !d.CONDITION_START_DATE.match(/^20081/) ||
                 d.PERSON_ID % 2);
        return recs.map(rec=>{return {
          month: extractDate(rec,label),
          label: label
        }});
      })
      .flatten()
      .value()
  prepd.push(... 
    _.supergroup(selectedData.visit_occurrence,
     [d=>new Date(d.VISIT_START_DATE.replace(/(....)(..)(..)/,"$1-$2-01")),
       'PERSON_ID'])
     .leafNodes().map(d=>{return {label:'patient_count',month:new Date(d.parent)}}));

  let pcrecs = _.supergroup(prepd, ['month','label'])
    .map(month=>{
      //let pcrec={month:month.val}; // supergroup-es6
      let pcrec={month:new Date(month)}; 
      month.children.forEach(lbl=>{
        pcrec[lbl]=lbl.records.length
      });
      return pcrec;
    });
  return pcrecs;
}
Пример #3
0
function colStats(recs, col) {
  let sg = _.supergroup(recs,col);
  //let missing = 
  return {distinctVals: sg.length};
}