<commit_before>"""
This module defines the base PatientList classes.
"""
from opal.models import Episode, UserProfile
from opal.core import discoverable


class PatientList(discoverable.DiscoverableFeature):
    """
    A view of a list shown on the list page, complete with schema that
    define the columns shown and a queryset that defines the episodes shown
    """
    module_name = 'patient_lists'
    template_name = 'episode_list.html'
    order       = None

    @classmethod
    def list(klass):
        """
        Return an iterable of Patient Lists.
        """
        klasses = sorted(super(PatientList, klass).list(), key=lambda x: x.order)
        klasses.remove(TaggedPatientList)
        return klasses

    @classmethod
    def for_user(klass, user):
        """
        Return the set of instances that this USER can see.
        """
        for k in klass.list():
            if k.visible_to(user):
                yield k

    @classmethod
    def visible_to(klass, user):
        profile, _ = UserProfile.objects.get_or_create(user=user)
        if profile.restricted_only:
            return False

        return True

    @property
    def schema(self):
        raise ValueError("this needs to be implemented")

    @property<commit_msg>Convert PatientList to use RestrictableFeature<commit_after>"""
This module defines the base PatientList classes.
"""
from opal.models import Episode, UserProfile
from opal.core import discoverable


class PatientList(discoverable.DiscoverableFeature,
                  discoverable.RestrictableFeature):
    """
    A view of a list shown on the list page, complete with schema that
    define the columns shown and a queryset that defines the episodes shown
    """
    module_name = 'patient_lists'
    template_name = 'episode_list.html'
    order       = None

    @classmethod
    def list(klass):
        """
        Return an iterable of Patient Lists.
        """
        klasses = sorted(super(PatientList, klass).list(), key=lambda x: x.order)
        klasses.remove(TaggedPatientList)
        return klasses

    @classmethod
    def visible_to(klass, user):
        profile, _ = UserProfile.objects.get_or_create(user=user)
        if profile.restricted_only:
            return False

        return True

    @property
    def schema(self):
        raise ValueError("this needs to be implemented")

    @property
{'fraction_non_alphanumeric': 0.07775919732441472, 'fraction_numerical': 0.0, 'mean_word_length': 2.576980568011958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4008578', 'n_tokens_mistral': 663, 'n_tokens_neox': 641, 'n_words': 208}