Created
June 7, 2023 08:55
-
-
Save muhamedoufi/edc551207ac79a004e5177040dc19a49 to your computer and use it in GitHub Desktop.
multimedia models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# L'application accounts | |
# from sqlite3 import IntegrityError | |
import email | |
from PIL import Image | |
from django.db import models | |
# from django.contrib.auth.models import User | |
from django.db.models.signals import post_save | |
from django.dispatch import receiver | |
import datetime | |
from django.contrib.auth.models import AbstractUser | |
from django.utils.translation import gettext as _ | |
from django.db import models | |
from django.db.utils import IntegrityError | |
class User(AbstractUser): | |
# is_admin = models.BooleanField(default=False) | |
is_medecin = models.BooleanField(default=False) | |
is_technicien = models.BooleanField(default=False) | |
is_secretaire = models.BooleanField(default=False) | |
phone = models.CharField(max_length=10,null=True) | |
nni = models.CharField(max_length=100,null=True) | |
birth = models.DateField(null=True) | |
age = models.IntegerField(null=True) | |
gender = models.CharField(max_length=1, default="M") | |
class Profile(models.Model): | |
user = models.OneToOneField(User,on_delete=models.CASCADE) | |
phone_number = models.CharField(max_length=12) | |
image = models.ImageField(default='default.jpg',null=True) | |
manager = models.CharField(max_length=50,null=True) | |
def __str__(self): | |
return str(self.user) | |
def save(self, *args, **kwargs): | |
super().save(*args, **kwargs) | |
img = Image.open(self.image.path) | |
if img.width > 300 or img.height > 300: | |
output_size = (300, 300) | |
img.thumbnail(output_size) | |
img.save(self.image.path) | |
##create new user --->create new empty profile | |
@receiver(post_save, sender=User) | |
def create_user_profile(sender, instance, created, **kwargs): | |
if created: | |
profile = Profile.objects.create(user=instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#l'application Image | |
from email.policy import default | |
from io import BytesIO | |
from django.db import models | |
from accounts.models import User | |
from image.validator import validate_file_extension | |
from djongo import models as djongo_models | |
# from django.contrib.auth.models import User | |
from django.core.validators import FileExtensionValidator | |
from patient.models import Patient | |
from PIL import Image as im | |
from djongo.models import ObjectIdField | |
from djongo.storage import GridFSStorage | |
from django.conf import settings | |
# import matplotlib.pyplot as plt | |
# import numpy as np | |
from datetime import datetime | |
import pydicom | |
import pydicom.data | |
# Create your models here. | |
grid_fs_storage_zip = GridFSStorage(collection='zipfiles', base_url=''.join([settings.BASE_URL, 'myDCM/'])) | |
class DicomZipFile(models.Model): | |
# _id = ObjectIdField() | |
zipfile = djongo_models.FileField( | |
storage=grid_fs_storage_zip, | |
# validators=[validate_file_extension] | |
) | |
# Define your GrifFSStorage instance | |
grid_fs_storage = GridFSStorage(collection='myfiles', base_url=''.join([settings.BASE_URL, 'myDCM/'])) | |
class Image(models.Model): | |
# _id = ObjectIdField() | |
img = djongo_models.FileField( | |
storage=grid_fs_storage, | |
validators=[FileExtensionValidator(allowed_extensions=['dcm', 'zip'])] | |
) | |
# imgFolder= models.FileField(imgFolder=True) | |
# img = models.FileField(upload_to='image/images/',blank=True, null=True) | |
extension = models.CharField(max_length=30) | |
technicien = models.ForeignKey(User,on_delete=models.CASCADE,null=True) | |
patient = models.ForeignKey(Patient,on_delete=models.CASCADE) | |
description = models.TextField(null=True,default="") | |
created_at = models.DateTimeField(auto_now_add=True) | |
StudyInstanceUID = models.CharField(max_length=300) | |
def __str__(self): | |
return f"l'image du Patient {self.patient} est bien Ajouteé" | |
# MAHOU MOUHIM | |
class Chat(models.Model): | |
created = models.DateTimeField(auto_now_add=True) | |
message = models.CharField(max_length=255) | |
user = models.ForeignKey(User, related_name="messages" ,on_delete=models.CASCADE) | |
def __str__(self): | |
return self.message | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#l'application Patient | |
from django.db import models | |
from accounts.models import User | |
# from django.contrib.auth.models import User | |
# Create your models here. | |
class Patient(models.Model): | |
secretaire = models.ForeignKey(User,blank=True,null=True,on_delete=models.CASCADE) | |
nom = models.CharField(max_length=45) | |
prenom =models.CharField(max_length=45) | |
type = models.CharField(max_length=8,choices=(('Interne', 'Interne'),('Externe','Externe'),),default='Externe') | |
numero_dossier = models.IntegerField(null=True,blank=True) | |
sexe = models.CharField(max_length=8,choices=(('Male', 'Male'),('Femelle','Femelle'),)) | |
dateNaissance = models.DateField(null=True) | |
lieuNaissance = models.CharField(max_length=100) | |
lieuResidance = models.CharField(max_length=100) | |
NumTel1 = models.IntegerField(null=True) | |
NumTel2 = models.IntegerField(null=True) | |
Assurance = models.CharField(max_length=45) | |
def __str__(self): | |
return f"{self.nom}/{self.prenom}" | |
class Rendevous(models.Model): | |
medecin_technicien = models.ForeignKey(User,blank=True,null=True,on_delete=models.CASCADE) | |
patient = models.ForeignKey(Patient,blank=True,null=True,on_delete=models.CASCADE) | |
dateRendevou = models.DateField(null=True) | |
Status_Patient = models.TextField(max_length=1000) | |
def __str__(self): | |
return f"un Rendevous pour le Patient {self.patient.nom} est Bien planifié" | |
class Consultation(models.Model): | |
rendevous = models.ForeignKey(Rendevous,blank=True,null=True,on_delete=models.CASCADE) | |
medecin = models.ForeignKey(User,blank=True,null=True,on_delete=models.CASCADE) | |
patient = models.ForeignKey(Patient,blank=True,null=True,on_delete=models.CASCADE) | |
dateConsultation = models.DateField(null=True) | |
resultatConsultation = models.TextField(max_length=1000) | |
def __str__(self): | |
return f"la consultation de Patient {self.patient.nom}/{self.patient.prenom}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment