Giter Site home page Giter Site logo

patients-database's Introduction

forthebadge forthebadge forthebadge

Patients-Database

Patient Datababe Website made using Django


Here you can upload data of the patient and update the data and delete and view of details of the patients

hope you have installed django or else you can follow the command


python -m pip install Django

Create the project

django-admin startproject hospital

change the directory to the new project folder created

Then create the app for the project

python3 manage.py startapp patient

For quick overview of the project you can copy and overwrite the files and folder from the repo to the respective files of django that you have created

How to run the django server

now run the following commands

python3 manage.py makemigrations python3 manage.py migrate
python manage.py runserver

To access the admin portal of Django

follow the commands and give your own password and username

python3 manage.py createsuperuser

Important code snippets

forms.py

from django import forms
from .models import Patient
import datetime

class DateInput(forms.DateInput):
    input_type = 'date'

class PatientForm(forms.ModelForm):
    class Meta:
        model = Patient
        fields = [
            'First_Name',
            'Last_Name',
            'Gender',
            'Age',
            'Disease',
            'Doctor_name',
            'Doctor_fees',
            'Starting_data_of_meds',
            'Image'
        ]
        
class RawPatientForm(forms.Form):
    
    GENDER_CHOICES = [
        ('Male','Male'),
        ('Female','Female'),
    ]
    First_Name = forms.CharField(widget = forms.TextInput(attrs= {'placeholder': 'Enter First Name'}))
    Last_Name = forms.CharField(widget = forms.TextInput(attrs= {'placeholder': 'Enter Last Name'}))
    Gender = forms.ChoiceField(choices=GENDER_CHOICES)
    Age = forms.IntegerField(widget = forms.NumberInput(attrs={'placeholder':'Enter your Age'}))
    Disease = forms.CharField(widget = forms.Textarea(attrs={'rows': 4 , 'cols': 50,'placeholder':'Enter your Problems / Disease'}))
    Doctor_name = forms.CharField(widget = forms.TextInput(attrs={'placeholder': 'Enter your Doctor Name'}))
    Doctor_fees = forms.DecimalField(initial = 500.00)
    Starting_data_of_meds = forms.DateField(input_formats = ['%Y-%m-%d'],widget = DateInput)
    Image = forms.FileField()
    

models.py


Dynamic url is used to access the perticular id of the patient

from django.db import models
from django.urls import reverse

class Patient(models.Model):
    GENDER_CHOICES = [
        ('Male','Male'),
        ('Female','Female'),
    ]
    
    First_Name = models.CharField(max_length  = 120)
    Last_Name = models.CharField(max_length = 120)
    Gender = models.CharField(max_length = 10, choices = GENDER_CHOICES)
    Age = models.IntegerField()
    Disease = models.TextField()
    Doctor_name = models.CharField(max_length = 200)
    Doctor_fees = models.DecimalField(decimal_places=2,max_digits=100000,default = 500.00)
    Starting_data_of_meds = models.DateTimeField(null = True,blank = True)
    Image = models.FileField(upload_to='images/',default = '')
    
    def __str__(self):
        return self.First_Name
    def get_absolute_url(self):
        return reverse("patient:detail", kwargs={"pk": self.pk})
    

views.py

from django.shortcuts import render,get_object_or_404,redirect
from django.views.generic import ListView,DetailView
from .models import Patient
from .forms import PatientForm ,RawPatientForm
import datetime

class HomeView(ListView):
    model = Patient
    template_name = "patient/home.html"

class PatientDetailView(DetailView):
    model = Patient
    template_name = "patient/detail.html"
    
def patient_create_view(request):
    
    
    med_form = RawPatientForm()
    if request.method == "POST" or None:
        med_form = RawPatientForm(request.POST or None , request.FILES or None)
        if med_form.is_valid():
            Patient.objects.create(**med_form.cleaned_data)
            return redirect('../')
    context = {'form':med_form}
    

    return render(request,"patient/create.html",context)

def patient_delete_view(request,pk):
    patient = get_object_or_404(Patient,pk = pk)
    if request.method == "POST":
        patient.delete()
        return redirect('../../')
    context = {
        "patient":patient
    }
    return render(request,"patient/delete.html",context)

def patient_update_view(request,pk):
    patient = get_object_or_404(Patient,pk = pk)
    med_form = PatientForm(request.POST or None,request.FILES or None , instance = patient)
    if med_form.is_valid():
        med_form.save()
        return redirect('../../')
    context = {
        'form':med_form
    }
    return render(request,"patient/update.html",context)
    

Some changes in settings.py to needed

import os

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'patient'
]

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,"templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
            ],
        },
    },
]

TIME_ZONE = 'Asia/Kolkata'

MEDIA_ROOT = os.path.join(BASE_DIR,'media/')
MEDIA_URL = '/media/'

I have include my own urls.py in paient folder

from django.urls import path
from .views import HomeView,PatientDetailView,patient_create_view,patient_delete_view,patient_update_view

app_name = 'patient'

urlpatterns = [
    path('',HomeView.as_view(),name = 'home'),
    path('detail/<int:pk>/',PatientDetailView.as_view(),name = 'detail'),
    path('create/',patient_create_view,name = 'create'),
    path('delete/<int:pk>/',patient_delete_view,name = 'delete'),
    path('update/<int:pk>/',patient_update_view,name = 'update')
]

url patterns are set according to the dynamic url created in models.py

Few Screenshot of the Project

display patients (home.html)

Detail view of the perticular patient (detail.html)

delete page

Contributions to this project is highly appreciable

patients-database's People

Contributors

geek-ninja avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.