Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. exports = function(arg){
  2.   const http = context.services.get('httpServ');
  3.  
  4.   return http
  5.     .get({ url: `https://www.cancer.gov/about-cancer/treatment/drugs/${arg}` })
  6.     .then(response => {
  7.       // The response body is encoded as raw BSON.Binary. Parse it to JSON.
  8.       // const ejson_body = EJSON.parse(response.body.text());
  9.       let html = response.body.text();
  10.       html = html.substr(html.indexOf('resize-content')+'resize-content> '.length);
  11.       const data = {};
  12.  
  13.       data.combination = '';
  14.  
  15.       if (html.indexOf('<table class="drug-combination">') !== -1) {
  16.         const combination = html.substr(html.indexOf('<table class="drug-combination">')+'<table class="drug-combination">'.length);
  17.         data.combination = combination.substr(0, combination.indexOf('<h2>')).replace(/<caption>(.*)<\/caption>/, '');
  18.       }
  19.  
  20.       if (html.indexOf('US Brand Name(s)') !== -1) {
  21.         html = html.substr(html.indexOf('column2')+'column2  '.length);
  22.    
  23.         data.brands = html.substr(0, html.indexOf('</div')).trim();
  24.       }
  25.  
  26.       data.fdaApproved = 'Unknown';
  27.  
  28.       if (html.indexOf('FDA Approved') !== -1) {
  29.         html = html.substr(html.indexOf('column2')+'column2  '.length);
  30.    
  31.         data.fdaApproved = html.substr(0, html.indexOf('</div')).trim();
  32.       }
  33.  
  34.       html = html.substr(html.indexOf('Use in Cancer')+'Use in Cancer     '.length);
  35.       const moreAbout = html.indexOf('<h2>More About');
  36.  
  37.      
  38.       data.use = html.substr(0, moreAbout).trim();
  39.       html = html.substr(moreAbout);
  40.       const research = html.indexOf('<h2>Research Results and Related Resources</h2>');
  41.  
  42.       data.more = '';
  43.  
  44.       const more = html.substr(html.indexOf('</h2>')+'</h2>'.length);
  45.       if (research !== -1) {
  46.         data.more = more.substr(0, more.indexOf('<h2>'));
  47.         html = html.substr(research+'<h2>Research Results and Related Resources</h2>'.length);
  48.       }
  49.       else if (html.indexOf('<h2>Clinical Trials Accepting Patients') !== -1) {
  50.         data.more = more.substr(0, more.indexOf('<h2>'));
  51.         html = html.substr(research+'<h2>Research Results and Related Resources</h2>'.length);
  52.       }
  53.       else {
  54.         data.more = more.substr(0, more.indexOf('<aside'));
  55.       }
  56.  
  57.       data.clinicalTrials = '';
  58.       data.relatedResources = '';
  59.  
  60.       if (html.indexOf('<h2>Clinical Trials Accepting Patients') !== -1) {
  61.         if (research !== -1) {
  62.           data.relatedResources = html.substr(0, html.indexOf('<h2>Clinical Trials Accepting Patients'));
  63.         }
  64.    
  65.         html = html.substr(html.indexOf('<h2>Clinical Trials Accepting Patients</h2>')+'<h2>Clinical Trials Accepting Patients</h2>'.length);
  66.         data.clinicalTrials = html.substr(0, html.indexOf('<aside'));
  67.       }
  68.      
  69.       return { data };
  70.     });
  71. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement