From fc90744e06373cad0c17b65f2b010c2b2a2a0e97 Mon Sep 17 00:00:00 2001 From: rkorytkowski Date: Fri, 8 Nov 2024 12:27:32 +0100 Subject: [PATCH] Fixing errors --- core/code_systems/serializers.py | 4 ++++ core/common/serializers.py | 2 +- core/concept_maps/serializers.py | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/code_systems/serializers.py b/core/code_systems/serializers.py index e80ab1d7..54a76ea4 100644 --- a/core/code_systems/serializers.py +++ b/core/code_systems/serializers.py @@ -3,6 +3,7 @@ from collections import OrderedDict from rest_framework import serializers +from rest_framework.exceptions import ValidationError from rest_framework.fields import CharField, BooleanField, SerializerMethodField, ChoiceField, \ DateTimeField @@ -288,6 +289,9 @@ def create(self, validated_data): else: owner = UserProfile.objects.filter(username=ident['owner_id']).first() + if not owner: + raise ValidationError(f"Cannot find owner of type {ident['owner_type']} and id {ident['owner_id']}") + source.set_parent(owner) source.source_type = 'CodeSystem' diff --git a/core/common/serializers.py b/core/common/serializers.py index 014f225b..8e1dc985 100644 --- a/core/common/serializers.py +++ b/core/common/serializers.py @@ -112,7 +112,7 @@ def convert_ocl_uri_to_fhir_url(uri, resource_type): @staticmethod def convert_fhir_url_to_ocl_uri(uri, resource_type): resource_type_uri = f"/{resource_type}/" - if uri.startswith('/orgs/') or uri.startswith('/users/'): + if uri and (uri.startswith('/orgs/') or uri.startswith('/users/')): # Recognize OCL FHIR relative URI uri = uri.replace('/ConceptMap/', resource_type_uri).replace('/CodeSystem/', resource_type_uri) \ .replace('/ValueSet/', resource_type_uri) diff --git a/core/concept_maps/serializers.py b/core/concept_maps/serializers.py index e106ebb4..3a9b591a 100644 --- a/core/concept_maps/serializers.py +++ b/core/concept_maps/serializers.py @@ -2,6 +2,7 @@ from collections import OrderedDict from rest_framework import serializers +from rest_framework.exceptions import ValidationError from rest_framework.fields import CharField, SerializerMethodField, \ DateTimeField @@ -164,6 +165,9 @@ def create(self, validated_data): else: owner = UserProfile.objects.filter(username=ident['owner_id']).first() + if not owner: + raise ValidationError(f"Cannot find owner of type {ident['owner_type']} and id {ident['owner_id']}") + source.set_parent(owner) source.source_type = 'ConceptMap'