class CategoryFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_analyses.models.category.Category` model. """ title = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) description = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) parent = filters.CharFilter(field_name="parent__title") is_root = filters.BooleanFilter(field_name="parent", method="filter_is_root") class Meta: model = Category fields = "id", "title", "description", "parent", "is_root" def filter_is_root(self, queryset, name: str, value: bool): return queryset.filter(parent__isnull=value)
class UserFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~accounts.models.user.User` model. """ username = filters.LookupChoiceFilter( lookup_choices=DEFUALT_LOOKUP_CHOICES) first_name = filters.LookupChoiceFilter( lookup_choices=DEFUALT_LOOKUP_CHOICES) last_name = filters.LookupChoiceFilter( lookup_choices=DEFUALT_LOOKUP_CHOICES) email = filters.LookupChoiceFilter(lookup_choices=DEFUALT_LOOKUP_CHOICES) institute = filters.AllValuesMultipleFilter( field_name="profile__institute") study_ne = filters.NumberFilter(field_name="study", exclude=True) class Meta: model = User fields = ( "id", "username", "first_name", "last_name", "email", "institute", "study", "study_ne", )
class ExportDestinationFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~accounts.models.export_destination.ExportDestination` model. """ title = filters.LookupChoiceFilter(lookup_choices=DEFUALT_LOOKUP_CHOICES) description = filters.LookupChoiceFilter( lookup_choices=DEFUALT_LOOKUP_CHOICES ) ip = filters.LookupChoiceFilter(lookup_choices=DEFUALT_LOOKUP_CHOICES) username = filters.LookupChoiceFilter( lookup_choices=DEFUALT_LOOKUP_CHOICES ) destination = filters.LookupChoiceFilter( lookup_choices=DEFUALT_LOOKUP_CHOICES ) user_in = NumberInFilter( field_name="users__id", lookup_expr="in", label="User ID" ) class Meta: model = ExportDestination fields = ( "id", "title", "description", "ip", "username", "destination", "user_in", )
class AnalysisVersionFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_analyses.models.analysis_version.AnalysisVersion` model. """ title = filters.LookupChoiceFilter( lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ] ) description = filters.LookupChoiceFilter( lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ] ) created = filters.DateTimeFromToRangeFilter("created") class Meta: model = AnalysisVersion fields = "id", "analysis", "title", "description", "created"
class EventFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.event.Event` model. """ title = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) description = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) procedure = filters.ModelMultipleChoiceFilter( queryset=Procedure.objects.all(), label="Procedures:") exclude_procedure = filters.ModelMultipleChoiceFilter( queryset=Procedure.objects.all(), exclude=True, field_name="procedure", label="Exclude procedures:", ) study = filters.ModelMultipleChoiceFilter( queryset=Study.objects.all(), label="Studies:", field_name="procedure__study", ) class Meta: model = Event fields = ("id", )
class SubjectFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.subject.Subject` model. """ born_after_date = filters.DateFilter("date_of_birth", lookup_expr="gte") born_before_date = filters.DateFilter("date_of_birth", lookup_expr="lte") first_name = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) last_name = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) dicom_patient = filters.NumberFilter(method="filter_by_dicom_patient") class Meta: model = Subject fields = ( "id", "first_name", "last_name", "sex", "gender", "born_after_date", "born_before_date", "dominant_hand", "dicom_patient", ) def filter_by_dicom_patient(self, queryset, name, value): """ Find the subject that represents a particular DICOM :class:`~django_dicom.models.patient.Patient` instance. Parameters ---------- queryset : django.db.models.QuerySet The :class:`~research.models.subject.Subject` queryset to filter. name : str The name of the model field to filter on. value : int DICOM :class:`~django_dicom.models.patient.Patient` ID. """ if not value: return queryset dicom_patient = Patient.objects.get(id=value) mri_scans = Scan.objects.filter( dicom__in=dicom_patient.series_set.all()) subject_ids = set( mri_scans.order_by("subject").values_list("subject", flat=True)) return queryset.filter(id=subject_ids.pop())
class PatientFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_dicom.models.patient.Patient` class. """ born_after_date = filters.DateFilter("date_of_birth", lookup_expr="gte") born_before_date = filters.DateFilter("date_of_birth", lookup_expr="lte") name_prefix = filters.AllValuesFilter("name_prefix") sex = filters.ChoiceFilter("sex", choices=Sex.choices()) uid = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) given_name = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) middle_name = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) family_name = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) name_suffix = filters.AllValuesFilter("name_suffix") study__id = filters.NumberFilter(method="filter_by_study") class Meta: model = Patient fields = ( "id", "uid", "born_after_date", "born_before_date", "name_prefix", "given_name", "middle_name", "family_name", "name_suffix", ) def filter_by_study(self, queryset, name, value): if not value: return queryset series = Series.objects.filter(study__id=value) patient_ids = set(series.values_list("patient", flat=True)) return queryset.filter(id__in=patient_ids)
class SessionFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_dicom.models.session.Session` class. """ comments = filters.LookupChoiceFilter( "comments", lookup_choices=LOOKUP_CHOICES, ) session_date = filters.DateTimeFromToRangeFilter("time__date") id_in = NumberInFilter(field_name="id", lookup_expr="in", label="Session ID is in") study_id_in = NumberInFilter( lookup_expr="in", label="Associated Study ID is in", method="filter_by_study_association", ) subject_id_in = NumberInFilter(field_name="subject__id", lookup_expr="in", label="Subject ID is in") scan_set = NumberInFilter(field_name="scan_set", method="in", label="Contains scan IDs") subject_id_number = filters.LookupChoiceFilter( "subject__id_number", lookup_choices=LOOKUP_CHOICES, ) subject_first_name = filters.LookupChoiceFilter( "subject__first_name", lookup_choices=LOOKUP_CHOICES, ) subject_last_name = filters.LookupChoiceFilter( "subject__last_name", lookup_choices=LOOKUP_CHOICES, ) class Meta: model = Session fields = ( "id", "subject", "comments", "time", "scan_set", "session_date", ) def filter_by_study_association(self, queryset: QuerySet, name: str, value: List[str]): query = Q(scan__study_groups__study__id__in=value) | Q( measurement__procedure__study__id__in=value) return queryset.filter(query).distinct()
class DataAcquisitionFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.subject.Subject` model. """ app_label = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) model = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) class Meta: model = ContentType fields = ("id", "app_label", "model")
class KeyWordListFilter(django_filters.FilterSet): rvn_stelle_key_word_keyword__text__autor = django_filters.ModelMultipleChoiceFilter( queryset=Autor.objects.all(), label="Autor", help_text="Stichworte wurde von diesen Autoren verwendet", widget=autocomplete.Select2Multiple( url="archiv-ac:autor-autocomplete", )) legacy_id = django_filters.CharFilter( lookup_expr='icontains', help_text=KeyWord._meta.get_field('legacy_id').help_text, label=KeyWord._meta.get_field('legacy_id').verbose_name) stichwort = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=KeyWord._meta.get_field('stichwort').help_text, label=KeyWord._meta.get_field('stichwort').verbose_name) wurzel = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=KeyWord._meta.get_field('wurzel').help_text, label=KeyWord._meta.get_field('wurzel').verbose_name) kommentar = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=KeyWord._meta.get_field('kommentar').help_text, label=KeyWord._meta.get_field('kommentar').verbose_name) varianten = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=KeyWord._meta.get_field('varianten').help_text, label=KeyWord._meta.get_field('varianten').verbose_name) rvn_stelle_key_word_keyword = django_filters.ModelMultipleChoiceFilter( queryset=Stelle.objects.all(), label="Stelle", help_text="Stichworte stehen mit diesen Stellen in Verbindung", widget=autocomplete.Select2Multiple( url="archiv-ac:stelle-autocomplete", )) rvn_stelle_key_word_keyword__text = django_filters.ModelMultipleChoiceFilter( queryset=Text.objects.all(), label="Text", help_text="Stichworte stehen mit diesen Texten in Verbindung", widget=autocomplete.Select2Multiple( url="archiv-ac:text-autocomplete", )) rvn_stelle_key_word_keyword__text__autor__ort = django_filters.ModelMultipleChoiceFilter( queryset=Ort.objects.all(), label="Ort", help_text="Stichworte stehen mit diesen Orten in Verbindung", widget=autocomplete.Select2Multiple( url="archiv-ac:ort-autocomplete", )) class Meta: model = KeyWord fields = [ 'rvn_stelle_key_word_keyword__text__autor', 'id', 'legacy_id', 'legacy_pk', 'stichwort', 'art', 'wurzel', 'kommentar', 'varianten' ]
class EventFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.event.Event` model. """ title = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) description = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) class Meta: model = Event fields = "id", "title", "description"
class GroupFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.subject.Subject` model. """ title = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) description = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) study = filters.ModelMultipleChoiceFilter(queryset=Study.objects.all(), label="Studies:") class Meta: model = Group fields = ("id", "title", "description")
class ProcedureFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.procedure.Procedure` model. """ title = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) description = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) exclude_study = filters.ModelMultipleChoiceFilter( field_name="study", exclude=True, queryset=Study.objects.all()) class Meta: model = Procedure fields = "id", "title", "description", "study", "exclude_study"
class TaskResultFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~accounts.models.export_destination.ExportDestination` model. """ task_id = filters.LookupChoiceFilter(lookup_choices=DEFUALT_LOOKUP_CHOICES) task_name = filters.LookupChoiceFilter( lookup_choices=DEFUALT_LOOKUP_CHOICES) worker = filters.LookupChoiceFilter(lookup_choices=DEFUALT_LOOKUP_CHOICES) status = filters.MultipleChoiceFilter(choices=STATUS_CHOICES) parent = EmptyCharFilter(lookup_expr="exact", label="Parent task ID:") class Meta: model = TaskResult fields = ("id", "parent")
class SessionFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_dicom.models.session.Session` class. """ comments = filters.LookupChoiceFilter( "comments", lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ], ) session_date = filters.DateTimeFromToRangeFilter("time__date") subject_id_in = NumberInFilter(field_name="subject__id", lookup_expr="in") scan_set = NumberInFilter(field_name="scan_set", method="in") id_in = NumberInFilter(field_name="id", lookup_expr="in") class Meta: model = Session fields = ( "id", "subject", "comments", "time", "scan_set", "session_date", )
class StudyFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_dicom.models.study.Study` class. """ description = filters.LookupChoiceFilter( lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ] ) created_after_date = filters.DateFilter("date", lookup_expr="gte") created_before_date = filters.DateFilter("date", lookup_expr="lte") created_after_time = filters.DateFilter("time", lookup_expr="gte") created_before_time = filters.DateFilter("time", lookup_expr="lte") class Meta: model = Study fields = ( "id", "uid", "description", "created_after_date", "created_before_date", "created_after_time", "created_before_time", )
class ScanFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_dicom.models.scan.Scan` class. """ description = filters.LookupChoiceFilter( "description", lookup_choices=LOOKUP_CHOICES, ) number = filters.NumberFilter("number") scan_time = filters.DateTimeFromToRangeFilter("time") created = filters.DateTimeFromToRangeFilter("created") institution_name = filters.AllValuesFilter("institution_name") dicom_id_in = NumberInFilter(field_name="dicom__id", lookup_expr="in") sequence_type = filters.MultipleChoiceFilter( field_name="dicom__sequence_type", # Exclude the null value choices because it doesn't seem to integrate # well with DRF. choices=SEQUENCE_TYPE_CHOICES[:-1], # Create DRF compatible null filter. null_value=None, null_label="Unknown", ) subject_id_number = filters.LookupChoiceFilter( "session__subject__id_number", lookup_choices=LOOKUP_CHOICES, ) subject_first_name = filters.LookupChoiceFilter( "session__subject__first_name", lookup_choices=LOOKUP_CHOICES, ) subject_last_name = filters.LookupChoiceFilter( "session__subject__last_name", lookup_choices=LOOKUP_CHOICES, ) study_groups = filters.ModelMultipleChoiceFilter( queryset=Group.objects.all() ) class Meta: model = Scan fields = ( "id", "echo_time", "inversion_time", "repetition_time", "is_updated_from_dicom", "dicom__id", "session", )
class ProcedureStepFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.procedure_step.ProcedureStep` model. """ title = filters.LookupChoiceFilter(field_name="event__title", lookup_choices=LOOKUP_CHOICES) description = filters.LookupChoiceFilter(field_name="event__description", lookup_choices=LOOKUP_CHOICES) exclude_procedure = filters.ModelMultipleChoiceFilter( field_name="procedure", exclude=True, queryset=Procedure.objects.all()) event_type = filters.ChoiceFilter( choices=( ("measurementdefinition", "Measurement Definition"), ("task", "Task"), ), method="check_event_type", label="Event type:", ) content_type = filters.ChoiceFilter( choices=(("django_mri.Session", "MRI Session"), ), method="check_content_type", label="Measurement content type:", ) class Meta: model = ProcedureStep fields = ( "id", "index", "procedure", ) def check_event_type(self, queryset: QuerySet, name: str, value: str, *args, **kwargs) -> QuerySet: key = EVENT_TYPE_QUERY_KEY.format(event_type=value) return queryset.filter(**{key: False}) def check_content_type(self, queryset: QuerySet, name: str, value: str, *args, **kwargs) -> QuerySet: query = Q() values = value.lower().split(".") for part, value in zip(CONTENT_TYPE_PARTS, values): key = CONTENT_TYPE_QUERY_KEY.format(part=part) query |= Q(**{key: value}) return queryset.filter(query)
class FlightFilter(filters.FilterSet): destination = filters.CharFilter(lookup_expr='icontains') departure = filters.CharFilter(lookup_expr='icontains') departureDate = filters.LookupChoiceFilter(field_name='departure_date', lookup_choices=[('exact', 'On'), ('gte', 'After'), ('lte', 'Before')]) class Meta: model = Flight fields = ('destination', 'departure', 'departureDate', 'status',)
class StelleListFilter(django_filters.FilterSet): legacy_id = django_filters.CharFilter( lookup_expr='icontains', help_text=Stelle._meta.get_field('legacy_id').help_text, label=Stelle._meta.get_field('legacy_id').verbose_name) text = django_filters.ModelMultipleChoiceFilter( queryset=Text.objects.all(), help_text=Stelle._meta.get_field('text').help_text, label=Stelle._meta.get_field('text').verbose_name, widget=autocomplete.Select2Multiple( url="archiv-ac:text-autocomplete", )) summary = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=Stelle._meta.get_field('summary').help_text, label=Stelle._meta.get_field('summary').verbose_name) zitat = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=Stelle._meta.get_field('zitat').help_text, label=Stelle._meta.get_field('zitat').verbose_name) translation = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=Stelle._meta.get_field('translation').help_text, label=Stelle._meta.get_field('translation').verbose_name) key_word = django_filters.ModelMultipleChoiceFilter( queryset=KeyWord.objects.all(), help_text=Stelle._meta.get_field('key_word').help_text, label=Stelle._meta.get_field('key_word').verbose_name, widget=autocomplete.Select2Multiple( url="archiv-ac:keyword-autocomplete", )) use_case = django_filters.ModelMultipleChoiceFilter( queryset=UseCase.objects.all(), help_text="Related UseCase", label="UseCase", widget=autocomplete.Select2Multiple( url="archiv-ac:usecase-autocomplete", )) kommentar = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=Stelle._meta.get_field('kommentar').help_text, label=Stelle._meta.get_field('kommentar').verbose_name) class Meta: model = Stelle fields = [ 'id', 'legacy_id', 'legacy_pk', 'text', 'summary', 'zitat', 'translation', 'key_word', 'kommentar', 'use_case' ]
class TicketFilter(filters.FilterSet): passenger = filters.CharFilter(lookup_expr='icontains') bookedBy = filters.LookupChoiceFilter(field_name='booked_by__email', lookup_choices=[('iexact', 'Exactly matches'), ('icontains', 'Contains')]) flightNumber = filters.CharFilter(field_name='seat__flight', lookup_expr='number__icontains') flightDate = filters.CharFilter(field_name='seat__flight', lookup_expr='departure_date') class Meta: model = Ticket fields = ('passenger', 'bookedBy', 'flightNumber', 'flightDate')
class StudyFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.study.Study` model. """ title = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) description = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) n_subjects = filters.RangeFilter( label="Number of associated subjects between:") collaborators = filters.ModelMultipleChoiceFilter( queryset=User.objects.all()) procedures = filters.ModelMultipleChoiceFilter( queryset=Procedure.objects.all()) if ENABLE_COUNT_FILTERING: n_subjects = filters.RangeField( label="Number of associated subjects between:") class Meta: model = Study fields = ("id", )
class UseCaseListFilter(django_filters.FilterSet): title = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=UseCase._meta.get_field('title').help_text, label=UseCase._meta.get_field('title').verbose_name, ) principal_investigator = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=UseCase._meta.get_field('principal_investigator').help_text, label=UseCase._meta.get_field('principal_investigator').verbose_name) pi_norm_id = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=UseCase._meta.get_field('pi_norm_id').help_text, label=UseCase._meta.get_field('pi_norm_id').verbose_name) description = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=UseCase._meta.get_field('description').help_text, label=UseCase._meta.get_field('description').verbose_name) has_stelle__text = django_filters.ModelMultipleChoiceFilter( queryset=Text.objects.all(), help_text="Related Text", label="Text", widget=autocomplete.Select2Multiple( url="archiv-ac:text-autocomplete", )) has_stelle__text__autor = django_filters.ModelMultipleChoiceFilter( queryset=Autor.objects.all(), help_text="Related Authors", label="Author", widget=autocomplete.Select2Multiple( url="archiv-ac:autor-autocomplete", )) has_stelle__key_word = django_filters.ModelMultipleChoiceFilter( queryset=KeyWord.objects.all(), help_text="Related Keywords", label="Keywords", widget=autocomplete.Select2Multiple( url="archiv-ac:keyword-autocomplete", )) class Meta: model = UseCase fields = '__all__'
class PatientFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_dicom.models.patient.Patient` class. """ born_after_date = filters.DateFilter("date_of_birth", lookup_expr="gte") born_before_date = filters.DateFilter("date_of_birth", lookup_expr="lte") name_prefix = filters.AllValuesFilter("name_prefix") given_name = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) middle_name = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) family_name = filters.LookupChoiceFilter(lookup_choices=[ ("contains", "Contains (case-sensitive)"), ("icontains", "Contains (case-insensitive)"), ("exact", "Exact"), ]) name_suffix = filters.AllValuesFilter("name_suffix") class Meta: model = Patient fields = ( "id", "uid", "born_after_date", "born_before_date", "name_prefix", "given_name", "middle_name", "family_name", "name_suffix", )
class AnalysisFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_analyses.models.analysis.Analysis` model. """ title = filters.LookupChoiceFilter(lookup_choices=DEFAULT_LOOKUP_CHOICES) description = filters.LookupChoiceFilter( lookup_choices=DEFAULT_LOOKUP_CHOICES) created = filters.DateTimeFromToRangeFilter() has_runs = filters.BooleanFilter( field_name="version_set__run__isnull", method="filter_has_runs", label="Has existing runs:", ) class Meta: model = Analysis fields = "id", "category" def filter_has_runs(self, queryset, name, value): return queryset.filter(**{name: not value}).distinct()
class MeasurementDefinitionFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.event.Event` model. """ title = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) description = filters.LookupChoiceFilter(lookup_choices=LOOKUP_CHOICES) model_name = filters.CharFilter( field_name="content_type__model", lookup_expr="exact", label="Model name (exact)", ) app_label = filters.CharFilter( field_name="content_type__app_label", lookup_expr="exact", label="App label (exact)", ) class Meta: model = MeasurementDefinition fields = "id", "title", "description", "content_type"
class EventListFilter(django_filters.FilterSet): title = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=Event._meta.get_field('title').help_text, label=Event._meta.get_field('title').verbose_name) description = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=Event._meta.get_field('description').help_text, label=Event._meta.get_field('description').verbose_name) start_date = django_filters.LookupChoiceFilter( lookup_choices=DATE_LOOKUP_CHOICES, help_text=Event._meta.get_field('start_date').help_text, label=Event._meta.get_field('start_date').verbose_name) end_date = django_filters.LookupChoiceFilter( lookup_choices=DATE_LOOKUP_CHOICES, help_text=Event._meta.get_field('end_date').help_text, label=Event._meta.get_field('end_date').verbose_name) class Meta: model = Event fields = [ 'title', ]
class ProcedureStepFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~research.models.procedure_step.ProcedureStep` model. """ title = filters.LookupChoiceFilter(field_name="event__title", lookup_choices=LOOKUP_CHOICES) description = filters.LookupChoiceFilter(field_name="event__description", lookup_choices=LOOKUP_CHOICES) exclude_procedure = filters.ModelMultipleChoiceFilter( field_name="procedure", exclude=True, queryset=Procedure.objects.all()) class Meta: model = ProcedureStep fields = ( "id", "index", "procedure", "exclude_procedure", "title", "description", )
class AnalysisVersionFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_analyses.models.analysis_version.AnalysisVersion` model. """ analysis = filters.ModelMultipleChoiceFilter( queryset=Analysis.objects.all()) title = filters.LookupChoiceFilter(lookup_choices=DEFAULT_LOOKUP_CHOICES) description = filters.LookupChoiceFilter( lookup_choices=DEFAULT_LOOKUP_CHOICES) created = filters.DateTimeFromToRangeFilter("created") has_runs = filters.BooleanFilter( field_name="run__isnull", method="filter_has_runs", label="Has existing runs:", ) class Meta: model = AnalysisVersion fields = "id", "analysis", "title", "description", "created" def filter_has_runs(self, queryset, name, value): return queryset.filter(**{name: not value}).distinct()
class IrbApprovalFilter(filters.FilterSet): """ Provides useful filtering options for the :class:`~django_dicom.models.irb_approval.IrbApproval` class. """ institution = filters.LookupChoiceFilter( "institution", lookup_choices=LOOKUP_CHOICES, ) number = filters.LookupChoiceFilter( "number", lookup_choices=LOOKUP_CHOICES, ) class Meta: model = IrbApproval fields = ( "id", "institution", "number", )