{"action":"created","comment":{"url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/comments/111123599","pull_request_review_id":32344416,"id":111123599,"diff_hunk":"@@ -0,0 +1,43 @@\n+class EscortCreator\n+  def self.call(escort_attrs)\n+    new(escort_attrs).call\n+  end\n+\n+  def initialize(escort_attrs)\n+    @prison_number = escort_attrs.fetch(:prison_number)\n+  end\n+\n+  def call\n+    if existent_escort\n+      deep_clone_escort.tap(&:needs_review!)\n+    else\n+      Escort.create(prison_number: prison_number)\n+    end\n+  end\n+\n+  private\n+\n+  attr_reader :prison_number\n+\n+  INCLUDE_GRAPH = [\n+    { detainee: [\n+      :risk,\n+      { healthcare: [:medications] },\n+      { offences: [:current_offences] }\n+] },","path":"app/services/escort_creator.rb","position":27,"original_position":27,"commit_id":"38ee790d7adcdabf84f7559663de6dd82fcfbfc9","original_commit_id":"38ee790d7adcdabf84f7559663de6dd82fcfbfc9","user":{"login":"dan-palmer","id":1006365,"avatar_url":"https://avatars3.githubusercontent.com/u/1006365?v=3","gravatar_id":"","url":"https://api.github.com/users/dan-palmer","html_url":"https://github.com/dan-palmer","followers_url":"https://api.github.com/users/dan-palmer/followers","following_url":"https://api.github.com/users/dan-palmer/following{/other_user}","gists_url":"https://api.github.com/users/dan-palmer/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-palmer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-palmer/subscriptions","organizations_url":"https://api.github.com/users/dan-palmer/orgs","repos_url":"https://api.github.com/users/dan-palmer/repos","events_url":"https://api.github.com/users/dan-palmer/events{/privacy}","received_events_url":"https://api.github.com/users/dan-palmer/received_events","type":"User","site_admin":false},"body":"🚓 such padding","created_at":"2017-04-12T11:20:25Z","updated_at":"2017-04-12T11:37:33Z","html_url":"https://github.com/ministryofjustice/moving-people-safely/pull/264#discussion_r111123599","pull_request_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/264","_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/comments/111123599"},"html":{"href":"https://github.com/ministryofjustice/moving-people-safely/pull/264#discussion_r111123599"},"pull_request":{"href":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/264"}}},"pull_request":{"url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/264","id":114853196,"html_url":"https://github.com/ministryofjustice/moving-people-safely/pull/264","diff_url":"https://github.com/ministryofjustice/moving-people-safely/pull/264.diff","patch_url":"https://github.com/ministryofjustice/moving-people-safely/pull/264.patch","issue_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues/264","number":264,"state":"open","locked":false,"title":"Escort as top level object","user":{"login":"lostie","id":67125,"avatar_url":"https://avatars1.githubusercontent.com/u/67125?v=3","gravatar_id":"","url":"https://api.github.com/users/lostie","html_url":"https://github.com/lostie","followers_url":"https://api.github.com/users/lostie/followers","following_url":"https://api.github.com/users/lostie/following{/other_user}","gists_url":"https://api.github.com/users/lostie/gists{/gist_id}","starred_url":"https://api.github.com/users/lostie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lostie/subscriptions","organizations_url":"https://api.github.com/users/lostie/orgs","repos_url":"https://api.github.com/users/lostie/repos","events_url":"https://api.github.com/users/lostie/events{/privacy}","received_events_url":"https://api.github.com/users/lostie/received_events","type":"User","site_admin":false},"body":"Refactor data modelling to guarantee idempotency of escort\r\n\r\nAs it stands every time a new escort was created the information used\r\nfor a previous escort, namely, detainee information, risk assessment,\r\nhealthcare assessment, offences would be re-used and most likely\r\nmodified which meant we would track of the information used to perform\r\nthe previous escort.\r\n\r\nThese changes ensure that all the information used in an escort are\r\nrelated only to that escort and cannot be modify outside the scope of\r\nthe escort itself.\r\n\r\nThis turns out to be quite a big change in terms of:\r\n- Routes - all the data required to be created/modified is now under the\r\nescorts scope\r\n- Detainee and Move are not longer directly related but instead they\r\n    belong to an Escort record. There's potential, in the future for these\r\n    two models to be normalised and all the information related with them to\r\n    be present directly in the Escort record. Due to the nature of the\r\n    refactor we have refrained from doing any more changes than the MVP.\r\n- The risk and healthcare assessments and the offences are currently\r\n    related to a detainee, so the escort record access its information by\r\n    delegating their call to the detainee. There's potential for this to be\r\n    move directly to the escort, so that the escort has a directly\r\n    relationship with the data it requires\r\n- The workflows associated with the move, the risk and healthcare\r\n    assessments, and the offences, are defined in a very convoluted way\r\n    where the detainee holds the relation to the data but the move holds the\r\n    relation to the status of the data. In this PR we masked this by having\r\n    the models themselves to response to status enquires. Under the hood, we\r\n    are still navigation to this convoluted way of accessing the status. In\r\n    a future iteration we will simplify the process by having the model to\r\n    respond directly to this status enquires.\r\n- This PR starts to establish the responsability to the status of the\r\n    escort to the escort itself, although it currently does it by delegating\r\n    some of its status checks to the Move record. This is a transiction step\r\n    as the Move record has a lot of responsability that shouldn't really\r\n    have, but again, refactoring this would increase even more the size of\r\n    the PR which is already quite big.\r\n\r\nFuture iterations:\r\n- Establish correct relationships between models\r\n- Have escort to control directly its status","created_at":"2017-04-07T16:31:36Z","updated_at":"2017-04-12T11:37:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"001a2fcaf5db310d520c975a53f9e6a02e718877","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/264/commits","review_comments_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/264/comments","review_comment_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues/264/comments","statuses_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/statuses/38ee790d7adcdabf84f7559663de6dd82fcfbfc9","head":{"label":"ministryofjustice:move-top-level-object","ref":"move-top-level-object","sha":"38ee790d7adcdabf84f7559663de6dd82fcfbfc9","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars0.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":61026442,"name":"moving-people-safely","full_name":"ministryofjustice/moving-people-safely","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars0.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/moving-people-safely","description":"Moving People Safely - Digital Person Escort Record","fork":false,"url":"https://api.github.com/repos/ministryofjustice/moving-people-safely","forks_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/forks","keys_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/events","assignees_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/merges","archive_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/releases{/id}","deployments_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/deployments","created_at":"2016-06-13T10:10:06Z","updated_at":"2016-11-29T15:36:53Z","pushed_at":"2017-04-12T09:25:39Z","git_url":"git://github.com/ministryofjustice/moving-people-safely.git","ssh_url":"git@github.com:ministryofjustice/moving-people-safely.git","clone_url":"https://github.com/ministryofjustice/moving-people-safely.git","svn_url":"https://github.com/ministryofjustice/moving-people-safely","homepage":"","size":1495,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":1,"default_branch":"master"}},"base":{"label":"ministryofjustice:master","ref":"master","sha":"28425fe6497e29969014e6b8b96ba39604f30423","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars0.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":61026442,"name":"moving-people-safely","full_name":"ministryofjustice/moving-people-safely","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars0.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/moving-people-safely","description":"Moving People Safely - Digital Person Escort Record","fork":false,"url":"https://api.github.com/repos/ministryofjustice/moving-people-safely","forks_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/forks","keys_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/events","assignees_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/merges","archive_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/releases{/id}","deployments_url":"https://api.github.com/repos/ministryofjustice/moving-people-safely/deployments","created_at":"2016-06-13T10:10:06Z","updated_at":"2016-11-29T15:36:53Z","pushed_at":"2017-04-12T09:25:39Z","git_url":"git://github.com/ministryofjustice/moving-people-safely.git","ssh_url":"git@github.com:ministryofjustice/moving-people-safely.git","clone_url":"https://github.com/ministryofjustice/moving-people-safely.git","svn_url":"https://github.com/ministryofjustice/moving-people-safely","homepage":"","size":1495,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/264"},"html":{"href":"https://github.com/ministryofjustice/moving-people-safely/pull/264"},"issue":{"href":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues/264"},"comments":{"href":"https://api.github.com/repos/ministryofjustice/moving-people-safely/issues/264/comments"},"review_comments":{"href":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/264/comments"},"review_comment":{"href":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ministryofjustice/moving-people-safely/pulls/264/commits"},"statuses":{"href":"https://api.github.com/repos/ministryofjustice/moving-people-safely/statuses/38ee790d7adcdabf84f7559663de6dd82fcfbfc9"}}}}
{"actor":{"display_login":"dan-palmer"}}