Skip to content

Commit

Permalink
Merge branch 'v0.11.0' into as_menuitem
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmiller committed Apr 13, 2018
2 parents 16100be + 6a992a6 commit 8b9279d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 88 deletions.
39 changes: 20 additions & 19 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,25 @@ Pathways.
To aid this, the `.as_menuitem()` method now creates one from the target class with
sensible but overridable defaults.

#### Removes "episode_history" from episode serialization

Serialised episodes previously contained a "shallow" copy of all other episodes in
a property named `episode_history`. This was primarially useful before we switched
from episode-oriented to patient-oriented detail views by default.

This also includes a change to the signature of the `.serialised()` method of the
Episode manager, which no longer accepts a `episode_history` kwarg.

#### Misc Changes

Adds the utility function `opal.utils.get`. Similar to the `getattr` builtin, `get` looks
for a method named `get_$attr` and will call that if it exists.

Adds the method `.get_absolute_url()` to `opal.core.pathways.Pathway` and
`opal.core.patient_lists.PatientList`.

Adds the Opal error `SignatureError`.

### 0.10.1 (Minor Release)

#### Plugin API end points can now override application end points
Expand Down Expand Up @@ -36,6 +55,7 @@ with moderately heavy `ForeignKeyOrFreeText` usage.

(Approx 30-40% in our tests.)


### 0.10.0 (Major Release)

This is a major release with breaking changes from upstream dependencies.
Expand Down Expand Up @@ -161,25 +181,6 @@ Adds the `rows` option to the textarea template tag which just fills in the html

Configures the setting `CSRF_FAILURE_VIEW` to use the bundled `opal.views.csrf_failure` view.

Adds the utility function `opal.utils.get`. Similar to the `getattr` builtin, `get` looks
for a method named `get_$attr` and will call that if it exists.
<<<<<<< HEAD

Adds the method `.get_absolute_url()` to `opal.core.pathways.Pathway` and
`opal.core.patient_lists.PatientList`.

Adds the Opal error `SignatureError`.

Pathway slugs may now include hyphens as well as numbers, lower case letters and underscores.

=======
>>>>>>> v0.11.0
Adds the method `.get_absolute_url()` to `opal.core.pathways.Pathway` and
`opal.core.patient_lists.PatientList`.

Adds the Opal error `SignatureError`.

Pathway slugs may now include hyphens as well as numbers, lower case letters and underscores.

Bugfix: in edit_item.js $scope.episode_category is now set from episode.category_name
Expand Down
8 changes: 1 addition & 7 deletions opal/managers.py
Expand Up @@ -80,13 +80,11 @@ def serialised_episode_subrecords(self, episodes, user):
episode_subs[sub.episode_id][name].append(sub.to_dict(user))
return episode_subs

def serialised(self, user, episodes,
historic_tags=False, episode_history=False):
def serialised(self, user, episodes, historic_tags=False):
"""
Return a set of serialised EPISODES.
If HISTORIC_TAGS is Truthy, return deleted tags as well.
If EPISODE_HISTORY is Truthy return historic episodes as well.
"""
patient_ids = [e.patient_id for e in episodes]
patient_subs = defaultdict(lambda: defaultdict(list))
Expand Down Expand Up @@ -128,10 +126,6 @@ def serialised(self, user, episodes,
d['tagging'] = [taggings[e.id]]
d['tagging'][0]['id'] = e.id
serialised.append(d)

if episode_history:
d['episode_history'] = e._episode_history_to_dict(user)

return serialised

def serialised_active(self, user, **kw):
Expand Down
13 changes: 0 additions & 13 deletions opal/models.py
Expand Up @@ -854,17 +854,6 @@ def get_tag_names(self, user, historic=False):

return list(qs.values_list("value", flat=True))

def _episode_history_to_dict(self, user):
"""
Return a serialised version of this patient's episode history
"""
from opal.core.search.queries import episodes_for_user

order = 'start', 'end'
episode_history = self.patient.episode_set.order_by(*order)
episode_history = episodes_for_user(episode_history, user)
return [e.to_dict(user, shallow=True) for e in episode_history]

def to_dict(self, user, shallow=False):
"""
Serialisation to JSON for Episodes
Expand Down Expand Up @@ -898,8 +887,6 @@ def to_dict(self, user, shallow=False):
]

d['tagging'] = self.tagging_dict(user)

d['episode_history'] = self._episode_history_to_dict(user)
return d


Expand Down
2 changes: 0 additions & 2 deletions opal/tests/test_api.py
Expand Up @@ -644,8 +644,6 @@ def setUp(self):
self.expected = self.episode.to_dict(self.user)
self.expected["start"] = "14/01/2014"
self.expected["end"] = "15/01/2014"
self.expected["episode_history"][0]["end"] = "15/01/2014"
self.expected["episode_history"][0]["start"] = "14/01/2014"

def test_retrieve_episode(self):
response = json.loads(api.EpisodeViewSet().retrieve(self.mock_request, pk=self.episode.pk).content.decode('UTF-8'))
Expand Down
48 changes: 3 additions & 45 deletions opal/tests/test_episode.py
Expand Up @@ -148,50 +148,6 @@ def test_not_bulk_serialisable_episode_subrecords(self, episode_subrecords):
to_dict = episode.to_dict(self.user)
self.assertNotIn(InvisibleHatWearer.get_api_name(), to_dict)


def test_to_dict_with_multiple_episodes(self):
self.episode.start = datetime.date(2015, 7, 25)
self.episode.save()
prev = self.patient.create_episode()
prev.start = datetime.date(2012, 7, 25)
prev.end = datetime.date(2012, 8, 12)
prev.active=False
prev.save()

serialised = self.episode.to_dict(self.user)
self.assertEqual(2, len(serialised['episode_history']))
self.assertEqual(datetime.date(2012, 7, 25),
serialised['episode_history'][0]['start'])

def test_to_dict_episode_ordering(self):
patient = Patient.objects.create()
prev = patient.create_episode()
prev.start = datetime.date(2012, 7, 25)
prev.end = datetime.date(2012, 8, 12)
prev.active = False
prev.save()

previouser = patient.create_episode()
previouser.start = datetime.date(2011, 7, 25)
previouser.active = False
previouser.save()

episode = patient.create_episode()
episode.start = datetime.date(2014, 6, 23)
episode.save()

serialised = episode.to_dict(self.user)
self.assertEqual(3, len(serialised['episode_history']))
self.assertEqual(datetime.date(2011, 7, 25),
serialised['episode_history'][0]['start'])
self.assertEqual(datetime.date(2012, 7, 25),
serialised['episode_history'][1]['start'])

def test_to_dict_episode_history_includes_no_dates(self):
prev = self.patient.create_episode()
serialised = self.episode.to_dict(self.user)
self.assertEqual(2, len(serialised['episode_history']))

@patch('opal.models.episode_subrecords')
def test_to_dict_episode_with_many_to_many(self, episode_subrecords):
episode_subrecords.return_value = [HatWearer]
Expand All @@ -201,7 +157,9 @@ def test_to_dict_episode_with_many_to_many(self, episode_subrecords):
hw = HatWearer.objects.create(episode=prev)
hw.hats.add(bowler, top)
serialised = prev.to_dict(self.user)
self.assertEqual(serialised["hat_wearer"][0]["hats"], [u'bowler', u'top'])
self.assertEqual(
serialised["hat_wearer"][0]["hats"], [u'bowler', u'top']
)


class EpisodeCategoryTestCase(OpalTestCase):
Expand Down
4 changes: 2 additions & 2 deletions opal/tests/test_managers.py
Expand Up @@ -189,7 +189,7 @@ def test_serialised_equals_to_dict(self):
""" Serialised is an optimisation
"""
as_dict = Episode.objects.serialised(
self.user, [self.episode], episode_history=True
self.user, [self.episode]
)

expected = self.episode.to_dict(self.user)
Expand All @@ -202,6 +202,6 @@ def test_serialised_mine_tag_other_user(self):
user2 = self.make_user('the password', username='user2')
self.episode.set_tag_names(tags, user2)
as_dict = Episode.objects.serialised(
self.user, [self.episode], episode_history=False
self.user, [self.episode]
)
self.assertEqual(as_dict[0]['tagging'][0], {'id': 1})

0 comments on commit 8b9279d

Please sign in to comment.