Exemple #1
0
    def do_GET(self):

        client = OpenFDAClient()
        HTML = OpenFDAHTML()
        parser = OpenFDAParser()

        if self.path == '/':
            html = HTML.get_main_page()
            self.send_response(200)

        elif 'listDrugs' in self.path:
            limit = self.path.split('=')[1]
            events = client.get_event(limit)
            medicamentos = parser.get_drug(events)
            html = HTML.drug_page(medicamentos)
            self.send_response(200)

        elif 'searchDrug' in self.path:
            drug = self.path.split('=')[1]
            events = client.get_all_drugs(drug)
            com_num = parser.get_com_num(events)
            html = HTML.drug_page(com_num)
            self.send_response(200)

        elif 'listCompanies' in self.path:
            limit = self.path.split('=')[1]
            events = client.get_event(limit)
            com_num = parser.get_com_num(events)
            html = HTML.drug_page(com_num)
            self.send_response(200)

        elif 'searchCompany' in self.path:
            com_num = self.path.split('=')[1]
            events = client.get_medicinalproduct(com_num)
            medicinalproduct = parser.get_drug(events)
            html = HTML.drug_page(medicinalproduct)
            self.send_response(200)

        elif 'listGender' in self.path:
            limit = self.path.split('=')[1]
            events = client.get_event(limit)
            gender = parser.get_gender(events)
            html = HTML.drug_page(gender)
            self.send_response(200)

        else:
            html = HTML.not_found()
            self.send_response(404)

        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write(bytes(html, 'utf8'))
        return
Exemple #2
0
 def get_drug_effects(self, path):
     client = OpenFDAClient()
     events = client.get_event(path)
     effects = []
     results = events['results']
     for effect in results:
         effects += [effect['patient']['reaction'][0]['reactionmeddrapt']]
     return effects
Exemple #3
0
 def get_drugs_from_events(self, path):
     client = OpenFDAClient()
     events = client.get_event(path)
     drugs = []
     results = events['results']
     for event in results:
         drugs += [event['patient']['drug'][0]['medicinalproduct']]
     return drugs
Exemple #4
0
 def get_patient_sex(self, path):
     client = OpenFDAClient()
     events = client.get_event(path)
     patientsex = []
     results = events['results']
     for sex in results:
         patientsex += [sex['patient']['patientsex']]
     return patientsex
Exemple #5
0
 def get_companynumb(self, path):
     client = OpenFDAClient()
     events = client.get_event(path)
     companynumb = []
     results = events['results']
     for company in results:
         companynumb += [company['companynumb']]
     return companynumb
Exemple #6
0
 def get_COMPANIES_list(self, limit):
     client = OpenFDAClient()
     event = client.get_event(limit)
     companies_list = []
     info = json.loads(event)
     results = info["results"]
     for event in results:
         companies_list += [event['companynumb']]
     return companies_list
Exemple #7
0
 def get_warnings(self, limit):
     client = loader_FDA()
     event = client.get_event(limit)
     warning_list = []
     info = json.loads(event)
     results = info['results']
     for event in results:
         warning_list += [number['warnings']]
     return warning_list
Exemple #8
0
 def get_drugs(self, limit):
     client = OpenFDAClient()
     data2 = client.get_event(limit)
     med_list = []
     events = json.loads(data2)
     results = events["results"]
     for i in results:
         patient = i["patient"]
         drug = patient["drug"]
         med_prod = drug[0]["medicinalproduct"]
         med_list.append(med_prod)
     return med_list
Exemple #9
0
 def get_genders(self, limit):
     client = OpenFDAClient()
     event = client.get_event(limit)
     number_list = []
     gender_list = []
     info = json.loads(event)
     results = info['results']
     for number in results:
         number_list += [number['patient']['patientsex']]
     for number in number_list:
         if number == "1":
             gender_list.append("Male")
         elif number == "2":
             gender_list.append("Female")
         elif number == "0":
             gender_list.append("Unknown")
     return gender_list
Exemple #10
0
 def do_GET(self):
     client = OpenFDAClient()
     parser = OpenFDAParser()
     HTML = OpenFDAHTML()
     html = HTML.get_main_page()
     main_page = False
     listDrug = False
     searchDrug = False
     listCompanies = False
     searchCompany = False
     listGender = False
     secret = False
     redirect = False
     if self.path == '/':
         main_page = True
     elif '/listDrugs' in self.path:
         listDrug = True
     elif '/searchDrug' in self.path:
         searchDrug = True
     elif '/listCompanies' in self.path:
         listCompanies = True
     elif '/searchCompany' in self.path:
         searchCompany = True
     elif '/listGender' in self.path:
         listGender = True
     elif '/secret' in self.path:
         secret = True
     elif '/redirect' in self.path:
         redirect = True
     if main_page:
         self.get_html_answer()
         self.wfile.write(bytes(html, "utf8"))
     elif listDrug:
         self.get_html_answer()
         url = "?limit="
         limit = self.path.split('=')[1]
         event = client.get_event(url, limit)
         events = json.loads(event)
         events = events["results"]
         events = parser.get_drugs_from_events(events)
         html = HTML.get_list_html(events)
         self.wfile.write(bytes(html, "utf8"))
     elif searchDrug:
         self.get_html_answer()
         url = '?search=patient.drug.medicinalproduct:' + self.path.split(
             '=')[1]
         limit = '&limit=10'
         event = client.get_event(url, limit)
         events = json.loads(event)
         events = events["results"]
         events = parser.get_search_companynumb(events)
         html = HTML.get_list_html(events)
         self.wfile.write(bytes(html, "utf8"))
     elif listCompanies:
         self.get_html_answer()
         url = "?limit="
         limit = self.path.split('=')[1]
         event = client.get_event(url, limit)
         events = json.loads(event)
         events = events["results"]
         events = parser.get_search_companynumb(events)
         html = HTML.get_list_html(events)
         self.wfile.write(bytes(html, "utf8"))
     elif searchCompany:
         self.get_html_answer()
         url = '?search=' + self.path.split('=')[1]
         limit = '&limit=10'
         event = client.get_event(url, limit)
         events = json.loads(event)
         events = events["results"]
         events = parser.get_drugs_from_events(events)
         html = HTML.get_list_html(events)
         self.wfile.write(bytes(html, "utf8"))
     elif listGender:
         self.get_html_answer()
         url = "?limit="
         limit = self.path.split('=')[1]
         event = client.get_event(url, limit)
         events = json.loads(event)
         events = events["results"]
         events = parser.get_patientsex(events)
         html = HTML.get_list_html(events)
         self.wfile.write(bytes(html, "utf8"))
     elif secret:
         self.send_response(401)
         self.send_header('WWW-Authenticate', 'Basic realm=\"Test\"')
         self.end_headers()
     elif redirect:
         self.send_response(302)
         self.send_header('Location', 'http://localhost:8000/')
         self.end_headers()
     else:
         self.send_response(404)
         self.send_header('Content-type', 'text/html')
         self.end_headers()
         html = HTML.get_html_not_exists_resource()
         self.wfile.write(bytes(html, "utf8"))
     return