Skip to content

Commit

Permalink
Merge a86f56d into 0093178
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmiller committed Oct 3, 2018
2 parents 0093178 + a86f56d commit a9b8cfe
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 293 deletions.
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
### 0.13.0 (Major Release)

#### Removes CopyToCategory

Removes the entire CopyToCategory flow from Opal Core. If applications continue to rely on it,
they are advised to implement at application level.

In general application developers are advised to find alternative ways to display subrecords
from multiple episodes rather than copying them however, as this is known to cause duplication
of data that is hard to trace back later on.

This includes the API endpoint at `episode/$id/actions/copyto/$category/`, the template
`copy_to_category.html`, the Angular controller `CopyToCategoryCtrl` and service
`CopyToCategory` and Subrecord property `_clonable`.

#### Removes the deprecated Model._title property

Use of `Model._title` to set a display name of a subrecord has issued a warning for several
Expand Down
12 changes: 1 addition & 11 deletions doc/docs/reference/subrecords.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ Name of the field by which we want to sort these records when displaying.
_sort = 'start_date'
```

#### Subrecord._clonable

A Boolean that is True by default used by `opal.views.EpisodeCopyToCategoryView`
to determine if instances of this record should be copied across.

```python
class Antimicrobial(EpisodeSubrecord):
_clonable = 'False'
```

#### Subrecord._exclude_from_extract

Boolean to specify that this subrecord should be excluded from any standard data extract.
Expand Down Expand Up @@ -104,7 +94,7 @@ Classmethod that returns the display name of the subrecord.
This is used as the user visible title of subrecord panels and modals amongst other places.

By default this uses the Django
[Meta verbose_name](https://docs.djangoproject.com/en/dev/ref/models/options/#verbose-name)
[Meta verbose_name](https://docs.djangoproject.com/en/dev/ref/models/options/#verbose-name)
property

```python
Expand Down
1 change: 0 additions & 1 deletion opal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,6 @@ class Meta:


class EpisodeSubrecord(Subrecord):
_clonable = True

episode = models.ForeignKey(Episode, null=False)

Expand Down
45 changes: 0 additions & 45 deletions opal/static/js/opal/controllers/copy_to_category.js

This file was deleted.

30 changes: 0 additions & 30 deletions opal/static/js/opal/services/copy_to_category.js

This file was deleted.

95 changes: 0 additions & 95 deletions opal/static/js/test/copy.to.category.controller.test.js

This file was deleted.

40 changes: 0 additions & 40 deletions opal/templates/copy_to_category.html

This file was deleted.

1 change: 0 additions & 1 deletion opal/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class Meta:


class Colour(models.EpisodeSubrecord):
_clonable = False
_advanced_searchable = False
_exclude_from_extract = True
_angular_service = 'Colour'
Expand Down
30 changes: 0 additions & 30 deletions opal/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,36 +414,6 @@ def test_get_non_existing_template(self):
self.assertEqual(404, resp.status_code)


class CopyToCategoryViewTestCase(BaseViewTestCase):
def test_copy_to_category(self):
""" copy all subrecords that don't have _clonable=True and
are not singletons
"""
request = MagicMock()
request.user = self.user;
view = self.setup_view(views.EpisodeCopyToCategoryView, request)
testmodels.Colour.objects.create(
episode=self.episode, name="purple"
)
testmodels.HatWearer.objects.create(
episode=self.episode, name="hat wearer"
)
testmodels.EpisodeName.objects.create(
episode=self.episode, name="episode name"
)
view.post(request, pk=self.episode.pk, category="Outpatient")

new_episode = models.Episode.objects.exclude(id=self.episode.id).get()
self.assertEqual(new_episode.hatwearer_set.get().name, "hat wearer")
self.assertEqual(new_episode.colour_set.count(), 0)
self.assertEqual(new_episode.category_name, "Outpatient")

# a singleton will be created but not populate it
self.assertEqual(
new_episode.episodename_set.filter(name="episode name").count(), 0
)


class CSRFFailureTestCase(TestCase):
def test_get(self):
factory = RequestFactory()
Expand Down
6 changes: 0 additions & 6 deletions opal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@

url(r'^admin/', include(admin.site.urls)),

url(r'^episode/(?P<pk>\d+)/actions/copyto/(?P<category>[a-zA-Z_\-]+)/?$',
views.EpisodeCopyToCategoryView.as_view()),

# Template views
url(r'^templates/patient_list.html/(?P<slug>[0-9a-z_\-]+)/?$',
views.PatientListTemplateView.as_view(),
Expand All @@ -63,9 +60,6 @@
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()),

Expand Down
36 changes: 2 additions & 34 deletions opal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
from django.shortcuts import get_object_or_404, redirect
from django.template.loader import get_template
from django.template import TemplateDoesNotExist
from django.views.generic import TemplateView, View
from django.views.generic import TemplateView

from opal import models
from opal.core import application, detail, episodes
from opal.core.patient_lists import PatientList, TabbedPatientListGroup
from opal.core.subrecords import (
episode_subrecords, get_subrecord_from_api_name
)
from opal.core.views import json_response
from opal.core.subrecords import get_subrecord_from_api_name
from opal.utils import camelcase_to_underscore
from opal.utils.banned_passwords import banned

Expand Down Expand Up @@ -144,31 +141,6 @@ def check_password_reset(request, *args, **kwargs):
return response


"""Internal (Legacy) API View"""


class EpisodeCopyToCategoryView(LoginRequiredMixin, View):
"""
Copy an episode to a given category, excluding tagging.
"""
def post(self, request, pk=None, category=None, **kwargs):
old = models.Episode.objects.get(pk=pk)
new = models.Episode(patient=old.patient,
category_name=category,
start=old.start)
new.save()

for sub in episode_subrecords():
if sub._is_singleton or not sub._clonable:
continue
for item in sub.objects.filter(episode=old):
item.id = None
item.episode = new
item.save()
serialised = new.to_dict(self.request.user)
return json_response(serialised)


"""
Template views for Opal
"""
Expand Down Expand Up @@ -272,10 +244,6 @@ class DischargeEpisodeTemplateView(LoginRequiredMixin, TemplateView):
template_name = 'discharge_episode_modal.html'


class CopyToCategoryTemplateView(LoginRequiredMixin, TemplateView):
template_name = 'copy_to_category.html'


class DeleteItemConfirmationView(LoginRequiredMixin, TemplateView):
template_name = 'delete_item_confirmation_modal.html'

Expand Down

0 comments on commit a9b8cfe

Please sign in to comment.