示例#1
0
    study = StudySerializer()
    inclusion_criteria = serializers.StringRelatedField(many=True)
    exclusion_criteria = serializers.StringRelatedField(many=True)
    url = serializers.ReadOnlyField(source="get_absolute_url")
    protocol_type = serializers.ReadOnlyField(source="get_protocol_type_display")
    lit_search_strategy = serializers.ReadOnlyField(source="get_lit_search_strategy_display")
    results = MetaResultLinkSerializer(many=True)

    class Meta:
        model = models.MetaProtocol


class MetaResultSerializer(serializers.ModelSerializer):
    protocol = MetaProtocolSerializer()
    url = serializers.ReadOnlyField(source="get_absolute_url")
    metric = ResultMetricSerializer()
    adjustment_factors = serializers.StringRelatedField(many=True)
    single_results = SingleResultSerializer(many=True)

    def to_representation(self, instance):
        ret = super(MetaResultSerializer, self).to_representation(instance)
        ret['estimateFormatted'] = instance.estimate_formatted
        return ret

    class Meta:
        model = models.MetaResult


SerializerHelper.add_serializer(models.MetaProtocol, MetaProtocolSerializer)
SerializerHelper.add_serializer(models.MetaResult, MetaResultSerializer)
示例#2
0
    can_create_sets = serializers.BooleanField(read_only=True)
    effects = EffectTagsSerializer()
    diagnostic = serializers.CharField(source='get_diagnostic_display', read_only=True)
    url = serializers.CharField(source='get_absolute_url', read_only=True)
    results = ResultSerializer(many=True)
    comparison_sets = ComparisonSetLinkSerializer(many=True)

    class Meta:
        model = models.Outcome


class ComparisonSetSerializer(serializers.ModelSerializer):
    url = serializers.CharField(source='get_absolute_url', read_only=True)
    exposure = ExposureSerializer()
    outcome = OutcomeSerializer()
    study_population = StudyPopulationSerializer()
    groups = GroupSerializer(many=True)

    class Meta:
        model = models.ComparisonSet


class OutcomeCleanupFieldsSerializer(DynamicFieldsMixin, serializers.ModelSerializer):

    class Meta:
        model = models.Outcome
        cleanup_fields = model.TEXT_CLEANUP_FIELDS
        fields = cleanup_fields + ('id', )

SerializerHelper.add_serializer(models.Outcome, OutcomeSerializer)
示例#3
0
class FinalRobStudySerializer(StudySerializer):
    assessment = serializers.PrimaryKeyRelatedField(read_only=True)
    riskofbiases = RiskOfBiasSerializer(many=True, read_only=True)

    class Meta:
        model = models.Study
        exclude = (
            'searches',
            'identifiers',
        )

    def to_representation(self, instance):
        instance.riskofbiases = instance.riskofbiases.filter(final=True)
        ret = super().to_representation(instance)
        return ret


class StudyCleanupFieldsSerializer(DynamicFieldsMixin,
                                   serializers.ModelSerializer):
    class Meta:
        model = models.Study
        cleanup_fields = model.TEXT_CLEANUP_FIELDS
        fields = (
            'id',
            'short_citation',
        ) + cleanup_fields


SerializerHelper.add_serializer(models.Study, VerboseStudySerializer)
示例#4
0
    protocol_type = serializers.ReadOnlyField(
        source="get_protocol_type_display")
    lit_search_strategy = serializers.ReadOnlyField(
        source="get_lit_search_strategy_display")
    results = MetaResultLinkSerializer(many=True)

    class Meta:
        model = models.MetaProtocol
        fields = '__all__'


class MetaResultSerializer(serializers.ModelSerializer):
    protocol = MetaProtocolSerializer()
    url = serializers.ReadOnlyField(source="get_absolute_url")
    metric = ResultMetricSerializer()
    adjustment_factors = serializers.StringRelatedField(many=True)
    single_results = SingleResultSerializer(many=True)

    def to_representation(self, instance):
        ret = super().to_representation(instance)
        ret['estimateFormatted'] = instance.estimate_formatted
        return ret

    class Meta:
        model = models.MetaResult
        fields = '__all__'


SerializerHelper.add_serializer(models.MetaProtocol, MetaProtocolSerializer)
SerializerHelper.add_serializer(models.MetaResult, MetaResultSerializer)
示例#5
0
    study = StudyAssessmentSerializer(read_only=True)
    type_display = serializers.CharField(source='get_type_display')
    status_display = serializers.CharField(source='get_status_display')

    class Meta:
        model = models.Task
        fields = '__all__'
        read_only_fields = (
            'id',
            'study',
            'open',
            'started',
            'completed',
        )

    def update(self, instance, validated_data):
        if self.initial_data['owner']:
            owner_id = self.initial_data['owner']['id']
            instance.owner = HAWCUser.objects.get(pk=owner_id)
            instance.save()
        return super().update(instance, validated_data)


class TaskByAssessmentSerializer(TaskSerializer):
    study = StudyAssessmentSerializer(read_only=True)

    class Meta(TaskSerializer.Meta):
        depth = 2

SerializerHelper.add_serializer(models.Task, TaskSerializer)
示例#6
0
        ret["settings"] = settings
        return ret

    class Meta:
        model = models.Visual
        exclude = ('endpoints', )


class VisualSerializer(CollectionVisualSerializer):

    def to_representation(self, instance):
        ret = super().to_representation(instance)

        ret['url_update'] = instance.get_update_url()
        ret['url_delete'] = instance.get_delete_url()

        ret["endpoints"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_endpoints()
        ]

        ret["studies"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_studies()
        ]

        return ret


SerializerHelper.add_serializer(models.Visual, VisualSerializer)
示例#7
0
    class Meta:
        model = models.StudyQuality
        exclude = ('object_id', 'content_type')


class StudySerializer(serializers.ModelSerializer):

    def to_representation(self, instance):
        ret = super(StudySerializer, self).to_representation(instance)
        ret['study_type'] = instance.get_study_type_display()
        ret['coi_reported'] = instance.get_coi_reported_display()
        ret['url'] = instance.get_absolute_url()
        return ret

    class Meta:
        model = models.Study


class VerboseStudySerializer(StudySerializer):
    assessment = serializers.PrimaryKeyRelatedField(read_only=True)
    searches = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
    qualities = StudyQualitySerializer(many=True, read_only=True)
    identifiers = IdentifiersSerializer(many=True)
    tags = ReferenceTagsSerializer()

    class Meta:
        model = models.Study


SerializerHelper.add_serializer(models.Study, VerboseStudySerializer)
示例#8
0
    class Meta:
        model = models.RiskOfBiasScore
        fields = ('id', 'score', 'notes', 'metric')


class RiskOfBiasSerializer(serializers.ModelSerializer):
    scores = RiskOfBiasScoreSerializer(read_only=False, many=True, partial=True)
    author = HAWCUserSerializer(read_only=True)

    class Meta:
        model = models.RiskOfBias
        fields = ('id', 'author', 'active',
                  'final', 'study', 'created',
                  'last_updated', 'scores')

    def update(self, instance, validated_data):
        """
        Updates the nested RiskOfBiasScores with submitted data before updating
        the RiskOfBias instance.
        """
        score_data = validated_data.pop('scores')
        for score, form_data in zip(instance.scores.all(), score_data):
            for field, value in form_data.items():
                setattr(score, field, value)
            score.save()
        return super(RiskOfBiasSerializer, self).update(instance, validated_data)


SerializerHelper.add_serializer(models.RiskOfBias, RiskOfBiasSerializer)
示例#9
0
from rest_framework import serializers

from utils.helper import SerializerHelper

from . import models


class HAWCUserSerializer(serializers.ModelSerializer):
    full_name = serializers.CharField(source='get_full_name')

    class Meta:
        model = models.HAWCUser
        fields = (
            'id',
            'full_name',
        )


SerializerHelper.add_serializer(models.HAWCUser, HAWCUserSerializer)
示例#10
0
        models.EndpointGroup.percentControl(ret['data_type'], ret['endpoint_group'])

        # get individual animal data
        if instance.individual_animal_data:
            models.EndpointGroup.getIndividuals(instance, ret['endpoint_group'])

        # get BMD
        ret['BMD'] = None
        try:
            model = instance.BMD_session.latest().selected_model
            if model is not None:
                ret['BMD'] = BMDModelRunSerializer().to_representation(model)
        except instance.BMD_session.model.DoesNotExist:
            pass

        return ret

    class Meta:
        model = models.Endpoint


class AggregationSerializer(serializers.ModelSerializer):
    endpoints = EndpointSerializer(many=True)

    class Meta:
        model = models.Aggregation


SerializerHelper.add_serializer(models.Endpoint, EndpointSerializer)
SerializerHelper.add_serializer(models.Aggregation, AggregationSerializer)
示例#11
0
    url = serializers.CharField(source='get_absolute_url', read_only=True)
    results = ResultSerializer(many=True)
    comparison_sets = ComparisonSetLinkSerializer(many=True)

    class Meta:
        model = models.Outcome
        fields = '__all__'


class ComparisonSetSerializer(serializers.ModelSerializer):
    url = serializers.CharField(source='get_absolute_url', read_only=True)
    exposure = ExposureSerializer()
    outcome = OutcomeSerializer()
    study_population = StudyPopulationSerializer()
    groups = GroupSerializer(many=True)

    class Meta:
        model = models.ComparisonSet
        fields = '__all__'


class OutcomeCleanupFieldsSerializer(DynamicFieldsMixin,
                                     serializers.ModelSerializer):
    class Meta:
        model = models.Outcome
        cleanup_fields = model.TEXT_CLEANUP_FIELDS
        fields = cleanup_fields + ('id', )


SerializerHelper.add_serializer(models.Outcome, OutcomeSerializer)
示例#12
0
from rest_framework import serializers

from utils.helper import SerializerHelper

from . import models


class HAWCUserSerializer(serializers.ModelSerializer):
    full_name = serializers.CharField(source='get_full_name')

    class Meta:
        model = models.HAWCUser
        fields = ('id', 'full_name', )

SerializerHelper.add_serializer(models.HAWCUser, HAWCUserSerializer)
示例#13
0
            settings = {}
        ret["settings"] = settings
        return ret

    class Meta:
        model = models.Visual
        exclude = ('endpoints', )


class VisualSerializer(CollectionVisualSerializer):
    def to_representation(self, instance):
        ret = super().to_representation(instance)

        ret['url_update'] = instance.get_update_url()
        ret['url_delete'] = instance.get_delete_url()

        ret["endpoints"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_endpoints()
        ]

        ret["studies"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_studies()
        ]

        return ret


SerializerHelper.add_serializer(models.Visual, VisualSerializer)
示例#14
0
    endpoints = MiniIVEndpointSerializer(many=True)


class IVEndpointCleanupFieldsSerializer(DynamicFieldsMixin,
                                        serializers.ModelSerializer):
    study_short_citation = serializers.SerializerMethodField()

    class Meta:
        model = models.IVEndpoint
        cleanup_fields = ('study_short_citation', ) + model.TEXT_CLEANUP_FIELDS
        fields = cleanup_fields + ('id', )

    def get_study_short_citation(self, obj):
        return obj.experiment.study.short_citation


class IVChemicalCleanupFieldsSerializer(DynamicFieldsMixin,
                                        serializers.ModelSerializer):
    study_short_citation = serializers.SerializerMethodField()

    class Meta:
        model = models.IVChemical
        cleanup_fields = ('study_short_citation', ) + model.TEXT_CLEANUP_FIELDS
        fields = cleanup_fields + ('id', )

    def get_study_short_citation(self, obj):
        return obj.study.short_citation


SerializerHelper.add_serializer(models.IVEndpoint, IVEndpointSerializer)
示例#15
0
        ret = super(MetaProtocolSerializer, self).to_representation(instance)
        ret['url'] = instance.get_absolute_url()
        ret['protocol_type'] = instance.get_protocol_type_display()
        ret['lit_search_strategy'] = instance.get_lit_search_strategy_display()
        return ret

    class Meta:
        model = models.MetaProtocol


class MetaResultSerializer(serializers.ModelSerializer):
    protocol = MetaProtocolSerializer()
    statistical_metric = StatisticalMetricSerializer()
    single_results = SingleResultSerializer(many=True)
    adjustment_factors = serializers.StringRelatedField(many=True)

    def to_representation(self, instance):
        ret = super(MetaResultSerializer, self).to_representation(instance)
        ret['url'] = instance.get_absolute_url()
        ret['estimateFormatted'] = instance.estimate_formatted
        return ret

    class Meta:
        model = models.MetaResult


SerializerHelper.add_serializer(models.StudyPopulation, StudyPopulationSerializer)
SerializerHelper.add_serializer(models.AssessedOutcome, AssessedOutcomeSerializer)
SerializerHelper.add_serializer(models.MetaProtocol, MetaProtocolSerializer)
SerializerHelper.add_serializer(models.MetaResult, MetaResultSerializer)
示例#16
0
    experiment = serializers.PrimaryKeyRelatedField(read_only=True)
    chemical = _IVChemicalSerializer()
    groups = serializers.PrimaryKeyRelatedField(read_only=True, many=True)
    benchmarks = serializers.PrimaryKeyRelatedField(read_only=True, many=True)
    category = serializers.PrimaryKeyRelatedField(read_only=True)

    def to_representation(self, instance):
        ret = super(MiniIVEndpointSerializer, self).to_representation(instance)
        ret['url'] = instance.get_absolute_url()
        return ret

    class Meta:
        model = models.IVEndpoint


class IVExperimentSerializerFull(IVExperimentSerializer):
    url_update = serializers.CharField(source='get_update_url', read_only=True)
    url_delete = serializers.CharField(source='get_delete_url', read_only=True)
    url_create_endpoint = serializers.CharField(source='get_endpoint_create_url', read_only=True)
    endpoints = MiniIVEndpointSerializer(many=True)


class CleanupFieldsSerializer(DynamicFieldsMixin, serializers.ModelSerializer):

    class Meta:
        model = models.IVEndpoint
        cleanup_fields = model.text_cleanup_fields()
        fields = cleanup_fields + ('id', 'name')

SerializerHelper.add_serializer(models.IVEndpoint, IVEndpointSerializer)
示例#17
0
        """
        score_data = validated_data.pop('scores')
        for score, form_data in zip(instance.scores.all(), score_data):
            for field, value in list(form_data.items()):
                setattr(score, field, value)
            score.save()
        return super().update(instance, validated_data)


class AssessmentMetricScoreSerializer(serializers.ModelSerializer):
    scores = serializers.SerializerMethodField('get_final_score')

    class Meta:
        model = models.RiskOfBiasMetric
        fields = ('id', 'name', 'description', 'scores')

    def get_final_score(self, instance):
        scores = instance.scores.filter(riskofbias__final=True,
                                        riskofbias__active=True)
        serializer = RiskOfBiasScoreSerializer(scores, many=True)
        return serializer.data


class AssessmentRiskOfBiasScoreSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.RiskOfBiasScore
        fields = ('id', 'notes', 'score')


SerializerHelper.add_serializer(models.RiskOfBias, RiskOfBiasSerializer)