Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Add Analysis Batch Summary endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Veni Kunche authored and Veni Kunche committed Sep 21, 2017
1 parent cd9b174 commit 8cd2af8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
68 changes: 68 additions & 0 deletions lideservices/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,74 @@ class Meta:
model = AnalysisBatch
fields = ('id', 'analysis_batch_description', 'analysis_batch_notes','samples','studies','extractions','created_date','created_by','modified_date','modified_by',)

class AnalysisBatchSummarySerializer(serializers.ModelSerializer):

#studies
def get_studies(self, obj):
studies = []
vals = obj.samples.values()
for val in vals:
study_id = val.get('study_id')
studies.append(study_id)
return studies
studies = serializers.SerializerMethodField()

#summary: extraction count, inhibition count, reverse transcription count, target count
def get_summary(self, obj):
summary = {}
inhibition_count = 0
reverse_transcription_count = 0
targets = []

extractions = obj.extractions.values()

#extraction count
extraction_count = len(extractions)

for val in extractions:
extraction_id = val.get('id')

#inhibition count
inhibition_count += len(Inhibition.objects.filter(extraction=extraction_id))

#reverse transcription count
reverse_transcription_count += len(ReverseTranscription.objects.filter(extraction=extraction_id))

#target count
replicates = PCRReplicate.objects.filter(extraction=extraction_id)
for replicate in replicates:
target = replicate.target
if target not in targets:
targets.append(replicate.target)

summary['extraction_count'] = extraction_count
summary['inhibition_count'] = inhibition_count
summary['reverse_transcription_count'] = reverse_transcription_count
summary['target_count'] = len(targets)

return summary
summary = serializers.SerializerMethodField()

#created by username
def get_created_by(self, obj):
username = None
if obj.created_by is not None:
username = obj.created_by.username
return username
created_by = serializers.StringRelatedField()

#modified by username
def get_modified_by(self, obj):
username = None
if obj.modified_by is not None:
username = obj.modified_by.username
return username
modified_by = serializers.StringRelatedField()

class Meta:
model = AnalysisBatch
fields = ('id', 'analysis_batch_description', 'analysis_batch_notes','studies','summary','created_date','created_by','modified_date','modified_by',)


######
#
Expand Down
1 change: 1 addition & 0 deletions lideservices/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
router.register(r'samplegroups', views.SampleGroupViewSet, 'samplegroups')
router.register(r'analysisbatches', views.AnalysisBatchViewSet, 'analysisbatches')
router.register(r'analysisbatchdetail', views.AnalysisBatchDetailViewSet, 'analysisbatchdetail')
router.register(r'analysisbatchsummary', views.AnalysisBatchSummaryViewSet, 'analysisbatchsummary')
router.register(r'analysisbatchtemplatess', views.AnalysisBatchTemplateViewSet, 'analysisbatchtemplates')
router.register(r'extractions', views.ExtractionViewSet, 'extractions')
router.register(r'extractionmethods', views.ExtractionMethodViewSet, 'extractionmethods')
Expand Down
4 changes: 4 additions & 0 deletions lideservices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def get_queryset(self):
if batch is not None:
queryset = queryset.filter(id__exact=batch)
return queryset

class AnalysisBatchSummaryViewSet(HistoryViewSet):
queryset = AnalysisBatch.objects.all()
serializer_class = AnalysisBatchSummarySerializer


class AnalysisBatchTemplateViewSet(HistoryViewSet):
Expand Down

0 comments on commit 8cd2af8

Please sign in to comment.