function formatDataToArray (data) {
                var newData = [];

                var cat_list = ['title', 'intro', 'result', 'discussion', 'conclusion', 'other'];   // preferred sorting order

                data.forEach(function (d, i) {
                    var row = [];
                    var dlit = d.evidence.literature_ref; // data literature - now we use the epmc data
                    var pubmedId = dlit.data.pmid || dlit.data.pmcid || dlit.data.id;


                    // 0 - Access level
                    row.push((d.access_level === otConsts.ACCESS_LEVEL_PUBLIC) ? otConsts.ACCESS_LEVEL_PUBLIC_DIR : otConsts.ACCESS_LEVEL_PRIVATE_DIR);

                    // 1 - Disease label
                    row.push(
                        '<a href="/disease/' + (d.disease.efo_info.efo_id.split('/').pop()) + '">'
                        + d.disease.efo_info.label
                        + '</a>'
                    );

                    // 3 - Publication (title, abstract etc)

                    // Authors formatting - now from evidence.literature_ref.data
                    var authorStr = '(No authors provided)';
                    if (dlit.data.authorList) {
                        authorStr = formatAuthor(dlit.data.authorList.author[0]);
                        if (dlit.data.authorList.author.length > 2) {
                            authorStr += ' <i>et al</i>';
                        } else if (dlit.data.authorList.author.length === 2) {
                            authorStr += ' and ' + formatAuthor(dlit.data.authorList.author[1]);
                        }
                        authorStr += '.';
                    }

                    // Abstract
                    if (!dlit.data.title && !dlit.data.abstractText && (!dlit.data.journalInfo || !dlit.data.journalInfo.journal)) {
                        row.push('N/A');
                    } else {
                        var abstractSentences = getMatchedSentences(d);
                        var abstractSection = 'Abstract';
                        var abstractText = dlit.data.abstractText || 'Not abstract supplied.';
                        var abId = pubmedId + abstractSection + '--' + i;
                        var abstract = '<div id=\'' + abId + '\'>' + abstractText + '</div>';

                        var abstractString = '<p class=\'small\'><span onclick=\'angular.element(this).scope().displaySentences("' + abId + '")\'style=\'cursor:pointer\'><i class=\'fa fa-chevron-circle-down\' aria-hidden=\'true\'></i>&nbsp;<span class=\'bold\'>Abstract</span></p>';

                        var title = dlit.data.title || '';

                        if (abstractSentences && abstract) {
                            abstractSentences.map(function (f) {
                                var pos = abstract.indexOf(f.raw);
                                abstract = abstract.replace(f.raw, f.formatted);

                                // If not in the abstract, try the title
                                if (pos === -1) {
                                    pos = title.indexOf(f.raw);
                                    title = title.replace(f.raw, f.formatted);
                                }
                            });
                        }

                        // journal info
                        var journalInfo = (dlit.data.journalInfo.journal.medlineAbbreviation || dlit.data.journalInfo.journal.title || '');
                        // journal reference
                        var jref = dlit.data.journalInfo.volume + '(' + dlit.data.journalInfo.issue + '):' + dlit.data.pageInfo;
                        journalInfo += ' ' + jref;

                        var titleAndSource = '<span class=large><a href="http://europepmc.org/abstract/MED/' + pubmedId + '" target="_blank">' + title + '</a></span>'
                        + '<br />'
                        + '<span class=small>' + authorStr + ' ' + journalInfo + '</span>';

                        // PMID
                        var pmidStr = '<span class="text-lowlight">PMID: ' + pubmedId + '</span>';

                        // matched sentences
                        dlit.mined_sentences.sort(function (a, b) {
                            var a = a.section.toLowerCase();
                            var b = b.section.toLowerCase();

                            var ai = cat_list.length;
                            var bi = cat_list.length;
                            cat_list.forEach(function (li, i) {
                                if (a.substr(0, li.length) === li) {
                                    ai = i;
                                }
                                if (b.substr(0, li.length) === li) {
                                    bi = i;
                                }
                            });

                            return +(ai > bi) || +(ai === bi) - 1;
                        });

                        var sectionCount = countSentences(d.evidence.literature_ref.mined_sentences);
                        var sectionSentences = prepareSectionSentences(d.evidence.literature_ref.mined_sentences);
                        var sectionSentencesSimple = prepareSectionSentencesSimple(d.evidence.literature_ref.mined_sentences);
                        var previousSection = null;

                        var matchedSentences = d.evidence.literature_ref.mined_sentences.map(function (sent) {
                            var section = otUpperCaseFirstFilter(otClearUnderscoresFilter(sent.section));
                            var sentenceString = '';
                            var msId = pubmedId + sent.section + '--' + i;
                            if (section !== 'Title' && section !== 'Abstract') {
                                if (previousSection !== sent.section) {
                                    if (previousSection !== null) { // this is not the first section with matched sentences
                                        sentenceString = sentenceString + '</div>';
                                    }
                                    sentenceString += '<p class=\'small\'><span onclick=\'angular.element(this).scope().displaySentences("' + msId + '")\'style=\'cursor:pointer\'><i class=\'fa fa-chevron-circle-down\' aria-hidden=\'true\'></i>&nbsp;<span class=\'bold\'>' + section + ': </span>' + sectionCount[sent.section];
                                    if (sectionCount[sent.section] === 1) {
                                        sentenceString += ' matched sentence</span></p>';
                                    } else {
                                        sentenceString += ' matched sentences</span></p>';
                                    }
                                    previousSection = sent.section;
                                }

                                sentenceString += '<div id=\'' + msId + '\' style=\'display:none\'><ul style=\'margin-left: 10px;\'>' + sectionSentences[sent.section] + '</ul></div>';
                            }

                            return sentenceString;
                        }).join('') + '</div>';


                        row.push(
                            titleAndSource + '<br/>'
                            + pmidStr + '<br/><br/>'
                            + abstractString
                            + abstract
                            + ' <p class=small>'
                            + (matchedSentences || 'no matches available')
                            + '</p>'
                        );
                    }

                    // 4 - Year
                    // Note we could use something like year = moment(date).year() if needed to parse a date string
                    row.push(dlit.data.pubYear || 'N/A');

                    newData.push(row);
                });

                return newData;
            }
/*
             * Takes the data object returned by the API and formats it
             * to an array of arrays to be displayed by the dataTable widget.
             */
Takes the data object returned by the API and formats it
to an array of arrays to be displayed by the dataTable widget.
Takes the data object returned by the API and formats it to an array of arrays to be displayed by the dataTable widget .
function formatDataToArray (data) {
                var newData = [];
                var cat_list = ['title', 'intro', 'result', 'discussion', 'conclusion', 'other'];   
                data.forEach(function (d, i) {
                    var row = [];
                    var dlit = d.evidence.literature_ref; 
                    var pubmedId = dlit.data.pmid || dlit.data.pmcid || dlit.data.id;
                    row.push((d.access_level === otConsts.ACCESS_LEVEL_PUBLIC) ? otConsts.ACCESS_LEVEL_PUBLIC_DIR : otConsts.ACCESS_LEVEL_PRIVATE_DIR);
                    row.push(
                        '<a href="/disease/' + (d.disease.efo_info.efo_id.split('/').pop()) + '">'
                        + d.disease.efo_info.label
                        + '</a>'
                    );
                    var authorStr = '(No authors provided)';
                    if (dlit.data.authorList) {
                        authorStr = formatAuthor(dlit.data.authorList.author[0]);
                        if (dlit.data.authorList.author.length > 2) {
                            authorStr += ' <i>et al</i>';
                        } else if (dlit.data.authorList.author.length === 2) {
                            authorStr += ' and ' + formatAuthor(dlit.data.authorList.author[1]);
                        }
                        authorStr += '.';
                    }
                    if (!dlit.data.title && !dlit.data.abstractText && (!dlit.data.journalInfo || !dlit.data.journalInfo.journal)) {
                        row.push('N/A');
                    } else {
                        var abstractSentences = getMatchedSentences(d);
                        var abstractSection = 'Abstract';
                        var abstractText = dlit.data.abstractText || 'Not abstract supplied.';
                        var abId = pubmedId + abstractSection + '--' + i;
                        var abstract = '<div id=\'' + abId + '\'>' + abstractText + '</div>';
                        var abstractString = '<p class=\'small\'><span onclick=\'angular.element(this).scope().displaySentences("' + abId + '")\'style=\'cursor:pointer\'><i class=\'fa fa-chevron-circle-down\' aria-hidden=\'true\'></i>&nbsp;<span class=\'bold\'>Abstract</span></p>';
                        var title = dlit.data.title || '';
                        if (abstractSentences && abstract) {
                            abstractSentences.map(function (f) {
                                var pos = abstract.indexOf(f.raw);
                                abstract = abstract.replace(f.raw, f.formatted);
                                if (pos === -1) {
                                    pos = title.indexOf(f.raw);
                                    title = title.replace(f.raw, f.formatted);
                                }
                            });
                        }
                        var journalInfo = (dlit.data.journalInfo.journal.medlineAbbreviation || dlit.data.journalInfo.journal.title || '');
                        var jref = dlit.data.journalInfo.volume + '(' + dlit.data.journalInfo.issue + '):' + dlit.data.pageInfo;
                        journalInfo += ' ' + jref;
                        var titleAndSource = '<span class=large><a href="http://europepmc.org/abstract/MED/' + pubmedId + '" target="_blank">' + title + '</a></span>'
                        + '<br />'
                        + '<span class=small>' + authorStr + ' ' + journalInfo + '</span>';
                        var pmidStr = '<span class="text-lowlight">PMID: ' + pubmedId + '</span>';
                        dlit.mined_sentences.sort(function (a, b) {
                            var a = a.section.toLowerCase();
                            var b = b.section.toLowerCase();
                            var ai = cat_list.length;
                            var bi = cat_list.length;
                            cat_list.forEach(function (li, i) {
                                if (a.substr(0, li.length) === li) {
                                    ai = i;
                                }
                                if (b.substr(0, li.length) === li) {
                                    bi = i;
                                }
                            });
                            return +(ai > bi) || +(ai === bi) - 1;
                        });
                        var sectionCount = countSentences(d.evidence.literature_ref.mined_sentences);
                        var sectionSentences = prepareSectionSentences(d.evidence.literature_ref.mined_sentences);
                        var sectionSentencesSimple = prepareSectionSentencesSimple(d.evidence.literature_ref.mined_sentences);
                        var previousSection = null;
                        var matchedSentences = d.evidence.literature_ref.mined_sentences.map(function (sent) {
                            var section = otUpperCaseFirstFilter(otClearUnderscoresFilter(sent.section));
                            var sentenceString = '';
                            var msId = pubmedId + sent.section + '--' + i;
                            if (section !== 'Title' && section !== 'Abstract') {
                                if (previousSection !== sent.section) {
                                    if (previousSection !== null) { 
                                        sentenceString = sentenceString + '</div>';
                                    }
                                    sentenceString += '<p class=\'small\'><span onclick=\'angular.element(this).scope().displaySentences("' + msId + '")\'style=\'cursor:pointer\'><i class=\'fa fa-chevron-circle-down\' aria-hidden=\'true\'></i>&nbsp;<span class=\'bold\'>' + section + ': </span>' + sectionCount[sent.section];
                                    if (sectionCount[sent.section] === 1) {
                                        sentenceString += ' matched sentence</span></p>';
                                    } else {
                                        sentenceString += ' matched sentences</span></p>';
                                    }
                                    previousSection = sent.section;
                                }
                                sentenceString += '<div id=\'' + msId + '\' style=\'display:none\'><ul style=\'margin-left: 10px;\'>' + sectionSentences[sent.section] + '</ul></div>';
                            }
                            return sentenceString;
                        }).join('') + '</div>';
                        row.push(
                            titleAndSource + '<br/>'
                            + pmidStr + '<br/><br/>'
                            + abstractString
                            + abstract
                            + ' <p class=small>'
                            + (matchedSentences || 'no matches available')
                            + '</p>'
                        );
                    }
                    row.push(dlit.data.pubYear || 'N/A');
                    newData.push(row);
                });
                return newData;
            }
function formatDataToArray ( data ) { var newData = [ ] ; var cat_list = [ 'title' , 'intro' , 'result' , 'discussion' , 'conclusion' , 'other' ] ; data . forEach ( function ( d , i ) { var row = [ ] ; var dlit = d . evidence . literature_ref ; var pubmedId = dlit . data . pmid || dlit . data . pmcid || dlit . data . id ; row . push ( ( d . access_level === otConsts . ACCESS_LEVEL_PUBLIC ) ? otConsts . ACCESS_LEVEL_PUBLIC_DIR : otConsts . ACCESS_LEVEL_PRIVATE_DIR ) ; row . push ( '<a href="/disease/' + ( d . disease . efo_info . efo_id . split ( '/' ) . pop ( ) ) + '">' + d . disease . efo_info . label + '</a>' ) ; var authorStr = '(No authors provided)' ; if ( dlit . data . authorList ) { authorStr = formatAuthor ( dlit . data . authorList . author [ 0 ] ) ; if ( dlit . data . authorList . author . length > 2 ) { authorStr += ' <i>et al</i>' ; } else if ( dlit . data . authorList . author . length === 2 ) { authorStr += ' and ' + formatAuthor ( dlit . data . authorList . author [ 1 ] ) ; } authorStr += '.' ; } if ( ! dlit . data . title && ! dlit . data . abstractText && ( ! dlit . data . journalInfo || ! dlit . data . journalInfo . journal ) ) { row . push ( 'N/A' ) ; } else { var abstractSentences = getMatchedSentences ( d ) ; var abstractSection = 'Abstract' ; var abstractText = dlit . data . abstractText || 'Not abstract supplied.' ; var abId = pubmedId + abstractSection + '--' + i ; var abstract = '<div id=\'' + abId + '\'>' + abstractText + '</div>' ; var abstractString = '<p class=\'small\'><span onclick=\'angular.element(this).scope().displaySentences("' + abId + '")\'style=\'cursor:pointer\'><i class=\'fa fa-chevron-circle-down\' aria-hidden=\'true\'></i>&nbsp;<span class=\'bold\'>Abstract</span></p>' ; var title = dlit . data . title || '' ; if ( abstractSentences && abstract ) { abstractSentences . map ( function ( f ) { var pos = abstract . indexOf ( f . raw ) ; abstract = abstract . replace ( f . raw , f . formatted ) ; if ( pos === - 1 ) { pos = title . indexOf ( f . raw ) ; title = title . replace ( f . raw , f . formatted ) ; } } ) ; } var journalInfo = ( dlit . data . journalInfo . journal . medlineAbbreviation || dlit . data . journalInfo . journal . title || '' ) ; var jref = dlit . data . journalInfo . volume + '(' + dlit . data . journalInfo . issue + '):' + dlit . data . pageInfo ; journalInfo += ' ' + jref ; var titleAndSource = '<span class=large><a href="http://europepmc.org/abstract/MED/' + pubmedId + '" target="_blank">' + title + '</a></span>' + '<br />' + '<span class=small>' + authorStr + ' ' + journalInfo + '</span>' ; var pmidStr = '<span class="text-lowlight">PMID: ' + pubmedId + '</span>' ; dlit . mined_sentences . sort ( function ( a , b ) { var a = a . section . toLowerCase ( ) ; var b = b . section . toLowerCase ( ) ; var ai = cat_list . length ; var bi = cat_list . length ; cat_list . forEach ( function ( li , i ) { if ( a . substr ( 0 , li . length ) === li ) { ai = i ; } if ( b . substr ( 0 , li . length ) === li ) { bi = i ; } } ) ; return + ( ai > bi ) || + ( ai === bi ) - 1 ; } ) ; var sectionCount = countSentences ( d . evidence . literature_ref . mined_sentences ) ; var sectionSentences = prepareSectionSentences ( d . evidence . literature_ref . mined_sentences ) ; var sectionSentencesSimple = prepareSectionSentencesSimple ( d . evidence . literature_ref . mined_sentences ) ; var previousSection = null ; var matchedSentences = d . evidence . literature_ref . mined_sentences . map ( function ( sent ) { var section = otUpperCaseFirstFilter ( otClearUnderscoresFilter ( sent . section ) ) ; var sentenceString = '' ; var msId = pubmedId + sent . section + '--' + i ; if ( section !== 'Title' && section !== 'Abstract' ) { if ( previousSection !== sent . section ) { if ( previousSection !== null ) { sentenceString = sentenceString + '</div>' ; } sentenceString += '<p class=\'small\'><span onclick=\'angular.element(this).scope().displaySentences("' + msId + '")\'style=\'cursor:pointer\'><i class=\'fa fa-chevron-circle-down\' aria-hidden=\'true\'></i>&nbsp;<span class=\'bold\'>' + section + ': </span>' + sectionCount [ sent . section ] ; if ( sectionCount [ sent . section ] === 1 ) { sentenceString += ' matched sentence</span></p>' ; } else { sentenceString += ' matched sentences</span></p>' ; } previousSection = sent . section ; } sentenceString += '<div id=\'' + msId + '\' style=\'display:none\'><ul style=\'margin-left: 10px;\'>' + sectionSentences [ sent . section ] + '</ul></div>' ; } return sentenceString ; } ) . join ( '' ) + '</div>' ; row . push ( titleAndSource + '<br/>' + pmidStr + '<br/><br/>' + abstractString + abstract + ' <p class=small>' + ( matchedSentences || 'no matches available' ) + '</p>' ) ; } row . push ( dlit . data . pubYear || 'N/A' ) ; newData . push ( row ) ; } ) ; return newData ; }
Takes the data object returned by the API and formats it
 to an array of arrays to be displayed by the dataTable widget.
Takes the data object returned by the API and formats it to an array of arrays to be displayed by the dataTable widget .
// preferred sorting order // data literature - now we use the epmc data // 0 - Access level // 1 - Disease label // 3 - Publication (title, abstract etc) // Authors formatting - now from evidence.literature_ref.data // Abstract // If not in the abstract, try the title // journal info // journal reference // PMID // matched sentences // this is not the first section with matched sentences // 4 - Year // Note we could use something like year = moment(date).year() if needed to parse a date string