Skip to content

Feature: Patient Age Validation & Eligibility #14

Description

@codeCraft-Ritik

Issue Description :

Currently, the system allows patients to register with any age. In a medical context, blood requests for minors often require different oversight, or there should be a logical minimum age for a "Patient" profile (e.g., above 0). Adding validation ensures data integrity.

File to Modify : bloodbankmanagement/patient/forms.py (and models.py)

Logic: Add a clean_age method to the Patient form to ensure the age is within a realistic range (e.g., 0–120).

Code Implementation :

# In bloodbankmanagement/patient/forms.py
from django import forms
from .models import Patient

class PatientForm(forms.ModelForm):
    class Meta:
        model = Patient
        fields = ['age', 'bloodgroup', 'disease', 'doctorname', 'address', 'mobile', 'profile_pic']

    def clean_age(self):
        age = self.cleaned_data.get('age')
        if age <= 0 or age > 120:
            raise forms.ValidationError("Please enter a valid age between 1 and 120.")
        return age

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions