Digital Rights Management für elektronische Patientenakten
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from django.db import models
  2. from django.contrib.auth.models import User
  3. from django.dispatch import receiver
  4. from django.db.models.signals import post_save
  5. from health_view.crypto_functions import *
  6. class FolderInfo(models.Model):
  7. """Adding attributes to default model user"""
  8. patient = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True)
  9. pub_key = models.CharField(max_length=300, blank=True)
  10. content_key = models.CharField(max_length=300, blank=True, default="no_key")
  11. def __str__(self):
  12. """String for representing the Model object."""
  13. return str(self.id)
  14. @receiver(post_save, sender=User)
  15. def create_folderinfo(sender, instance, created, **kwargs):
  16. """Creates folderinfo when user gets created"""
  17. if created:
  18. folderinfo = FolderInfo.objects.create(patient=instance)
  19. folderinfo.pub_key = make_key_pair_public(folderinfo.patient)
  20. folderinfo.save()
  21. class Permission(models.Model):
  22. shortcut = models.CharField(max_length=5)
  23. permissions = models.CharField(max_length=100)
  24. def __str__(self):
  25. """String for representing the Model object."""
  26. return self.permissions
  27. class FolderPart(models.Model):
  28. shortcut = models.CharField(max_length=3)
  29. part_name = models.CharField(max_length=40)
  30. def __str__(self):
  31. """String for representing the Model object."""
  32. return self.part_name
  33. class License(models.Model):
  34. """License model which defines rights"""
  35. patient = models.ForeignKey(User, on_delete=models.CASCADE, related_name='patient_id')
  36. justified = models.ForeignKey(User, default=None, on_delete=models.CASCADE, related_name='justified_id')
  37. license_creator = models.ForeignKey(User, default=None, null=True, blank=True, on_delete=models.CASCADE, related_name='license_creators')
  38. exp_date = models.CharField(max_length=200, null=True, blank=True)
  39. permissions = models.ManyToManyField(Permission)
  40. folder_parts = models.ManyToManyField(FolderPart)
  41. signature = models.CharField(max_length=200, null=True)
  42. def __str__(self):
  43. """String for representing the Model object."""
  44. return self.justified.get_username() + " " + ''.join(p.shortcut for p in self.permissions.all())