Skip to content

Commit

Permalink
Merge pull request #57 from EBI-G2P/fix/lgd_curators_list
Browse files Browse the repository at this point in the history
Update record endpoint to return list of curators
  • Loading branch information
olaaustine authored Oct 28, 2024
2 parents b31e482 + 439f0b9 commit ec25c73
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework import serializers
from django.db import connection
from datetime import datetime
import itertools

from ..models import (Panel, Attrib,
LGDPanel, LocusGenotypeDisease, LGDVariantGenccConsequence,
Expand Down Expand Up @@ -42,6 +43,7 @@ class LocusGenotypeDiseaseSerializer(serializers.ModelSerializer):
last_updated = serializers.SerializerMethodField()
date_created = serializers.SerializerMethodField()
comments = serializers.SerializerMethodField(allow_null=True)
curators = serializers.SerializerMethodField(allow_null=True)
is_reviewed = serializers.IntegerField(allow_null=True, required=False)

def get_locus(self, id):
Expand Down Expand Up @@ -254,6 +256,49 @@ def get_date_created(self, id):

return date

def get_curators(self, id):
"""
List of curators who worked on the LGD record.
Dependency: this method depends on the history table.
Note: entries that were migrated from the old db have limited info details.
"""
list_curators = set()
lgd_obj = self.instance
# Check LGD record history
history_records = lgd_obj.history.all().values('history_user__first_name', 'history_user__last_name')
# Check LGD cross cutting modifier history
history_records_ccm = LGDCrossCuttingModifier.history.filter(lgd=lgd_obj).values(
'history_user__first_name', 'history_user__last_name')
# Check LGD panel history
history_records_lgdpanel = LGDPanel.history.filter(lgd=lgd_obj).values(
'history_user__first_name', 'history_user__last_name')
# Check LGD phenotype history
history_records_lgdpheno = LGDPhenotype.history.filter(lgd=lgd_obj).values(
'history_user__first_name', 'history_user__last_name')
# Check LGD publication history
history_records_lgdpublication = LGDPublication.history.filter(lgd=lgd_obj).values(
'history_user__first_name', 'history_user__last_name')
# Check LGD variation GenCC consequence history
history_records_lgdvarcons = LGDVariantGenccConsequence.history.filter(lgd=lgd_obj).values(
'history_user__first_name', 'history_user__last_name')
# Check LGD variation type history
history_records_lgdvartype = LGDVariantType.history.filter(lgd=lgd_obj).values(
'history_user__first_name', 'history_user__last_name')
# Check LGD variation type description history
history_records_lgdvartype_desc = LGDVariantTypeDescription.history.filter(lgd=lgd_obj).values(
'history_user__first_name', 'history_user__last_name')

for record in itertools.chain(history_records, history_records_ccm, history_records_lgdpanel,
history_records_lgdpheno, history_records_lgdpublication,
history_records_lgdvarcons, history_records_lgdvartype,
history_records_lgdvartype_desc):
first_name = record.get('history_user__first_name')
last_name = record.get('history_user__last_name')
list_curators.add(f"{first_name} {last_name}")

return list_curators

def check_user_permission(self, id, user_panels):
"""
Check if user has permission to update this G2P record.
Expand Down

0 comments on commit ec25c73

Please sign in to comment.