示例#1
0
    def handle(self, *args, **options):
        if options['filename']:
            data = self._from_file(options['filename'])
        else:
            raise ValueError('no lookuplist_provided!')

        num = 0
        for model in LookupList.__subclasses__():
            name = model.__name__.lower()
            # print name, (name in data)
            # if name == 'drug':
            #     import pdb;pdb.set_trace()
            #     print data[name]
            if name in data:
                print 'Loading', name
                num += 1

                for item in data[name]:
                    self._install_item(model, item)
        print "\nLoaded", num, "lookup lists\n"
        print "\n\nNew items report:\n\n\n"
        print "{0} new items".format(self.items_created)
        print "{0} new synonyms".format(self.synonyms_created)
        print "\n\nEnd new items report."
        return
示例#2
0
    def list(self, request):

        data = {}
        subclasses = LookupList.__subclasses__()
        for model in subclasses:
            options = list(model.objects.all().values_list("name", flat=True))
            data[model.get_api_name()] = options

        model_to_ct = ContentType.objects.get_for_models(
            *subclasses
        )

        for model, ct in model_to_ct.iteritems():
            synonyms = Synonym.objects.filter(content_type=ct).values_list(
                "name", flat=True
            )
            data[model.get_api_name()].extend(synonyms)

        for name in data:
            data[name].sort()

        data.update(metadata.MicroTestDefaultsMetadata.to_dict())
        data.update(metadata.MacrosMetadata.to_dict())
        data.update(TaggedPatientListMetadata.to_dict(user=request.user))
        data.update(FirstListMetadata.to_dict(user=request.user))
        return Response(data)
示例#3
0
    def delete(self):
        for item in Synonym.objects.all():
            item.delete()

        for model in LookupList.__subclasses__():
            for item in model.objects.all():
                item.delete()
示例#4
0
 def delete(self):
     for model in LookupList.__subclasses__():
         try:
             for item in model.objects.all():
                 item.delete()
         except: 
             continue
     for item in Synonym.objects.all():
         item.delete()
示例#5
0
 def delete(self):
     for model in LookupList.__subclasses__():
         try:
             for item in model.objects.all():
                 item.delete()
         except:
             continue
     for item in Synonym.objects.all():
         item.delete()
示例#6
0
    def delete(self):
        write('Deleting Synonyms')

        for item in Synonym.objects.all():
            item.delete()

        write('Deleting Lookuplists')
        for model in LookupList.__subclasses__():
            for item in model.objects.all():
                item.delete()
示例#7
0
文件: api.py 项目: anukat2015/opal-1
    def list(self, request):


        data = {}
        subclasses = LookupList.__subclasses__()
        for model in subclasses:
            options = list(model.objects.all().values_list("name", flat=True))
            data[model.__name__.lower()] = options

        model_to_ct = ContentType.objects.get_for_models(
            *subclasses
        )

        for model, ct in model_to_ct.iteritems():
            synonyms = Synonym.objects.filter(content_type=ct).values_list(
                "name", flat=True
            )
            data[model.__name__.lower()].extend(synonyms)

        for name in data:
            data[name].sort()

        data['micro_test_defaults'] = micro_test_defaults

        tag_hierarchy = collections.defaultdict(list)
        tag_visible_in_list = []
        tag_display = {}

        if request.user.is_authenticated():
            teams = Team.for_user(request.user)
            for team in teams:
                if team.parent:
                    continue # Will be filled in at the appropriate point!
                tag_display[team.name] = team.title

                if team.visible_in_list:
                    tag_visible_in_list.append(team.name)

                subteams = [st for st in teams if st.parent == team]
                tag_hierarchy[team.name] = [st.name for st in subteams]
                for sub in subteams:
                    tag_display[sub.name] = sub.title

                    if sub.visible_in_list:
                        tag_visible_in_list.append(sub.name)

        data['tag_hierarchy'] = tag_hierarchy
        data['tag_display'] = tag_display
        data['tag_visible_in_list'] = tag_visible_in_list
        data['macros'] = Macro.to_dict()

        return Response(data)
示例#8
0
    def handle(self, *args, **options):
        data = collections.defaultdict(dict)

        for model in LookupList.__subclasses__():
            content_type = ContentType.objects.get_for_model(model)
            items = []
            for item in model.objects.all():
                synonyms = [s.name for s in
                            Synonym.objects.filter(content_type=content_type,
                                                   object_id=item.id)]
                items.append({'name': item.name, 'synonyms': synonyms})
            data[model.__name__.lower()] = items

        self._to_json(data)
        return
示例#9
0
文件: api.py 项目: wjt/opal
    def list(self, request):

        data = {}
        subclasses = LookupList.__subclasses__()
        for model in subclasses:
            options = list(model.objects.all().values_list("name", flat=True))
            data[model.__name__.lower()] = options

        model_to_ct = ContentType.objects.get_for_models(*subclasses)

        for model, ct in model_to_ct.iteritems():
            synonyms = Synonym.objects.filter(content_type=ct).values_list(
                "name", flat=True)
            data[model.__name__.lower()].extend(synonyms)

        for name in data:
            data[name].sort()

        data['micro_test_defaults'] = micro_test_defaults

        tag_hierarchy = collections.defaultdict(list)
        tag_visible_in_list = []
        tag_display = {}

        if request.user.is_authenticated():
            teams = Team.for_user(request.user)
            for team in teams:
                if team.parent:
                    continue  # Will be filled in at the appropriate point!
                tag_display[team.name] = team.title

                if team.visible_in_list:
                    tag_visible_in_list.append(team.name)

                subteams = [st for st in teams if st.parent == team]
                tag_hierarchy[team.name] = [st.name for st in subteams]
                for sub in subteams:
                    tag_display[sub.name] = sub.title

                    if sub.visible_in_list:
                        tag_visible_in_list.append(sub.name)

        data['tag_hierarchy'] = tag_hierarchy
        data['tag_display'] = tag_display
        data['tag_visible_in_list'] = tag_visible_in_list
        data['macros'] = Macro.to_dict()

        return Response(data)
示例#10
0
    def retrieve(self, request, pk=None):
        the_list = None
        for lookuplist in LookupList.__subclasses__():
            if lookuplist.get_api_name() == pk:
                the_list = lookuplist
                break
        if the_list:
            values = list(the_list.objects.all().values_list('name', flat=True))
            ct = ContentType.objects.get_for_model(the_list)
            synonyms = Synonym.objects.filter(content_type=ct).values_list(
                'name', flat=True
            )
            values += list(synonyms)
            return Response(values)

        return Response({'error': 'Item does not exist'}, status=status.HTTP_404_NOT_FOUND)
示例#11
0
文件: api.py 项目: prohealthbox/opal
    def list(self, request):
        data = {}
        subclasses = LookupList.__subclasses__()
        for model in subclasses:
            options = list(model.objects.all().values_list("name", flat=True))
            data[model.get_api_name()] = options

        model_to_ct = ContentType.objects.get_for_models(*subclasses)

        for model, ct in model_to_ct.items():
            synonyms = Synonym.objects.filter(content_type=ct).values_list(
                "name", flat=True)
            data[model.get_api_name()].extend(synonyms)

        for name in data:
            data[name].sort()
        return json_response(data)
示例#12
0
    def handle(self, *args, **options):
        data = collections.defaultdict(dict)

        for model in LookupList.__subclasses__():
            content_type = ContentType.objects.get_for_model(model)
            items = []
            for item in model.objects.all():
                synonyms = [
                    s.name
                    for s in Synonym.objects.filter(content_type=content_type,
                                                    object_id=item.id)
                ]
                items.append({'name': item.name, 'synonyms': synonyms})
            data[model.__name__.lower()] = items

        self._to_json(data)
        return
示例#13
0
文件: api.py 项目: mattstibbs/opal
    def list(self, request):
        data = {}
        subclasses = LookupList.__subclasses__()
        for model in subclasses:
            options = list(model.objects.all().values_list("name", flat=True))
            data[model.get_api_name()] = options

        model_to_ct = ContentType.objects.get_for_models(
            *subclasses
        )

        for model, ct in model_to_ct.items():
            synonyms = Synonym.objects.filter(content_type=ct).values_list(
                "name", flat=True
            )
            data[model.get_api_name()].extend(synonyms)

        for name in data:
            data[name].sort()
        return json_response(data)
示例#14
0
文件: api.py 项目: mattstibbs/opal
    def retrieve(self, request, pk=None):
        the_list = None
        for lookuplist in LookupList.__subclasses__():
            if lookuplist.get_api_name() == pk:
                the_list = lookuplist
                break
        if the_list:
            values = list(
                the_list.objects.all().values_list('name', flat=True)
            )
            ct = ContentType.objects.get_for_model(the_list)
            synonyms = Synonym.objects.filter(content_type=ct).values_list(
                'name', flat=True
            )
            values += list(synonyms)
            return json_response(values)

        return json_response(
            {'error': 'Item does not exist'},
            status_code=status.HTTP_404_NOT_FOUND
        )
示例#15
0
    def handle(self, *args, **options):
        if options.get('filename', None):
            data = self._from_file(options['filename'])
        else:
            raise ValueError('no lookuplist_provided!')

        num = 0
        for model in LookupList.__subclasses__():
            name = model.__name__.lower()
            if name in data:
                logging.info('Loading {0}'.format(name))
                num += 1

                for item in data[name]:
                    self._install_item(model, item)

        msg = "\nLoaded {0} lookup lists\n".format(num)
        msg += "\n\nNew items report:\n\n\n"
        msg += "{0} new items".format(self.items_created)
        msg += " {0} new synonyms".format(self.synonyms_created)
        msg += "\n\nEnd new items report."
        self.stdout.write(msg)
        return
示例#16
0
        if synonym_exists(object_class, name):
            raise ValidationError(
                "A synonym of that name already exists"
            )

        return self.cleaned_data["name"]


class OptionAdmin(admin.ModelAdmin):
    form = LookupListForm
    ordering = ['name']
    search_fields = ['name']
    inlines = [SynonymInline]


for model in LookupList.__subclasses__():
    admin.site.register(model, OptionAdmin)

admin.site.register(User, UserProfileAdmin)
admin.site.register(models.Patient, PatientAdmin)
admin.site.register(models.Episode, EpisodeAdmin)
admin.site.register(models.Tagging, TaggingAdmin)


for subclass in patient_subrecords():
    if not subclass._meta.abstract and not getattr(subclass, "_no_admin", False):
        admin.site.register(subclass, PatientSubRecordAdmin)

for subclass in episode_subrecords():
    if not subclass._meta.abstract and not getattr(subclass, "_no_admin", False):
        admin.site.register(subclass, EpisodeSubRecordAdmin)
示例#17
0
文件: admin.py 项目: mattstibbs/opal
        if synonym_exists(object_class, name):
            raise ValidationError(
                "A synonym of that name already exists"
            )

        return self.cleaned_data["name"]


class OptionAdmin(admin.ModelAdmin):
    form = LookupListForm
    ordering = ['name']
    search_fields = ['name']
    inlines = [SynonymInline]


for model in LookupList.__subclasses__():
    admin.site.register(model, OptionAdmin)

admin.site.register(User, UserProfileAdmin)
admin.site.register(models.Patient, PatientAdmin)
admin.site.register(models.Episode, EpisodeAdmin)
admin.site.register(models.Tagging, TaggingAdmin)


for subclass in patient_subrecords():
    if not subclass._meta.abstract and not getattr(
            subclass, "_no_admin", False):
        admin.site.register(subclass, PatientSubrecordAdmin)

for subclass in episode_subrecords():
    if not subclass._meta.abstract and not getattr(