77 lines
3.2 KiB
Python
77 lines
3.2 KiB
Python
# from rest_framework.views import APIView
|
||
# from rest_framework.response import Response
|
||
# from rest_framework import status
|
||
# from .models import Patient
|
||
# from .serializers import PatientSerializer
|
||
# from .tasks import fetch_patients, fetch_patient_details, sync_patients
|
||
#
|
||
#
|
||
# class PatientListView(APIView):
|
||
# def get(self, request):
|
||
# patients = Patient.objects.all()
|
||
# serializer = PatientSerializer(patients, many=True)
|
||
# return Response(serializer.data)
|
||
#
|
||
# class SyncPatientsView(APIView):
|
||
# def post(self, request):
|
||
# try:
|
||
# patient_ids = fetch_patients()
|
||
# for orthanc_id in patient_ids:
|
||
# patient_data = fetch_patient_details(orthanc_id)
|
||
# patient, created = Patient.objects.update_or_create(
|
||
# orthanc_id=orthanc_id,
|
||
# defaults={
|
||
# "patient_id": patient_data["MainDicomTags"].get("PatientID"),
|
||
# "patient_name": patient_data["MainDicomTags"].get("PatientName"),
|
||
# "patient_sex": patient_data["MainDicomTags"].get("PatientSex"),
|
||
# "patient_birth_date": patient_data["MainDicomTags"].get("PatientBirthDate"),
|
||
# "studies": patient_data.get("Studies", []),
|
||
# "patient_metadata": patient_data,
|
||
# },
|
||
# )
|
||
# return Response({"message": "Synchronization completed successfully"})
|
||
# except Exception as e:
|
||
# return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||
#
|
||
# class SyncPatientsView(APIView):
|
||
# def post(self, request):
|
||
# try:
|
||
# sync_patients()
|
||
# return Response({"detail": "Synchronization completed successfully."}, status=status.HTTP_200_OK)
|
||
# except Exception as e:
|
||
# return Response({"detail": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||
|
||
|
||
|
||
from rest_framework.views import APIView
|
||
from rest_framework.response import Response
|
||
from rest_framework import status
|
||
from .models import Patient
|
||
from .serializers import PatientSerializer
|
||
from .tasks import fetch_patients, fetch_patient_details, sync_patients
|
||
from rest_framework.permissions import IsAuthenticated
|
||
|
||
|
||
|
||
class ProtectedView(APIView):
|
||
permission_classes = [IsAuthenticated]
|
||
|
||
def get(self, request):
|
||
return Response({"message": f"Привет, {request.user.username}! Вы авторизованы."})
|
||
|
||
# Эндпоинт для получения списка пациентов
|
||
class PatientListView(APIView):
|
||
def get(self, request):
|
||
patients = Patient.objects.all()
|
||
serializer = PatientSerializer(patients, many=True)
|
||
return Response(serializer.data)
|
||
|
||
# Эндпоинт для синхронизации данных с Orthanc
|
||
class SyncPatientsView(APIView):
|
||
def post(self, request):
|
||
try:
|
||
sync_patients()
|
||
return Response({"detail": "Synchronization completed successfully."}, status=status.HTTP_200_OK)
|
||
except Exception as e:
|
||
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|