Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports = function(arg){
- const http = context.services.get('httpServ');
- return http
- .get({ url: `https://www.cancer.gov/about-cancer/treatment/drugs/${arg}` })
- .then(response => {
- // The response body is encoded as raw BSON.Binary. Parse it to JSON.
- // const ejson_body = EJSON.parse(response.body.text());
- let html = response.body.text();
- html = html.substr(html.indexOf('resize-content')+'resize-content> '.length);
- const data = {};
- data.combination = '';
- if (html.indexOf('<table class="drug-combination">') !== -1) {
- const combination = html.substr(html.indexOf('<table class="drug-combination">')+'<table class="drug-combination">'.length);
- data.combination = combination.substr(0, combination.indexOf('<h2>')).replace(/<caption>(.*)<\/caption>/, '');
- }
- if (html.indexOf('US Brand Name(s)') !== -1) {
- html = html.substr(html.indexOf('column2')+'column2 '.length);
- data.brands = html.substr(0, html.indexOf('</div')).trim();
- }
- data.fdaApproved = 'Unknown';
- if (html.indexOf('FDA Approved') !== -1) {
- html = html.substr(html.indexOf('column2')+'column2 '.length);
- data.fdaApproved = html.substr(0, html.indexOf('</div')).trim();
- }
- html = html.substr(html.indexOf('Use in Cancer')+'Use in Cancer '.length);
- const moreAbout = html.indexOf('<h2>More About');
- data.use = html.substr(0, moreAbout).trim();
- html = html.substr(moreAbout);
- const research = html.indexOf('<h2>Research Results and Related Resources</h2>');
- data.more = '';
- const more = html.substr(html.indexOf('</h2>')+'</h2>'.length);
- if (research !== -1) {
- data.more = more.substr(0, more.indexOf('<h2>'));
- html = html.substr(research+'<h2>Research Results and Related Resources</h2>'.length);
- }
- else if (html.indexOf('<h2>Clinical Trials Accepting Patients') !== -1) {
- data.more = more.substr(0, more.indexOf('<h2>'));
- html = html.substr(research+'<h2>Research Results and Related Resources</h2>'.length);
- }
- else {
- data.more = more.substr(0, more.indexOf('<aside'));
- }
- data.clinicalTrials = '';
- data.relatedResources = '';
- if (html.indexOf('<h2>Clinical Trials Accepting Patients') !== -1) {
- if (research !== -1) {
- data.relatedResources = html.substr(0, html.indexOf('<h2>Clinical Trials Accepting Patients'));
- }
- html = html.substr(html.indexOf('<h2>Clinical Trials Accepting Patients</h2>')+'<h2>Clinical Trials Accepting Patients</h2>'.length);
- data.clinicalTrials = html.substr(0, html.indexOf('<aside'));
- }
- return { data };
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement