File size: 2,620 Bytes
718f018
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
911701e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from django.db import models
from django.contrib.auth.models import User

class UserProfile(models.Model):
    ROLE_CHOICES = (('patient', 'Patient'), ('doctor', 'Doctor'))
    
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
    role = models.CharField(max_length=10, choices=ROLE_CHOICES)
    
    # Common fields
    # --- NEW FIELDS ADDED HERE ---
    full_name = models.CharField(max_length=200, blank=True)
    phone = models.CharField(max_length=20, blank=True)
    address = models.TextField(blank=True)
    # -----------------------------
    
    state = models.CharField(max_length=100, blank=True)
    city = models.CharField(max_length=100, blank=True)
    
    # Doctor specific
    license_number = models.CharField(max_length=50, blank=True, null=True)
    
    # Patient specific
    age = models.IntegerField(null=True, blank=True)
    gender = models.CharField(max_length=20, blank=True)

    def __str__(self):
        return f"{self.user.username} - {self.role}"

class TestResult(models.Model):
    RESULT_CHOICES = (('Positive', 'Positive'), ('Negative', 'Negative'))
    RISK_CHOICES = (('High', 'High'), ('Medium', 'Medium'), ('Low', 'Low'))
    
    patient = models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name='test_results')
    xray_image_url = models.URLField()
    date_tested = models.DateTimeField(auto_now_add=True)
    
    # Prediction Data
    result = models.CharField(max_length=20, choices=RESULT_CHOICES)
    confidence_score = models.FloatField()
    risk_level = models.CharField(max_length=20, choices=RISK_CHOICES)
    
    # Storing symptoms as a JSON object for flexibility
    symptoms_data = models.JSONField(default=dict)

    def __str__(self):
        return f"{self.patient.user.username} - {self.result} ({self.date_tested})"

class Appointment(models.Model):
    STATUS_CHOICES = (
        ('Pending', 'Pending'),
        ('Confirmed', 'Confirmed'),
        ('Completed', 'Completed'),
        ('Cancelled', 'Cancelled'),
    )

    patient = models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name='appointments_as_patient')
    doctor = models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name='appointments_as_doctor')
    date = models.DateField()
    time = models.TimeField()
    reason = models.TextField(blank=True)
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='Pending')
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.patient.full_name} with {self.doctor.full_name} on {self.date}"