Ejemplo n.º 1
0
    def get_editing_dataset(self, request):
        # Generate a pseudo-return when editing or creating a dataset.
        # Do not include the settings field; this will be set from the
        # input-form. Should approximately mirror the Visual API from rest-framework.

        dose_units = None
        try:
            dose_units = int(request.POST.get("dose_units"))
        except (TypeError, ValueError) as e:
            # TypeError if dose_units is None; ValueError if dose_units is ""
            pass

        data = {
            "title": request.POST.get("title"),
            "slug": request.POST.get("slug"),
            "caption": request.POST.get("caption"),
            "dose_units": dose_units,
            "created": datetime.now().isoformat(),
            "last_updated": datetime.now().isoformat()
        }

        data["endpoints"] = [
            SerializerHelper.get_serialized(e, json=False)
            for e in self.get_endpoints(request)
        ]

        data["studies"] = [
            SerializerHelper.get_serialized(s, json=False)
            for s in self.get_studies(request)
        ]

        return json.dumps(data)
Ejemplo n.º 2
0
    def get_editing_dataset(self, request):
        # Generate a pseudo-return when editing or creating a dataset.
        # Do not include the settings field; this will be set from the
        # input-form. Should approximately mirror the Visual API from rest-framework.

        dose_units = None
        try:
            dose_units = int(request.POST.get("dose_units"))
        except (TypeError, ValueError) as e:
            # TypeError if dose_units is None; ValueError if dose_units is ""
            pass

        data = {
            "title": request.POST.get("title"),
            "slug": request.POST.get("slug"),
            "caption": request.POST.get("caption"),
            "dose_units": dose_units,
            "created": datetime.now().isoformat(),
            "last_updated": datetime.now().isoformat()
        }

        data["endpoints"] = [
            SerializerHelper.get_serialized(e, json=False)
            for e in self.get_endpoints(request)
        ]

        data["studies"] = [
            SerializerHelper.get_serialized(s, json=False)
            for s in self.get_studies(request)
        ]

        return json.dumps(data)
Ejemplo n.º 3
0
    def get_docx_template_context(assessment, queryset):
        """
        Given a queryset of endpoints, invert the cached results to build
        a top-down data hierarchy from study to endpoint. We use this
        approach since our endpoints are cached, so while it may require
        more computation, its close to free on database access.
        """

        endpoints = [
            SerializerHelper.get_serialized(obj, json=False)
            for obj in queryset
        ]
        studies = {}

        # flip dictionary nesting
        for thisEp in endpoints:
            thisAG = thisEp["animal_group"]
            thisExp = thisEp["animal_group"]["experiment"]
            thisStudy = thisEp["animal_group"]["experiment"]["study"]

            study = studies.get(thisStudy["id"])
            if study is None:
                study = thisStudy
                study["exps"] = {}
                studies[study["id"]] = study

            exp = study["exps"].get(thisExp["id"])
            if exp is None:
                exp = thisExp
                exp["ags"] = {}
                study["exps"][exp["id"]] = exp

            ag = exp["ags"].get(thisAG["id"])
            if ag is None:
                ag = thisAG
                ag["eps"] = {}
                exp["ags"][ag["id"]] = ag

            ep = ag["eps"].get(thisEp["id"])
            if ep is None:
                ep = thisEp
                ag["eps"][ep["id"]] = ep

        # convert value dictionaries to lists
        studies = sorted(list(studies.values()),
                         key=lambda obj: (obj["short_citation"].lower()))
        for study in studies:
            study["exps"] = sorted(list(study["exps"].values()),
                                   key=lambda obj: (obj["name"].lower()))
            for exp in study["exps"]:
                exp["ags"] = sorted(list(exp["ags"].values()),
                                    key=lambda obj: (obj["name"].lower()))
                for ag in exp["ags"]:
                    ag["eps"] = sorted(list(ag["eps"].values()),
                                       key=lambda obj: (obj["name"].lower()))

        return {
            "assessment": AssessmentSerializer().to_representation(assessment),
            "studies": studies
        }
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 def get_docx_template_context(cls, assessment, queryset):
     studies = [
         SerializerHelper.get_serialized(study, json=False)
         for study in queryset
     ]
     return {
         "assessment": AssessmentSerializer().to_representation(assessment),
         "studies": studies
     }
Ejemplo n.º 7
0
 def get_json(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode)
Ejemplo n.º 8
0
 def get_json(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode)
Ejemplo n.º 9
0
    def get_docx_template_context(cls, assessment, queryset):
        """
        Given a queryset of endpoints, invert the cached results to build
        a top-down data hierarchy from study to endpoint. We use this
        approach since our endpoints are cached, so while it may require
        more computation, its close to free on database access.
        """

        endpoints = [
            SerializerHelper.get_serialized(obj, json=False)
            for obj in queryset
        ]
        studies = {}

        # flip dictionary nesting
        for thisEp in endpoints:
            thisAG = thisEp["animal_group"]
            thisExp = thisEp["animal_group"]["experiment"]
            thisStudy = thisEp["animal_group"]["experiment"]["study"]

            study = studies.get(thisStudy["id"])
            if study is None:
                study = thisStudy
                study["exps"] = {}
                studies[study["id"]] = study

            exp = study["exps"].get(thisExp["id"])
            if exp is None:
                exp = thisExp
                exp["ags"] = {}
                study["exps"][exp["id"]] = exp

            ag = exp["ags"].get(thisAG["id"])
            if ag is None:
                ag = thisAG
                ag["eps"] = {}
                exp["ags"][ag["id"]] = ag

            ep = ag["eps"].get(thisEp["id"])
            if ep is None:
                ep = thisEp
                ag["eps"][ep["id"]] = ep

        # convert value dictionaries to lists
        studies = sorted(
            studies.values(),
            key=lambda obj: (obj["short_citation"].lower()))
        for study in studies:
            study["exps"] = sorted(
                study["exps"].values(),
                key=lambda obj: (obj["name"].lower()))
            for exp in study["exps"]:
                exp["ags"] = sorted(
                    exp["ags"].values(),
                    key=lambda obj: (obj["name"].lower()))
                for ag in exp["ags"]:
                    ag["eps"] = sorted(
                        ag["eps"].values(),
                        key=lambda obj: (obj["name"].lower()))

        return {
            "assessment": AssessmentSerializer().to_representation(assessment),
            "studies": studies
        }
Ejemplo n.º 10
0
 def d_response(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode)
Ejemplo n.º 11
0
 def get_docx_template_context(assessment, queryset):
     studies = [SerializerHelper.get_serialized(study, json=False) for study in queryset]
     return {
         "assessment": AssessmentSerializer().to_representation(assessment),
         "studies": studies
     }
Ejemplo n.º 12
0
 def get_json(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode, from_cache=False)
Ejemplo n.º 13
0
    def get_docx_template_context(assessment, queryset):
        """
        Given a queryset of meta-results, invert the cached results to build
        a top-down data hierarchy from study to meta-result. We use this
        approach since our meta-results are cached, so while it may require
        more computation, its close to free on database access.
        """

        def getStatMethods(mr):
            key = "{}|{}".format(
                mr["adjustments_list"],
                mr["statistical_notes"]
            )
            return key, mr

        results = [
            SerializerHelper.get_serialized(obj, json=False)
            for obj in queryset
        ]
        studies = {}

        # flip dictionary nesting
        for thisMr in results:
            thisPro = thisMr["protocol"]
            thisStudy = thisMr["protocol"]["study"]

            study = studies.get(thisStudy["id"])
            if study is None:
                study = thisStudy
                study["protocols"] = {}
                studies[study["id"]] = study

            pro = study["protocols"].get(thisPro["id"])
            if pro is None:
                pro = thisPro
                pro["inclusion_list"] = ', '.join(pro["inclusion_criteria"])
                pro["exclusion_list"] = ', '.join(pro["exclusion_criteria"])
                pro["results"] = {}
                pro["statistical_methods"] = {}
                study["protocols"][pro["id"]] = pro

            mr = pro["results"].get(thisMr["id"])
            if mr is None:
                mr = thisMr
                mr["ci_percent"] = int(mr["ci_units"] * 100.)
                mr["adjustments_list"] = ', '.join(
                    sorted(mr["adjustment_factors"]))
                pro["results"][mr["id"]] = mr

            statKey, statVal = getStatMethods(thisMr)
            stats = pro["statistical_methods"].get(statKey)
            if stats is None:
                stats = statVal
                pro["statistical_methods"][statKey] = statVal
                stats["sm_endpoints"] = []
            stats["sm_endpoints"].append(thisMr)

        # convert value dictionaries to lists
        studies = sorted(
            list(studies.values()),
            key=lambda obj: (obj["short_citation"].lower()))
        for study in studies:
            study["protocols"] = sorted(
                list(study["protocols"].values()),
                key=lambda obj: (obj["name"].lower()))
            for pro in study["protocols"]:
                pro["results"] = sorted(
                    list(pro["results"].values()),
                    key=lambda obj: (obj["label"].lower()))
                pro["statistical_methods"] = list(pro["statistical_methods"].values())
                for obj in pro["statistical_methods"]:
                    obj["sm_endpoints"] = "; ".join([
                        d["label"] for d in obj["sm_endpoints"]
                    ])

        return {
            "assessment": AssessmentSerializer().to_representation(assessment),
            "studies": studies
        }
Ejemplo n.º 14
0
 def get_json(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode, from_cache=False)
Ejemplo n.º 15
0
    def get_docx_template_context(assessment, queryset):
        """
        Given a queryset of meta-results, invert the cached results to build
        a top-down data hierarchy from study to meta-result. We use this
        approach since our meta-results are cached, so while it may require
        more computation, its close to free on database access.
        """

        def getStatMethods(mr):
            key = "{}|{}".format(
                mr["adjustments_list"],
                mr["statistical_notes"]
            )
            return key, mr

        results = [
            SerializerHelper.get_serialized(obj, json=False)
            for obj in queryset
        ]
        studies = {}

        # flip dictionary nesting
        for thisMr in results:
            thisPro = thisMr["protocol"]
            thisStudy = thisMr["protocol"]["study"]

            study = studies.get(thisStudy["id"])
            if study is None:
                study = thisStudy
                study["protocols"] = {}
                studies[study["id"]] = study

            pro = study["protocols"].get(thisPro["id"])
            if pro is None:
                pro = thisPro
                pro["inclusion_list"] = ', '.join(pro["inclusion_criteria"])
                pro["exclusion_list"] = ', '.join(pro["exclusion_criteria"])
                pro["results"] = {}
                pro["statistical_methods"] = {}
                study["protocols"][pro["id"]] = pro

            mr = pro["results"].get(thisMr["id"])
            if mr is None:
                mr = thisMr
                mr["ci_percent"] = int(mr["ci_units"] * 100.)
                mr["adjustments_list"] = ', '.join(
                    sorted(mr["adjustment_factors"]))
                pro["results"][mr["id"]] = mr

            statKey, statVal = getStatMethods(thisMr)
            stats = pro["statistical_methods"].get(statKey)
            if stats is None:
                stats = statVal
                pro["statistical_methods"][statKey] = statVal
                stats["sm_endpoints"] = []
            stats["sm_endpoints"].append(thisMr)

        # convert value dictionaries to lists
        studies = sorted(
            list(studies.values()),
            key=lambda obj: (obj["short_citation"].lower()))
        for study in studies:
            study["protocols"] = sorted(
                list(study["protocols"].values()),
                key=lambda obj: (obj["name"].lower()))
            for pro in study["protocols"]:
                pro["results"] = sorted(
                    list(pro["results"].values()),
                    key=lambda obj: (obj["label"].lower()))
                pro["statistical_methods"] = list(pro["statistical_methods"].values())
                for obj in pro["statistical_methods"]:
                    obj["sm_endpoints"] = "; ".join([
                        d["label"] for d in obj["sm_endpoints"]
                    ])

        return {
            "assessment": AssessmentSerializer().to_representation(assessment),
            "studies": studies
        }
Ejemplo n.º 16
0
 def d_response(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode)