Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchuuu committed Nov 1, 2023
1 parent 36b2a3f commit cc5f839
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 59 deletions.
Binary file added app1/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added app1/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file added app1/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file added app1/__pycache__/forms.cpython-310.pyc
Binary file not shown.
Binary file added app1/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file added app1/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file added app1/__pycache__/views.cpython-310.pyc
Binary file not shown.
44 changes: 42 additions & 2 deletions app1/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from .models import OtherIllnesses
from .models import OtherIllnesses , DietChange,Physical,GastrSymptoms

class IllnessForm(forms.Form):
metabolic_stress = forms.MultipleChoiceField(
Expand All @@ -26,7 +26,47 @@ class IllnessForm(forms.Form):
required=False
)

class DietChangeForm(forms.Form):
changes = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
choices=[("Sub-optimal solid diet","sub-optimal solid diet"),
("Taking liquids only","Taking liquids only"),
("Hypo caloric diet","Hypo caloric diet"),
("Virtually Nil/Starvation","Virtually Nil/Starvation"),
("No change","No change")],
required=False
)

class GastrSymptomsForm(forms.Form):
symptoms = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
choices=[
("Nausea", "Nausea"),
("Vomiting/Diarrhea", "Vomiting/Diarrhea"),
("Severe Anorexia", "Severe Anorexia"),
("None", "None")
],
required=False
)

class PhysicalForm(forms.Form):
phy_illness = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
choices=[("Edema","Edema"),
("Muscle Wasting","Muscle Wasting"),
("Fractures","Fractures"),
("Minor burns","Minor burns"),
("Major burns","Major burns"),
("Severe burns","Severe burns"),
("Head injury/ Multiple Trauma","Head injury/ Multiple Trauma")],
required=False
)

class CustomUserCreationForm(UserCreationForm):
class Meta:
model = User # You can use your custom user model here if you have one
fields = ('username', 'email') # Customize the fields you want in the form
fields = ('username', 'email') # Customize the fields you want in the form

class CustomLoginForm(forms.Form):
username = forms.CharField(max_length=150, label='Username')
password = forms.CharField(widget=forms.PasswordInput, label='Password')
Binary file not shown.
Binary file added app1/migrations/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
13 changes: 8 additions & 5 deletions app1/templates/app1/illness_form_template.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Illness Selection</title>
<title>Illness Form</title>
</head>
<body>
<h1>Select Your Illnesses</h1>
<h1>Illness Form</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Calculate Score</button>
{{ diet_change_form.as_p }}
{{ illness_form.as_p }}
{{ gastr_symptoms_form.as_p}}
{{ physical_form.as_p}}
<input type="submit" value="Submit">
</form>
</body>
</html>
</html>
7 changes: 4 additions & 3 deletions app1/templates/app1/result_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<title>Result</title>
</head>
<body>
<h1>Your Total Score</h1>
<p>The total score for your selected illnesses is: {{ total_score }}</p>
<h1>Result</h1>
<p>Total Score: {{ total_score }}</p>
<!-- You can add more content here to display additional results if needed -->
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions app1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
path('', views.index, name='index'), # Example URL pattern
path('about/', views.about, name='about'),
path('illness-form/', views.illness_form, name='illness_form'),
path('login/', views.CustomLoginView.as_view(), name='login'),
path('login/', views.login_view, name='login'),
path('signup/', views.signup, name='signup'),
]
]
238 changes: 191 additions & 47 deletions app1/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from django.shortcuts import render
from django.http import HttpResponse
from .forms import IllnessForm
from .models import OtherIllnesses
from django.contrib.auth.views import LoginView
from django.urls import reverse_lazy
from .forms import CustomUserCreationForm
from .forms import CustomUserCreationForm, CustomLoginForm ,DietChangeForm,GastrSymptomsForm,PhysicalForm
from django.shortcuts import redirect
from django.contrib.auth import login
from django.contrib.auth import authenticate, login
from django.urls import reverse

from .models import OtherIllnesses, DietChange, GastrSymptoms, Physical # Import your models here

def index(request):
# Your view logic for the 'index' URL pattern
Expand All @@ -20,71 +19,216 @@ def about(request):
# Example: return a simple text response
return HttpResponse("This is the about page of app1.")

def calculate_total_score(selected_illnesses):
# Define a dictionary to map illness names to their scores
# def calculate_total_score(selected_illnesses, selected_diet_changes, selected_gastr_symptoms, selected_physical): # Define a dictionary to map illness names to their scores
# illness_scores = {
# "Mental illness": 0,
# "Minor surgery": 1,
# "Pregnancy/Lactation": 1,
# "Pregnancy with complications": 3,
# "Fever": 1,
# "Solid tumors/radiotherapy": 1,
# "Laparoscopic surgeries": 1,
# "Acute kidney disease": 2,
# "Cardiac Disease": 2,
# "Diabetes": 1,
# "Stroke": 2,
# "Severe Pneumonia": 2,
# "Current cancer undergoing treatment": 2,
# "Transplant surgeries": 3,
# "Severe Sepsis": 3,
# "Severe Acute Pancreatitis": 3,
# "None": 0,
# }

# # Define a dictionary to map diet change values to their scores
# diet_change_scores = {
# "Low carb diet": 2,
# "Vegan diet": 3,
# "Gluten-free diet": 2,
# "Keto diet": 2,
# "Mediterranean diet": 1,
# "No diet changes": 0,
# }

# gastr_symptoms_scores={
# "Nausea":1 ,
# "Vomiting/Diarrhea":2 ,
# "Severe Anorexia":3 ,
# "None":0 ,
# }
# physical_scores={
# "Edema":1,
# "Muscle Wasting":2,
# "Fractures":1,
# "Minor burns":1,
# "Major burns":2,
# "Severe burns":3,
# "Head injury/ Multiple Trauma":3,}
# # Calculate the total score for selected illnesses

# # Define dictionaries for scores of selected items (e.g., illness, diet changes, symptoms, and physical)
# # Replace these dictionaries with your actual data

# total_illness_score = sum(illness_scores.get(illness, 0) for illness in selected_illnesses)
# total_diet_change_score = sum(diet_change_scores.get(diet_changes, 0) for diet_changes in selected_diet_changes)
# total_symptoms_score = sum(gastr_symptoms_scores.get(gastr_symptoms, 0) for gastr_symptoms in selected_gastr_symptoms)
# total_physical_score = sum(physical_scores.get(physical, 0) for physical in selected_physical)

# # Calculate the final total score
# total_score = (
# total_illness_score +
# total_diet_change_score +
# total_symptoms_score +
# total_physical_score
# )

# return total_score

# def illness_form(request):
# if request.method == 'POST':
# diet_change_form = DietChangeForm(request.POST)
# illness_form = IllnessForm(request.POST)
# gastr_symptoms_form = GastrSymptomsForm(request.POST)
# physical_form = PhysicalForm(request.POST)

# if (
# diet_change_form.is_valid() and
# illness_form.is_valid() and
# gastr_symptoms_form.is_valid() and
# physical_form.is_valid()
# ):
# selected_illnesses = illness_form.cleaned_data.get('metabolic_stress')
# selected_diet_changes = diet_change_form.cleaned_data.get('metabolic_stress')
# selected_gastr_symptoms = gastr_symptoms_form.cleaned_data.get('gastr_symptoms')
# selected_physical = physical_form.cleaned_data.get('physical')

# total_score = calculate_total_score(
# selected_illnesses,
# selected_diet_changes,
# selected_gastr_symptoms,
# selected_physical
# )

# # Process the form data as needed
# return render(request, 'app1/result_template.html', {'total_score': total_score})
# else:
# diet_change_form = DietChangeForm()
# illness_form = IllnessForm()
# gastr_symptoms_form = GastrSymptomsForm()
# physical_form = PhysicalForm()

# return render(request, 'app1/illness_form_template.html', {
# 'diet_change_form': diet_change_form,
# 'illness_form': illness_form,
# 'gastr_symptoms_form': gastr_symptoms_form,
# 'physical_form': physical_form,
# })


def calculate_total_score(selected_illnesses, selected_diet_changes, selected_gastr_symptoms, selected_physical):
# Define dictionaries to map item names to their scores
illness_scores = {
"Mental illness": 0,
"Minor surgery": 1,
"Pregnancy/Lactation": 1,
"Pregnancy with complications": 3,
"Fever": 1,
"Solid tumors/radiotherapy": 1,
"Laproscopic surgeries": 1,
"Acute kidney disease": 2,
"Cardiac Disease": 2,
"Diabetes": 1,
"Stroke": 2,
"Severe Pneumonia": 2,
"Current cancer undergoing treatment": 2,
"Transplant surgeries": 3,
"Severe Sepsis": 3,
"Severe Acute Pancreatitis": 3,
"None": 0,
item.metabolic_stress: item.m_score for item in OtherIllnesses.objects.all()
}

total_score = sum(illness_scores.get(illness, 0) for illness in selected_illnesses)
return total_score
diet_change_scores = {
item.changes: item.d_score for item in DietChange.objects.all()
}

gastr_symptoms_scores = {
item.symptoms: item.g_score for item in GastrSymptoms.objects.all()
}

physical_scores = {
item.phy_illness: item.p_score for item in Physical.objects.all()
}

# Calculate the total score for selected items
total_illness_score = sum(illness_scores.get(illness, 0) for illness in selected_illnesses)
total_diet_change_score = sum(diet_change_scores.get(diet_changes, 0) for diet_changes in selected_diet_changes)
total_symptoms_score = sum(gastr_symptoms_scores.get(gastr_symptoms, 0) for gastr_symptoms in selected_gastr_symptoms)
total_physical_score = sum(physical_scores.get(physical, 0) for physical in selected_physical)

# Calculate the final total score
total_score = (
total_illness_score +
total_diet_change_score +
total_symptoms_score +
total_physical_score
)

return total_score

def illness_form(request):
if request.method == 'POST':
form = IllnessForm(request.POST)
if form.is_valid():
selected_illnesses = form.cleaned_data.get('metabolic_stress')
total_score = calculate_total_score(selected_illnesses)
diet_change_form = DietChangeForm(request.POST)
illness_form = IllnessForm(request.POST)
gastr_symptoms_form = GastrSymptomsForm(request.POST)
physical_form = PhysicalForm(request.POST)

if (
diet_change_form.is_valid() and
illness_form.is_valid() and
gastr_symptoms_form.is_valid() and
physical_form.is_valid()
):
selected_illnesses = illness_form.cleaned_data.get('metabolic_stress')
selected_diet_changes = diet_change_form.cleaned_data.get('changes')
selected_gastr_symptoms = gastr_symptoms_form.cleaned_data.get('symptoms')
selected_physical = physical_form.cleaned_data.get('phy_illness')

total_score = calculate_total_score(
selected_illnesses,
selected_diet_changes,
selected_gastr_symptoms,
selected_physical
)

# Process the form data as needed
return render(request, 'app1/result_template.html', {'total_score': total_score})
else:
form = IllnessForm()
diet_change_form = DietChangeForm()
illness_form = IllnessForm()
gastr_symptoms_form = GastrSymptomsForm()
physical_form = PhysicalForm()

return render(request, 'app1/illness_form_template.html', {'form': form})
return render(request, 'app1/illness_form_template.html', {
'diet_change_form': diet_change_form,
'illness_form': illness_form,
'gastr_symptoms_form': gastr_symptoms_form,
'physical_form': physical_form,
})

class CustomLoginView(LoginView):
template_name = 'app1/login.html'
success_url = reverse_lazy('home') # Redirect to the homepage upon successful login
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['signup_url'] = reverse('app1:signup') # Include the 'signup' URL in the context
return context
from django.contrib.auth.forms import AuthenticationForm

def signup(request):
def login_view(request):
if request.method == 'POST':
form = CustomUserCreationForm(request.POST)
form = CustomLoginForm(request.POST)

if form.is_valid():
user = form.save()
login(request, user)
return redirect('home') # Redirect to the homepage after signup
username = form.cleaned_data['username']
password = form.cleaned_data['password']

user = authenticate(request, username=username, password=password)

if user is not None:
login(request, user)
# Redirect to a success page or home page
return redirect('home')
else:
# Handle authentication failure
form.add_error(None, "Please enter a valid username and password.")
else:
form = CustomUserCreationForm()
form = CustomLoginForm()

return render(request, 'app1/signup.html', {'form': form})
def sig__nup(request):
return render(request, 'app1/login.html', {'form': form})
def signup(request):
if request.method == 'POST':
form = CustomUserCreationForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
return redirect('home') # Redirect to the homepage after signup
return redirect('login') # Redirect to the homepage after signup

else:
form = CustomUserCreationForm()
Expand Down
Binary file added project1/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added project1/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file added project1/__pycache__/urls.cpython-310.pyc
Binary file not shown.

0 comments on commit cc5f839

Please sign in to comment.