New updates

This commit is contained in:
Joshua Rubingh 2020-11-17 11:40:11 +01:00
parent 80711cd918
commit 6299b2f983
7 changed files with 73 additions and 91 deletions

View File

@ -9,58 +9,29 @@ class ApiConfig(AppConfig):
verbose_name = _('API')
verbose_name_plural = _('APIs')
# try:
# assert settings.SWAGGER_SETTINGS
# except AttributeError:
# # We only load this setting, if it is not available in the overall settings.py file
# settings.SWAGGER_SETTINGS = {
# 'SECURITY_DEFINITIONS': {
# 'Hawk': {
# 'type': 'apiKey',
# 'description': 'HTTP Holder-Of-Key Authentication Scheme, https://github.com/hapijs/hawk, https://hawkrest.readthedocs.io/en/latest/<br /><strong>Ex header:</strong><br />\'Authorization\': \'Hawk mac="F4+S9cu7yZiZEgdtqzMpOOdudvqcV2V2Yzk2WcphECc=", hash="+7fKUX+djeQolvnLTxr0X47e//UHKbkRlajwMw3tx3w=", id="7FI5JET4", ts="1592905433", nonce="DlV-fL"\'',
# 'name': 'Authorization',
# 'in': 'header'
# }
# }
# }
try:
assert settings.SWAGGER_SETTINGS
except AttributeError:
# We only load this setting, if it is not available in the overall settings.py file
settings.SWAGGER_SETTINGS = {
}
# try:
# assert settings.REST_FRAMEWORK
# except AttributeError:
# # We only load this setting, if it is not available in the overall settings.py file
# # To protect all API views with Hawk by default, put this in your settings:
# # https://hawkrest.readthedocs.io/en/latest/usage.html#protecting-api-views-with-hawk
# settings.REST_FRAMEWORK = {
try:
assert settings.REST_FRAMEWORK
except AttributeError:
# We only load this setting, if it is not available in the overall settings.py file
# To protect all API views with Hawk by default, put this in your settings:
# https://hawkrest.readthedocs.io/en/latest/usage.html#protecting-api-views-with-hawk
settings.REST_FRAMEWORK = {
# 'DEFAULT_AUTHENTICATION_CLASSES': (
# 'apps.api.authentication.APIHawk',
# ),
# 'DEFAULT_PERMISSION_CLASSES': (
# 'rest_framework.permissions.IsAuthenticated',
# ),
# # 'DEFAULT_AUTHENTICATION_CLASSES': (
# # 'rest_framework.authentication.TokenAuthentication',
# # ),
# # 'DEFAULT_PERMISSION_CLASSES': (
# # 'rest_framework.permissions.IsAuthenticated', ),
# # Use Django's standard `django.contrib.auth` permissions,
# # or allow read-only access for unauthenticated users.
# #'DEFAULT_PERMISSION_CLASSES': [
# # 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
# #],
# 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
# 'PAGE_SIZE': 10
# }
# try:
# assert settings.HAWK_MESSAGE_EXPIRATION
# except AttributeError:
# # We only load this setting, if it is not available in the overall settings.py file
# settings.HAWK_MESSAGE_EXPIRATION = 60
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
# 'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
# ],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10
}
def ready(self):
from . import signals

View File

@ -7,53 +7,27 @@ from drf_yasg2 import openapi
from . import views
# from apps.dropoff.api.views import DatadropViewSet
# from apps.invitation.api.views import InvitationViewSet
# from apps.researcher.api.views import ResearcherViewSet
# from apps.storage.api.views import StorageEngineViewSet, StorageLocationViewSet
# from apps.study.api.views import StudyViewSet
# from apps.virtual_machine.api.views import (VirtualMachineViewSet,
# VirtualMachineOperatingSystemViewSet,
# VirtualMachineProfileViewSet,
# VirtualMachineMemoryViewSet,
# VirtualMachineNetworkViewSet,
# VirtualMachineStorageViewSet,
# VirtualMachineGPUViewSet)
from apps.synthea.api.views import SyntheaViewSet
from apps.synthea.api.serializers import SyntheaSerializer ,SyntheaModelsSerializer
schema_view = get_schema_view(
openapi.Info(
title="Synthea WebService API",
default_version='v1',
default_version='',
description="Info about Synthea WebServer API",
terms_of_service="https://www.rug.nl",
contact=openapi.Contact(email="vre_team@rug.nl"),
contact=openapi.Contact(email="cit@rug.nl"),
license=openapi.License(name="MIT License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)
#api_router_v1 = routers.DefaultRouter()
generate_post = SyntheaViewSet.as_view({
'post': 'create'
})
# api_router_v1.register(r'researchers', ResearcherViewSet)
# api_router_v1.register(r'studies', StudyViewSet)
# api_router_v1.register(r'dropoffs', DatadropViewSet)
# api_router_v1.register(r'invitations', InvitationViewSet)
# api_router_v1.register(r'storageengines', StorageEngineViewSet)
# api_router_v1.register(r'storagelocations', StorageLocationViewSet)
# # Order is important for virtual machines. Longest match first
# api_router_v1.register(r'virtualmachines/profiles', VirtualMachineProfileViewSet)
# api_router_v1.register(r'virtualmachines/storage', VirtualMachineStorageViewSet)
# api_router_v1.register(r'virtualmachines/memory', VirtualMachineMemoryViewSet)
# api_router_v1.register(r'virtualmachines/network', VirtualMachineNetworkViewSet)
# api_router_v1.register(r'virtualmachines/gpu', VirtualMachineGPUViewSet)
# api_router_v1.register(r'virtualmachines/os', VirtualMachineOperatingSystemViewSet)
# api_router_v1.register(r'virtualmachines', VirtualMachineViewSet)
# Main namespace for the API urls
app_name = 'api'
@ -68,8 +42,5 @@ urlpatterns = [
path('states/', views.States.as_view(), name='states'),
path('modules/', views.Modules.as_view(), name='modules'),
path('generate/', views.Generate.as_view(), name='generate'),
# Add extra namespace for versioning the API
#path('v1/', include((api_router_v1.urls,'api'),namespace='v1')),
path('generate/', generate_post, name='generate'),
]

View File

@ -1,8 +1,16 @@
from rest_framework import serializers
from apps.synthea.models import Synthea
class SyntheaSerializer(serializers.ModelSerializer):
class Meta:
model = Synthea
fields = ['state', 'population', 'gender', 'age', 'module']
fields = ['state', 'population', 'gender', 'age', 'module']
class SyntheaModelsSerializer(serializers.Serializer):
id = serializers.CharField(max_length=200)
name = serializers.CharField(max_length=200)
class SyntheaStatesSerializer(serializers.Serializer):
id = serializers.CharField(max_length=200)
name = serializers.CharField(max_length=200)

View File

@ -0,0 +1,13 @@
from rest_framework import viewsets
from .serializers import SyntheaSerializer
from apps.synthea.models import Synthea
class SyntheaViewSet(viewsets.ModelViewSet):
"""
API endpoint for creating/reading/updating/deleting invitations.
"""
queryset = Synthea.objects.all().order_by('-created_at')
serializer_class = SyntheaSerializer

View File

@ -0,0 +1,15 @@
{% extends 'base.html' %} <!-- Add this for inheritance -->
{% load i18n %}
{% block title %}{% trans "dHealth Synthea" %}{% endblock %}
{% block pagetitle %}{% trans "dHealth Synthea" %}{% endblock %}
{% block menu %}
{% include 'synthea/menu.html' %}
{% endblock %}
{% block content %}
<h1>API</h1>
<p>Hier kunt u informatie vinden over de API zodat er ge-automatiseed patient data kan worden gegenereerd</p>
<p>Documentatie: <a href="redoc" target="_blank">Redoc / Swagger</a> </p>
{% endblock %}

View File

@ -4,6 +4,6 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
path('api/', views.index, name='api_info'),
path('api/', views.api, name='api_info'),
path('generate/', views.show_synthea_form, name='generator_form'),
]

View File

@ -12,6 +12,10 @@ def index(request):
template_name = 'synthea/index.html'
return render(request,template_name,{})
def api(request):
template_name = 'synthea/api.html'
return render(request,template_name,{})
def show_synthea_form(request):
template_name = 'synthea/generator_form.html'