<commit_before>from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from .forms import XMLInputForm,EliIEInputForm, EliIEForm
import requests,urllib,json
from xmljson import badgerfish as bf
from xml.etree import ElementTree as ET
import re
import textwrap
import os
from django.core.files import File


def index(request):
	return render(request,'OHDSImatcher/index.html')

def eliie(request):
	print("you entered the EliIE page")
	if request.method == 'POST':
		xml_text = eliie_exec(request.POST)
		request.session['xml_text'] = xml_text
		return HttpResponseRedirect('/json-transform')
	else:
		eliieform = EliIEInputForm()
		nct_eli = {}
		context = {
			'nct_eli' : nct_eli,
			'eliieform': eliieform
		}
		return render(request,'OHDSImatcher/eliie.html', context)

def eliie_nct(request,slug):
	print "you entered the EliIE page at",slug
	if request.method == 'POST':
		xml_text = eliie_exec(request.POST)
		request.session['xml_text'] = xml_text
		return HttpResponseRedirect('/json-transform')
	else:
		eliieform = EliIEInputForm()
		nct_eli = {}
		if slug[0:3] != "NCT" and slug[0:3] != "nct":
			nct_eli['text'] = str("You entered ClinicalTrials.gov ID: "+slug+", but this is not valid!")
		else:
			url = "https://clinicaltrials.gov/show/"+slug+"?displayxml=true"
			response = urllib.urlopen(url)
			try:
				nct_orig = response.read().decode('utf-8')
				try:
					nct_root = ET.fromstring(nct_orig)
				except:
					nct_eli['text'] = str("You entered ClinicalTrials.gov ID: "+slug+", but this is not valid!")
					context = {
						'nct_eli': nct_eli,
						'eliieform': eliieform
					}
					return render(request,'OHDSImatcher/eliie.html',context)
				eli = nct_root.findall('eligibility')[0]
				# nct_txt = "entered ClinicalTrials.gov ID: "+slug+", and success fetch response."
				for child in eli:
					if child.tag == "criteria":
						txt = child.findall('textblock')[0].text
						txt = txt.replace('\n','')
						txt = re.sub(' +',' ', txt).strip()
						nct_eli['text'] = txt
					elif child.tag == "gender":
						nct_eli['gender'] = child.text
					elif child.tag == "minimum_age":
						nct_eli['min_age'] = child.text
					elif child.tag == "maximum_age":
						nct_eli['max_age'] = child.text			
<commit_msg>Update views.py<commit_after>from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from .forms import XMLInputForm,EliIEInputForm, EliIEForm
import requests,urllib,json
from xmljson import badgerfish as bf
from xml.etree import ElementTree as ET
import re
import textwrap
import os
from django.core.files import File


def index(request):
	return render(request,'OHDSImatcher/index.html')

def eliie(request):
	print("you entered the EliIE page")
	if request.method == 'POST':
		xml_text = eliie_exec(request.POST)
		request.session['xml_text'] = xml_text
		return HttpResponseRedirect('/json-transform')
	else:
		eliieform = EliIEInputForm()
		nct_eli = {}
		context = {
			'nct_eli' : nct_eli,
			'eliieform': eliieform
		}
		return render(request,'OHDSImatcher/eliie.html', context)

def eliie_nct(request,slug):
	print "you entered the EliIE page at",slug
	if request.method == 'POST':
		xml_text = eliie_exec(request.POST)
		request.session['xml_text'] = xml_text
		return HttpResponseRedirect('/json-transform')
	else:
		eliieform = EliIEInputForm()
		nct_eli = {}
		if slug[0:3] != "NCT" and slug[0:3] != "nct":
			nct_eli['text'] = str("You entered ClinicalTrials.gov ID: "+slug+", but this is not valid!")
		else:
			url = "https://clinicaltrials.gov/show/"+slug+"?displayxml=true"
			response = urllib.urlopen(url)
			try:
				nct_orig = response.read().decode('utf-8')
				try:
					nct_root = ET.fromstring(nct_orig)
				except:
					nct_eli['text'] = str("You entered ClinicalTrials.gov ID: "+slug+", but this is not valid!")
					context = {
						'nct_eli': nct_eli,
						'eliieform': eliieform
					}
					return render(request,'OHDSImatcher/eliie.html',context)
				eli = nct_root.findall('eligibility')[0]
				# nct_txt = "entered ClinicalTrials.gov ID: "+slug+", and success fetch response."
				for child in eli:
					if child.tag == "criteria":
						txt = child.findall('textblock')[0].text
						txt = txt.replace('\n','')
						txt = re.sub(' +',' ', txt).strip()
						tnote = txt.split(' -')
						textarea=''
						for x in tnote:
							if 'Exclusion Criteria' in  x:
								temp = x.split('.')
								textarea=textarea+temp[0]+'.'+'\n'
								textarea=textarea+temp[1]+'\n'
							else:
								textarea=textarea+x+'\n'
							

						nct_eli['text'] = textarea
					elif child.tag == "gender":
						nct_eli['gender'] = child.text
					elif child.tag == "minimum_age":
						nct_eli['min_age'] = child.text
					elif child.tag == "maximum_age":
						nct_eli['max_age'] = child.text			

{'fraction_non_alphanumeric': 0.14188351920693928, 'fraction_numerical': 0.003304419661296985, 'mean_word_length': 3.7294921875, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4771336', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1692, 'n_words': 381}