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.

cron.py 1.7KB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from health_view.models import *
  2. from health_view.views import check_expiration_date
  3. from datetime import datetime
  4. from health_view.crypto_functions import *
  5. import requests
  6. import json
  7. loginname_restapi = 'gabi'
  8. passwort_restapi = 'Lolo7138'
  9. def check_exp_date():
  10. licenses = License.objects.all()
  11. date_now = datetime.now()
  12. for lic in licenses:
  13. if check_expiration_date(lic):
  14. continue
  15. licenses_same_owner = License.objects.filter(justified=lic.justified, patient=lic.patient).exclude(id=lic.id)
  16. folderparts = lic.folder_parts.all().values_list()
  17. parts_to_delete = list()
  18. for part in folderparts:
  19. delete = True
  20. for license in licenses_same_owner:
  21. if not check_expiration_date(license):
  22. continue
  23. for check_part in license.folder_parts.all().values_list():
  24. if check_part == part:
  25. delete = False
  26. if delete is True:
  27. parts_to_delete.append(part[2])
  28. if not parts_to_delete:
  29. lic.delete()
  30. continue
  31. new_total_key = make_encrypted_key_content_server()
  32. post_content = {
  33. 'patient': lic.patient.username,
  34. 'justified': lic.justified.username,
  35. 'new_total_key': new_total_key,
  36. 'old_total_key': lic.patient.folderinfo.content_key,
  37. 'folder_parts': parts_to_delete,
  38. }
  39. lic.patient.folderinfo.content_key = new_total_key
  40. lic.patient.folderinfo.save()
  41. lic.delete()
  42. request = requests.post('http://192.168.192.75:8000/manage/delete/', json=post_content, auth=(loginname_restapi, passwort_restapi))