def build_field_schema(cls): field_schema = [] for fieldname in cls._get_fieldnames_to_serialize(): if fieldname in ["id", "patient_id", "episode_id"]: continue elif fieldname.endswith("_fk_id"): continue elif fieldname.endswith("_ft"): continue getter = getattr(cls, "get_field_type_for_" + fieldname, None) if getter is None: field = cls._get_field_type(fieldname) if field in [models.CharField, ForeignKeyOrFreeText]: field_type = "string" else: field_type = camelcase_to_underscore(field.__name__[:-5]) else: field_type = getter() lookup_list = None if cls._get_field_type(fieldname) == ForeignKeyOrFreeText: fld = getattr(cls, fieldname) lookup_list = camelcase_to_underscore(fld.foreign_model.__name__) title = fieldname.replace("_", " ").title() field_schema.append({"name": fieldname, "title": title, "type": field_type, "lookup_list": lookup_list}) return field_schema
def build_field_schema(cls): field_schema = [] for fieldname in cls._get_fieldnames_to_serialize(): if fieldname in ['id', 'patient_id', 'episode_id']: continue elif fieldname.endswith('_fk_id'): continue elif fieldname.endswith('_ft'): continue getter = getattr(cls, 'get_field_type_for_' + fieldname, None) if getter is None: field = cls._get_field_type(fieldname) if field in [models.CharField, ForeignKeyOrFreeText]: field_type = 'string' else: field_type = camelcase_to_underscore(field.__name__[:-5]) else: field_type = getter() lookup_list = None if cls._get_field_type(fieldname) == ForeignKeyOrFreeText: fld = getattr(cls, fieldname) lookup_list = camelcase_to_underscore(fld.foreign_model.__name__) title = fieldname.replace('_', ' ').title() field_schema.append({'name': fieldname, 'title': title, 'type': field_type, 'lookup_list': lookup_list}) return field_schema
def build_field_schema(cls): field_schema = [] for fieldname in cls._get_fieldnames_to_serialize(): if fieldname in ['id', 'patient_id', 'episode_id']: continue elif fieldname.endswith('_fk_id'): continue elif fieldname.endswith('_ft'): continue getter = getattr(cls, 'get_field_type_for_' + fieldname, None) if getter is None: field = cls._get_field_type(fieldname) if field in [models.CharField, ForeignKeyOrFreeText]: field_type = 'string' else: field_type = camelcase_to_underscore(field.__name__[:-5]) else: field_type = getter() lookup_list = None if cls._get_field_type(fieldname) == ForeignKeyOrFreeText: fld = getattr(cls, fieldname) lookup_list = camelcase_to_underscore( fld.foreign_model.__name__) title = fieldname.replace('_', ' ').title() field_schema.append({ 'name': fieldname, 'title': title, 'type': field_type, 'lookup_list': lookup_list }) return field_schema
def get_api_name(self): if self.model: return self.model.get_api_name() else: return camelcase_to_underscore( self.get_display_name().replace(" ", "") )
def record_panel(model, editable=1, only_display_if_exists=False, title=None, name=None, detail_template=None, angular_filter=None): """ Register a panel for our record. Editable is an angular expression to be evaluated """ if name is None: name = camelcase_to_underscore(model.__class__.__name__) if detail_template is None: detail_template = model.__class__.get_detail_template() if title is None: title = getattr(model, '_title', name.replace('_', ' ').title()) return { 'name': name, 'singleton': getattr(model, '_is_singleton', False), 'title': title, 'detail_template': detail_template, 'icon': getattr(model, '_icon', None), 'editable': editable, 'angular_filter': angular_filter, 'only_display_if_exists': only_display_if_exists, }
def get_column_context(self, **kwargs): """ Return the context for our columns """ # we use this view to load blank tables without content for # the list redirect view, so if there are no kwargs, just # return an empty context if not self.patient_list: return [] context = [] for column in self.patient_list.schema: column_context = {} name = camelcase_to_underscore(column.__name__) column_context['name'] = name column_context['title'] = getattr(column, '_title', name.replace('_', ' ').title()) column_context['single'] = column._is_singleton column_context['icon'] = getattr(column, '_icon', '') column_context['list_limit'] = getattr(column, '_list_limit', None) column_context['template_path'] = column.get_display_template( patient_list=self.patient_list()) column_context[ 'detail_template_path'] = column.get_detail_template( patient_list=self.patient_list()) context.append(column_context) return context
def get_slug(klass): if klass.slug is not None: return klass.slug if klass.display_name is None: raise ValueError('Must set display_name for {0}'.format(klass)) return camelcase_to_underscore(klass.display_name).replace(' ', '')
def dispatch(self, *a, **kw): """ Set the context for what this modal is for so it can be accessed by all subsequent methods """ self.column = get_subrecord_from_api_name(kw['model']) self.name = camelcase_to_underscore(self.column.__name__) return super(FormTemplateView, self).dispatch(*a, **kw)
def get_slug(klass): if klass.slug is not None: return klass.slug if klass.display_name is None: raise ValueError( 'Must set display_name or slug for {0}'.format(klass) ) return camelcase_to_underscore(klass.display_name).replace(' ', '')
def get_template_name(model): model_name = camelcase_to_underscore(model.__name__) template_name = 'iframe_templates/{0}.html'.format(model_name) try: template_name = get_template(template_name).template.name return dict(template=template_name) except TemplateDoesNotExist: return dict(template='iframe_templates/template-not-found.html', status=400)
def get_detail_template(cls, team=None, subteam=None): """ Return the active detail template for our record """ name = camelcase_to_underscore(cls.__name__) templates = ["records/{0}_detail.html".format(name), "records/{0}.html".format(name)] try: return select_template(templates).template.name except TemplateDoesNotExist: return None
def record_timeline(model, whenfield): name = camelcase_to_underscore(model.__class__.__name__) return { 'name': name, 'editable': True, 'title': getattr(model, '_title', name.replace('_', ' ').title()), 'detail_template': model.__class__.get_detail_template(), 'icon': getattr(model, '_icon', None), 'whenfield': whenfield, }
def dispatch(self, *a, **kw): """ Set the context for what this modal is for so it can be accessed by all subsequent methods """ self.column = kw['model'] self.tag = kw.get('tag', None) self.subtag = kw.get('sub', None) self.template_name = self.column.get_form_template(team=self.tag, subteam=self.subtag) self.name = camelcase_to_underscore(self.column.__name__) return super(ModalTemplateView, self).dispatch(*a, **kw)
def get_template_name(model): model_name = camelcase_to_underscore(model.__name__) template_name = 'iframe_templates/{0}.html'.format(model_name) try: template_name = get_template(template_name).template.name return dict(template=template_name) except TemplateDoesNotExist: return dict( template='iframe_templates/template-not-found.html', status=400 )
def record_timeline(model, whenfield): name = camelcase_to_underscore(model.__class__.__name__) return { 'name' : name, 'editable' : True, 'title' : model.__class__.get_display_name(), 'detail_template': model.__class__.get_detail_template(), 'icon' : getattr(model, '_icon', None), 'whenfield' : whenfield, }
def get_detail_template(cls, team=None, subteam=None): """ Return the active detail template for our record """ name = camelcase_to_underscore(cls.__name__) templates = [ 'records/{0}_detail.html'.format(name), 'records/{0}.html'.format(name) ] try: return select_template(templates).template.name except TemplateDoesNotExist: return None
def get_lookup_list_api_name(cls, field_name): lookup_list = None field_type = cls._get_field_type(field_name) if field_type == ForeignKeyOrFreeText: fld = getattr(cls, field_name) lookup_list = camelcase_to_underscore( fld.foreign_model.get_api_name() ) elif field_type == models.fields.related.ManyToManyField: related_model = getattr(cls, field_name).field.related_model if issubclass(related_model, lookuplists.LookupList): return related_model.get_api_name() return lookup_list
def dispatch(self, *a, **kw): """ Set the context for what this modal is for so it can be accessed by all subsequent methods """ self.column = kw['model'] self.list_slug = kw.get('list', None) self.template_name = self.get_template_from_model() if self.template_name is None: raise ValueError('No modal Template available for {0}'.format( self.column.__name__)) self.name = camelcase_to_underscore(self.column.__name__) return super(ModalTemplateView, self).dispatch(*a, **kw)
def get_form_template(cls, team=None, subteam=None): """ Return the active form template for our record """ name = camelcase_to_underscore(cls.__name__) templates = ["modals/{0}_modal.html".format(name)] if team: templates.insert(0, "modals/{0}/{1}_modal.html".format(team, name)) if subteam: templates.insert(0, "modals/{0}/{1}/{2}_modal.html".format(team, subteam, name)) try: return select_template(templates).template.name except TemplateDoesNotExist: return None
def get_display_template(cls, team=None, subteam=None): """ Return the active display template for our record """ name = camelcase_to_underscore(cls.__name__) list_display_templates = ["records/{0}.html".format(name)] if team: list_display_templates.insert(0, "records/{0}/{1}.html".format(team, name)) if subteam: list_display_templates.insert(0, "records/{0}/{1}/{2}.html".format(team, subteam, name)) try: return select_template(list_display_templates).template.name except TemplateDoesNotExist: return None
def get_form_template(cls, team=None, subteam=None): """ Return the active form template for our record """ name = camelcase_to_underscore(cls.__name__) templates = ['modals/{0}_modal.html'.format(name)] if team: templates.insert(0, 'modals/{0}/{1}_modal.html'.format(team, name)) if subteam: templates.insert( 0, 'modals/{0}/{1}/{2}_modal.html'.format(team, subteam, name)) try: return select_template(templates).template.name except TemplateDoesNotExist: return None
def get_display_template(cls, team=None, subteam=None): """ Return the active display template for our record """ name = camelcase_to_underscore(cls.__name__) list_display_templates = ['records/{0}.html'.format(name)] if team: list_display_templates.insert( 0, 'records/{0}/{1}.html'.format(team, name)) if subteam: list_display_templates.insert( 0, 'records/{0}/{1}/{2}.html'.format(team, subteam, name)) try: return select_template(list_display_templates).template.name except TemplateDoesNotExist: return None
def dispatch(self, *a, **kw): """ Set the context for what this modal is for so it can be accessed by all subsequent methods """ self.column = kw['model'] self.list_slug = kw.get('list', None) self.template_name = self.get_template_from_model() if self.template_name is None: raise ValueError( 'No modal Template available for {0}'.format( self.column.__name__ ) ) self.name = camelcase_to_underscore(self.column.__name__) return super(ModalTemplateView, self).dispatch(*a, **kw)
def _get_column_context(schema, **kwargs): context = [] for column in schema: column_context = {} name = camelcase_to_underscore(column.__name__) column_context['name'] = name column_context['title'] = getattr(column, '_title', name.replace('_', ' ').title()) column_context['single'] = column._is_singleton column_context['icon'] = getattr(column, '_icon', '') column_context['list_limit'] = getattr(column, '_list_limit', None) header_templates = [name + '_header.html'] if 'tag' in kwargs: header_templates.insert( 0, 'list_display/{0}/{1}_header.html'.format(kwargs['tag'], name)) if 'subtag' in kwargs: header_templates.insert( 0, 'list_display/{0}/{1}/{2}_header.html'.format( kwargs['tag'], kwargs['subtag'], name)) column_context['template_path'] = column.get_display_template( team=kwargs.get('tag', None), subteam=kwargs.get('subtag', None)) column_context['detail_template_path'] = select_template([ t.format(name) for t in '{0}_detail.html', '{0}.html', 'records/{0}.html' ]).template.name try: column_context['header_template_path'] = select_template( header_templates).template.name except TemplateDoesNotExist: column_context['header_template_path'] = '' context.append(column_context) return context
def _get_column_context(schema, **kwargs): context = [] for column in schema: column_context = {} name = camelcase_to_underscore(column.__name__) column_context['name'] = name column_context['title'] = getattr(column, '_title', name.replace('_', ' ').title()) column_context['single'] = column._is_singleton column_context['icon'] = getattr(column, '_icon', '') column_context['list_limit'] = getattr(column, '_list_limit', None) header_templates = [name + '_header.html'] if 'tag' in kwargs: header_templates.insert( 0, 'list_display/{0}/{1}_header.html'.format(kwargs['tag'], name)) if 'subtag' in kwargs: header_templates.insert( 0, 'list_display/{0}/{1}/{2}_header.html'.format(kwargs['tag'], kwargs['subtag'], name)) column_context['template_path'] = column.get_display_template( team=kwargs.get('tag', None), subteam=kwargs.get('subtag', None)) column_context['detail_template_path'] = select_template([ t.format(name) for t in '{0}_detail.html', '{0}.html', 'records/{0}.html' ]).template.name try: column_context['header_template_path'] = select_template(header_templates).template.name except TemplateDoesNotExist: column_context['header_template_path'] = '' context.append(column_context) return context
def build_schema_for_field_name(cls, field_name): getter = getattr(cls, 'get_field_type_for_' + field_name, None) if getter is None: field = cls._get_field_type(field_name) if field in [models.CharField, ForeignKeyOrFreeText]: field_type = 'string' else: field_type = camelcase_to_underscore(field.__name__[:-5]) else: field_type = getter() title = cls._get_field_title(field_name) default = cls._get_field_default(field_name) field = { 'name': field_name, 'title': title, 'type': field_type, 'lookup_list': cls.get_lookup_list_api_name(field_name), 'default': default, 'model': cls.__name__, 'description': cls.get_field_description(field_name), 'enum': cls.get_field_enum(field_name) } return field
router.register('patient', PatientViewSet) router.register('episode', EpisodeViewSet) router.register('record', RecordViewSet) router.register('extract-schema', ExtractSchemaViewSet) router.register('userprofile', UserProfileViewSet) router.register('tagging', TaggingViewSet) router.register('patientlist', PatientListViewSet) router.register('patientrecordaccess', PatientRecordAccessViewSet) router.register('options', OptionsViewSet) router.register('referencedata', ReferenceDataViewSet) router.register('metadata', MetadataViewSet) for subrecord in subrecords(): sub_name = camelcase_to_underscore(subrecord.__name__) class SubViewSet(SubrecordViewSet): base_name = sub_name model = subrecord router.register(sub_name, SubViewSet) for plugin in plugins.plugins(): for api in plugin.apis: router.register(*api) class APIAdmitEpisodeView(View): """ Admit an episode from upstream! """
def slug(klass): return camelcase_to_underscore(klass.name).replace(' ', '')
def verbose_name(self): if self._verbose_name: return self._verbose_name else: field = camelcase_to_underscore(self.name) return field.replace('_', ' ')
def get_api_name(cls): return camelcase_to_underscore(cls._meta.object_name)
patient = Patient.objects.get(pk=pk) return Response(patient.to_dict(request.user)) router.register('patient', PatientViewSet) router.register('episode', EpisodeViewSet) router.register('flow', FlowViewSet) router.register('record', RecordViewSet) router.register('list-schema', ListSchemaViewSet) router.register('extract-schema', ExtractSchemaViewSet) router.register('options', OptionsViewSet) router.register('userprofile', UserProfileViewSet) router.register('tagging', TaggingViewSet) for subrecord in subrecords(): sub_name = camelcase_to_underscore(subrecord.__name__) class SubViewSet(SubrecordViewSet): base_name = sub_name model = subrecord router.register(sub_name, SubViewSet) for plugin in plugins.plugins(): for api in plugin.apis: router.register(*api) class APIAdmitEpisodeView(View): """ Admit an episode from upstream! """
url(r"^templates/modals/add_episode.html/?$", views.AddEpisodeTemplateView.as_view()), url(r"^templates/modals/add_episode_without_teams.html/?$", views.AddEpisodeWithoutTeamsTemplateView.as_view()), url(r"^templates/modals/hospital_number.html/?$", views.HospitalNumberTemplateView.as_view()), url(r"^templates/modals/reopen_episode.html/?$", views.ReopenEpisodeTemplateView.as_view()), url(r"^templates/modals/discharge_episode.html/?$", views.DischargeEpisodeTemplateView.as_view()), url(r"^templates/modals/copy_to_category.html/?$", views.CopyToCategoryTemplateView.as_view()), url(r"^templates/modals/delete_item_confirmation.html/?$", views.DeleteItemConfirmationView.as_view()), # New Public facing API urls url(r"api/v0.1/episode/admit", csrf_exempt(api.APIAdmitEpisodeView.as_view())), url(r"api/v0.1/episode/refer", csrf_exempt(api.APIReferPatientView.as_view())), url(r"api/v0.1/", include(api.router.urls)), ) # Generated subrecord template views for subrecord_model in subrecords(): sub_url = camelcase_to_underscore(subrecord_model.__name__) urlpatterns += patterns( "", url(r"^templates/modals/%s.html/?$" % sub_url, views.ModalTemplateView.as_view(), {"model": subrecord_model}), url( r"^templates/modals/%s.html/(?P<tag>[a-z_\-]+)/?$" % sub_url, views.ModalTemplateView.as_view(), {"model": subrecord_model}, ), url( r"^templates/modals/%s.html/(?P<tag>[a-z_\-]+)/(?P<subtag>[a-z_\-]+)/?$" % sub_url, views.ModalTemplateView.as_view(), {"model": subrecord_model}, ), )
url(r'^templates/modals/copy_to_category.html/?$', views.CopyToCategoryTemplateView.as_view()), url(r'^templates/modals/delete_item_confirmation.html/?$', views.DeleteItemConfirmationView.as_view()), # New Public facing API urls url(r'api/v0.1/episode/admit', csrf_exempt(api.APIAdmitEpisodeView.as_view())), url(r'api/v0.1/episode/refer', csrf_exempt(api.APIReferPatientView.as_view())), url(r'api/v0.1/', include(api.router.urls)), ) # Generated subrecord template views for subrecord_model in subrecords(): sub_url = camelcase_to_underscore(subrecord_model.__name__) urlpatterns += patterns( '', url(r'^templates/modals/%s.html/?$' % sub_url, views.ModalTemplateView.as_view(), {'model': subrecord_model}), url(r'^templates/modals/%s.html/(?P<tag>[a-z_\-]+)/?$' % sub_url, views.ModalTemplateView.as_view(), {'model': subrecord_model}), url( r'^templates/modals/%s.html/(?P<tag>[a-z_\-]+)/(?P<subtag>[a-z_\-]+)/?$' % sub_url, views.ModalTemplateView.as_view(), {'model': subrecord_model}), ) urlpatterns += staticfiles_urlpatterns() from opal.core import plugins