-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #852 from Health-Informatics-UoN/feat/refactor-str…
…ucture Feat/refactor structure
- Loading branch information
Showing
26 changed files
with
1,697 additions
and
1,516 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from api import deprecated_views | ||
from rest_framework import routers | ||
|
||
router = routers.DefaultRouter() | ||
|
||
|
||
router.register(r"omop/concepts", deprecated_views.ConceptViewSet, basename="concepts") | ||
router.register( | ||
r"omop/conceptsfilter", | ||
deprecated_views.ConceptFilterViewSet, | ||
basename="conceptsfilter", | ||
) | ||
router.register( | ||
r"scanreports", deprecated_views.ScanReportListViewSet, basename="scanreports" | ||
) | ||
router.register( | ||
r"scanreporttables", | ||
deprecated_views.ScanReportTableViewSet, | ||
basename="scanreporttables", | ||
) | ||
router.register( | ||
r"scanreportfields", | ||
deprecated_views.ScanReportFieldViewSet, | ||
basename="scanreportfields", | ||
) | ||
router.register( | ||
r"scanreportvalues", | ||
deprecated_views.ScanReportValueViewSet, | ||
basename="scanreportvalues", | ||
) | ||
router.register( | ||
r"scanreportconcepts", | ||
deprecated_views.ScanReportConceptViewSet, | ||
basename="scanreportconcepts", | ||
) | ||
router.register( | ||
r"scanreportconceptsfilter", | ||
deprecated_views.ScanReportConceptFilterViewSet, | ||
basename="scanreportconceptsfilter", | ||
) | ||
router.register(r"omoptables", deprecated_views.OmopTableViewSet, basename="omoptables") | ||
router.register(r"omopfields", deprecated_views.OmopFieldViewSet, basename="omopfields") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
from drf_dynamic_fields import DynamicFieldsMixin # type: ignore | ||
from rest_framework import serializers | ||
from rest_framework.exceptions import NotFound, PermissionDenied | ||
from shared.mapping.models import ( | ||
OmopField, | ||
OmopTable, | ||
ScanReport, | ||
ScanReportField, | ||
ScanReportTable, | ||
ScanReportValue, | ||
) | ||
from shared.mapping.permissions import has_editorship, is_admin, is_az_function_user | ||
|
||
|
||
class ScanReportViewSerializer(DynamicFieldsMixin, serializers.ModelSerializer): | ||
def validate(self, data): | ||
if request := self.context.get("request"): | ||
if ds := data.get("parent_dataset"): | ||
if not ( | ||
is_az_function_user(request.user) | ||
or is_admin(ds, request) | ||
or has_editorship(ds, request) | ||
): | ||
raise PermissionDenied( | ||
"You must be an admin of the parent dataset to add a new scan report to it.", | ||
) | ||
else: | ||
raise NotFound("Could not find parent dataset.") | ||
else: | ||
raise serializers.ValidationError( | ||
"Missing request context. Unable to validate scan report." | ||
) | ||
return super().validate(data) | ||
|
||
class Meta: | ||
model = ScanReport | ||
fields = "__all__" | ||
|
||
|
||
class ScanReportTableListSerializer(DynamicFieldsMixin, serializers.ModelSerializer): | ||
def validate(self, data): | ||
if request := self.context.get("request"): | ||
if sr := data.get("scan_report"): | ||
if not ( | ||
is_az_function_user(request.user) | ||
or is_admin(sr, request) | ||
or has_editorship(sr, request) | ||
): | ||
raise PermissionDenied( | ||
"You must have editor or admin privileges on the scan report to edit its tables.", | ||
) | ||
else: | ||
raise NotFound("Could not find the scan report for this table.") | ||
else: | ||
raise serializers.ValidationError( | ||
"Missing request context. Unable to validate scan report table." | ||
) | ||
return super().validate(data) | ||
|
||
class Meta: | ||
model = ScanReportTable | ||
fields = "__all__" | ||
|
||
|
||
class ScanReportValueViewSerializer(DynamicFieldsMixin, serializers.ModelSerializer): | ||
value = serializers.CharField( | ||
max_length=128, allow_blank=True, trim_whitespace=False | ||
) | ||
|
||
def validate(self, data): | ||
if request := self.context.get("request"): | ||
if srf := data.get("scan_report_field"): | ||
if not ( | ||
is_az_function_user(request.user) | ||
or is_admin(srf, request) | ||
or has_editorship(srf, request) | ||
): | ||
raise PermissionDenied( | ||
"You must have editor or admin privileges on the scan report to edit its values.", | ||
) | ||
else: | ||
raise NotFound("Could not find the scan report field for this value.") | ||
else: | ||
raise serializers.ValidationError( | ||
"Missing request context. Unable to validate scan report value." | ||
) | ||
return super().validate(data) | ||
|
||
class Meta: | ||
model = ScanReportValue | ||
fields = "__all__" | ||
|
||
|
||
class ScanReportValueEditSerializer(DynamicFieldsMixin, serializers.ModelSerializer): | ||
value = serializers.CharField( | ||
max_length=128, allow_blank=True, trim_whitespace=False | ||
) | ||
|
||
class Meta: | ||
model = ScanReportValue | ||
fields = "__all__" | ||
|
||
|
||
class ScanReportFieldListSerializer(DynamicFieldsMixin, serializers.ModelSerializer): | ||
name = serializers.CharField( | ||
max_length=512, allow_blank=True, trim_whitespace=False | ||
) | ||
description_column = serializers.CharField( | ||
max_length=512, allow_blank=True, trim_whitespace=False | ||
) | ||
|
||
def validate(self, data): | ||
if request := self.context.get("request"): | ||
if srt := data.get("scan_report_table"): | ||
if not ( | ||
is_az_function_user(request.user) | ||
or is_admin(srt, request) | ||
or has_editorship(srt, request) | ||
): | ||
raise PermissionDenied( | ||
"You must have editor or admin privileges on the scan report to edit its fields.", | ||
) | ||
else: | ||
raise NotFound("Could not find the scan report table for this field.") | ||
else: | ||
raise serializers.ValidationError( | ||
"Missing request context. Unable to validate scan report field." | ||
) | ||
return super().validate(data) | ||
|
||
class Meta: | ||
model = ScanReportField | ||
fields = "__all__" | ||
|
||
|
||
class OmopFieldSerializer(DynamicFieldsMixin, serializers.ModelSerializer): | ||
class Meta: | ||
model = OmopField | ||
fields = "__all__" | ||
|
||
|
||
class OmopTableSerializer(DynamicFieldsMixin, serializers.ModelSerializer): | ||
class Meta: | ||
model = OmopTable | ||
fields = "__all__" | ||
|
||
|
||
class ContentTypeSerializer(serializers.Serializer): | ||
""" | ||
Serializes the content type name. | ||
Args: | ||
self: The instance of the class. | ||
Attributes: | ||
type_name: The serialized content type name. | ||
""" | ||
|
||
type_name = serializers.CharField(max_length=100) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from api import deprecated_views | ||
from django.urls import path | ||
|
||
urlpatterns = [ | ||
path( | ||
r"contenttypeid", | ||
deprecated_views.GetContentTypeID.as_view(), | ||
name="contenttypeid", | ||
), | ||
path( | ||
r"countprojects/<int:dataset>", | ||
deprecated_views.CountProjects.as_view(), | ||
name="countprojects", | ||
), | ||
path(r"countstats/", deprecated_views.CountStats.as_view(), name="countstats"), | ||
path( | ||
r"countstatsscanreport/", | ||
deprecated_views.CountStatsScanReport.as_view(), | ||
name="countstatsscanreport", | ||
), | ||
path( | ||
r"countstatsscanreporttable/", | ||
deprecated_views.CountStatsScanReportTable.as_view(), | ||
name="countstatsscanreporttable", | ||
), | ||
path( | ||
r"countstatsscanreporttablefield/", | ||
deprecated_views.CountStatsScanReportTableField.as_view(), | ||
name="countstatsscanreporttablefield", | ||
), | ||
] |
Oops, something went wrong.