{"action":"created","comment":{"url":"https://api.github.com/repos/MRN-Code/quarterback/pulls/comments/84168574","pull_request_review_id":4956481,"id":84168574,"diff_hunk":"@@ -0,0 +1,70 @@\n+'use strict';\n+\n+const getFormAttributes = (bookshelf, query) => {\n+  const requestJson = JSON.parse(query.json);\n+  const modalityId = parseInt(requestJson._modalityId, 10);\n+  let qryStr = `SELECT\n+    a.attribute_id, \n+    a.modality_id, \n+    a.label AS attribute_label,\n+    a.description AS attribute_description,\n+    o.option_id,\n+    o.option_label,\n+    o.count\n+    FROM dx_source_attributes_vw a\n+    INNER JOIN mrs_modalities_vw m\n+       ON m.modality_id = a.modality_id\n+    INNER JOIN dx_options_mv o\n+       ON a.attribute_id = o.attribute_id\n+    WHERE o.option_id IS NOT NULL `;\n+    // if modality_id != -1, then we are calling this function from the GUI\n+    //    select only the specified modality_id and DON'T show attributes that\n+    //    are not supposed to be displayed to user\n+    // else modality_id == -1, then we are calling this function from the API\n+    //    select ALL modality_id's and ALL attributes\n+  if (modalityId !== '-1') {\n+    qryStr += ` AND m.modality_id = ${modalityId} AND a.display_to_user IS TRUE `;\n+  }\n+  qryStr += `ORDER BY m.modality_id, a.dx_attribute_order,\n+    CASE\n+      WHEN substring(o.option_label from '^[0-9]*$') IS NULL THEN 9999\n+      ELSE CAST(o.option_label as integer)\n+    END,\n+    o.option_label`;\n+\n+  return bookshelf.knex.raw(qryStr)\n+    .then(response => {\n+      const ret = [];\n+      const _attributes = {};\n+      for (let i = 0; i < response.rows.length; i++) {\n+        const attributeId = parseInt(response.rows[i].attribute_id, 10);\n+        if (_attributes[attributeId] === undefined) {\n+          _attributes[attributeId] = {};\n+          _attributes[attributeId]._options = [];\n+        }\n+\n+        _attributes[attributeId]._attributeId = attributeId;\n+        _attributes[attributeId]._attributeLabel = response.rows[i].attribute_label;\n+        _attributes[attributeId]._attributeDescription = response.rows[i].attribute_description;\n+        _attributes[attributeId]._modalityId = parseInt(response.rows[i].modality_id, 10);\n+        _attributes[attributeId]._options.push(\n+          {\n+            optionId: parseInt(response.rows[i].option_id, 10),","path":"packages/steelpenny/src/lib/controllers/dataexchange/filter.js","position":52,"original_position":52,"commit_id":"fd7d6c77c6740a4b2e87a95aa4fb54a091fb0920","original_commit_id":"fd7d6c77c6740a4b2e87a95aa4fb54a091fb0920","user":{"login":"drewlandis","id":5331362,"avatar_url":"https://avatars.githubusercontent.com/u/5331362?v=3","gravatar_id":"","url":"https://api.github.com/users/drewlandis","html_url":"https://github.com/drewlandis","followers_url":"https://api.github.com/users/drewlandis/followers","following_url":"https://api.github.com/users/drewlandis/following{/other_user}","gists_url":"https://api.github.com/users/drewlandis/gists{/gist_id}","starred_url":"https://api.github.com/users/drewlandis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drewlandis/subscriptions","organizations_url":"https://api.github.com/users/drewlandis/orgs","repos_url":"https://api.github.com/users/drewlandis/repos","events_url":"https://api.github.com/users/drewlandis/events{/privacy}","received_events_url":"https://api.github.com/users/drewlandis/received_events","type":"User","site_admin":false},"body":"option_id has type `text` in the database and it is not always numeric.  I think that we should _not_ call `parseInt` on it, otherwise we may end up with `NaN`.  E.g. `parseInt('foo', 10)` --> `NaN`","created_at":"2016-10-19T21:14:14Z","updated_at":"2016-10-19T21:21:17Z","html_url":"https://github.com/MRN-Code/quarterback/pull/25#discussion_r84168574","pull_request_url":"https://api.github.com/repos/MRN-Code/quarterback/pulls/25","_links":{"self":{"href":"https://api.github.com/repos/MRN-Code/quarterback/pulls/comments/84168574"},"html":{"href":"https://github.com/MRN-Code/quarterback/pull/25#discussion_r84168574"},"pull_request":{"href":"https://api.github.com/repos/MRN-Code/quarterback/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/MRN-Code/quarterback/pulls/25","id":89919524,"html_url":"https://github.com/MRN-Code/quarterback/pull/25","diff_url":"https://github.com/MRN-Code/quarterback/pull/25.diff","patch_url":"https://github.com/MRN-Code/quarterback/pull/25.patch","issue_url":"https://api.github.com/repos/MRN-Code/quarterback/issues/25","number":25,"state":"open","locked":false,"title":"Dataexchange filter getformattributes","user":{"login":"ruwang","id":5331481,"avatar_url":"https://avatars.githubusercontent.com/u/5331481?v=3","gravatar_id":"","url":"https://api.github.com/users/ruwang","html_url":"https://github.com/ruwang","followers_url":"https://api.github.com/users/ruwang/followers","following_url":"https://api.github.com/users/ruwang/following{/other_user}","gists_url":"https://api.github.com/users/ruwang/gists{/gist_id}","starred_url":"https://api.github.com/users/ruwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ruwang/subscriptions","organizations_url":"https://api.github.com/users/ruwang/orgs","repos_url":"https://api.github.com/users/ruwang/repos","events_url":"https://api.github.com/users/ruwang/events{/privacy}","received_events_url":"https://api.github.com/users/ruwang/received_events","type":"User","site_admin":false},"body":"#### asana\r\nhttps://app.asana.com/0/8755179914462/197010238354303\r\n\r\n# problem statement\r\n`getFormAttributes` controller for dcwebservice rewrite.\r\n","created_at":"2016-10-18T23:50:53Z","updated_at":"2016-10-19T21:21:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c332a1423397df8711f530f1260b579fe1971ad3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/MRN-Code/quarterback/pulls/25/commits","review_comments_url":"https://api.github.com/repos/MRN-Code/quarterback/pulls/25/comments","review_comment_url":"https://api.github.com/repos/MRN-Code/quarterback/pulls/comments{/number}","comments_url":"https://api.github.com/repos/MRN-Code/quarterback/issues/25/comments","statuses_url":"https://api.github.com/repos/MRN-Code/quarterback/statuses/fd7d6c77c6740a4b2e87a95aa4fb54a091fb0920","head":{"label":"MRN-Code:dataexchange-filter-getformattributes","ref":"dataexchange-filter-getformattributes","sha":"fd7d6c77c6740a4b2e87a95aa4fb54a091fb0920","user":{"login":"MRN-Code","id":5330818,"avatar_url":"https://avatars.githubusercontent.com/u/5330818?v=3","gravatar_id":"","url":"https://api.github.com/users/MRN-Code","html_url":"https://github.com/MRN-Code","followers_url":"https://api.github.com/users/MRN-Code/followers","following_url":"https://api.github.com/users/MRN-Code/following{/other_user}","gists_url":"https://api.github.com/users/MRN-Code/gists{/gist_id}","starred_url":"https://api.github.com/users/MRN-Code/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MRN-Code/subscriptions","organizations_url":"https://api.github.com/users/MRN-Code/orgs","repos_url":"https://api.github.com/users/MRN-Code/repos","events_url":"https://api.github.com/users/MRN-Code/events{/privacy}","received_events_url":"https://api.github.com/users/MRN-Code/received_events","type":"Organization","site_admin":false},"repo":{"id":55814426,"name":"quarterback","full_name":"MRN-Code/quarterback","owner":{"login":"MRN-Code","id":5330818,"avatar_url":"https://avatars.githubusercontent.com/u/5330818?v=3","gravatar_id":"","url":"https://api.github.com/users/MRN-Code","html_url":"https://github.com/MRN-Code","followers_url":"https://api.github.com/users/MRN-Code/followers","following_url":"https://api.github.com/users/MRN-Code/following{/other_user}","gists_url":"https://api.github.com/users/MRN-Code/gists{/gist_id}","starred_url":"https://api.github.com/users/MRN-Code/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MRN-Code/subscriptions","organizations_url":"https://api.github.com/users/MRN-Code/orgs","repos_url":"https://api.github.com/users/MRN-Code/repos","events_url":"https://api.github.com/users/MRN-Code/events{/privacy}","received_events_url":"https://api.github.com/users/MRN-Code/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/MRN-Code/quarterback","description":"coins.mrn.org monorepo","fork":false,"url":"https://api.github.com/repos/MRN-Code/quarterback","forks_url":"https://api.github.com/repos/MRN-Code/quarterback/forks","keys_url":"https://api.github.com/repos/MRN-Code/quarterback/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MRN-Code/quarterback/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MRN-Code/quarterback/teams","hooks_url":"https://api.github.com/repos/MRN-Code/quarterback/hooks","issue_events_url":"https://api.github.com/repos/MRN-Code/quarterback/issues/events{/number}","events_url":"https://api.github.com/repos/MRN-Code/quarterback/events","assignees_url":"https://api.github.com/repos/MRN-Code/quarterback/assignees{/user}","branches_url":"https://api.github.com/repos/MRN-Code/quarterback/branches{/branch}","tags_url":"https://api.github.com/repos/MRN-Code/quarterback/tags","blobs_url":"https://api.github.com/repos/MRN-Code/quarterback/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MRN-Code/quarterback/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MRN-Code/quarterback/git/refs{/sha}","trees_url":"https://api.github.com/repos/MRN-Code/quarterback/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MRN-Code/quarterback/statuses/{sha}","languages_url":"https://api.github.com/repos/MRN-Code/quarterback/languages","stargazers_url":"https://api.github.com/repos/MRN-Code/quarterback/stargazers","contributors_url":"https://api.github.com/repos/MRN-Code/quarterback/contributors","subscribers_url":"https://api.github.com/repos/MRN-Code/quarterback/subscribers","subscription_url":"https://api.github.com/repos/MRN-Code/quarterback/subscription","commits_url":"https://api.github.com/repos/MRN-Code/quarterback/commits{/sha}","git_commits_url":"https://api.github.com/repos/MRN-Code/quarterback/git/commits{/sha}","comments_url":"https://api.github.com/repos/MRN-Code/quarterback/comments{/number}","issue_comment_url":"https://api.github.com/repos/MRN-Code/quarterback/issues/comments{/number}","contents_url":"https://api.github.com/repos/MRN-Code/quarterback/contents/{+path}","compare_url":"https://api.github.com/repos/MRN-Code/quarterback/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MRN-Code/quarterback/merges","archive_url":"https://api.github.com/repos/MRN-Code/quarterback/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MRN-Code/quarterback/downloads","issues_url":"https://api.github.com/repos/MRN-Code/quarterback/issues{/number}","pulls_url":"https://api.github.com/repos/MRN-Code/quarterback/pulls{/number}","milestones_url":"https://api.github.com/repos/MRN-Code/quarterback/milestones{/number}","notifications_url":"https://api.github.com/repos/MRN-Code/quarterback/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MRN-Code/quarterback/labels{/name}","releases_url":"https://api.github.com/repos/MRN-Code/quarterback/releases{/id}","deployments_url":"https://api.github.com/repos/MRN-Code/quarterback/deployments","created_at":"2016-04-08T22:53:27Z","updated_at":"2016-04-12T20:26:13Z","pushed_at":"2016-10-19T20:12:33Z","git_url":"git://github.com/MRN-Code/quarterback.git","ssh_url":"git@github.com:MRN-Code/quarterback.git","clone_url":"https://github.com/MRN-Code/quarterback.git","svn_url":"https://github.com/MRN-Code/quarterback","homepage":null,"size":13833,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":15,"forks":0,"open_issues":15,"watchers":0,"default_branch":"master"}},"base":{"label":"MRN-Code:dcrerwrite","ref":"dcrerwrite","sha":"eb088109b5a152be4e948714cc9da5a35c74e5f8","user":{"login":"MRN-Code","id":5330818,"avatar_url":"https://avatars.githubusercontent.com/u/5330818?v=3","gravatar_id":"","url":"https://api.github.com/users/MRN-Code","html_url":"https://github.com/MRN-Code","followers_url":"https://api.github.com/users/MRN-Code/followers","following_url":"https://api.github.com/users/MRN-Code/following{/other_user}","gists_url":"https://api.github.com/users/MRN-Code/gists{/gist_id}","starred_url":"https://api.github.com/users/MRN-Code/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MRN-Code/subscriptions","organizations_url":"https://api.github.com/users/MRN-Code/orgs","repos_url":"https://api.github.com/users/MRN-Code/repos","events_url":"https://api.github.com/users/MRN-Code/events{/privacy}","received_events_url":"https://api.github.com/users/MRN-Code/received_events","type":"Organization","site_admin":false},"repo":{"id":55814426,"name":"quarterback","full_name":"MRN-Code/quarterback","owner":{"login":"MRN-Code","id":5330818,"avatar_url":"https://avatars.githubusercontent.com/u/5330818?v=3","gravatar_id":"","url":"https://api.github.com/users/MRN-Code","html_url":"https://github.com/MRN-Code","followers_url":"https://api.github.com/users/MRN-Code/followers","following_url":"https://api.github.com/users/MRN-Code/following{/other_user}","gists_url":"https://api.github.com/users/MRN-Code/gists{/gist_id}","starred_url":"https://api.github.com/users/MRN-Code/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MRN-Code/subscriptions","organizations_url":"https://api.github.com/users/MRN-Code/orgs","repos_url":"https://api.github.com/users/MRN-Code/repos","events_url":"https://api.github.com/users/MRN-Code/events{/privacy}","received_events_url":"https://api.github.com/users/MRN-Code/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/MRN-Code/quarterback","description":"coins.mrn.org monorepo","fork":false,"url":"https://api.github.com/repos/MRN-Code/quarterback","forks_url":"https://api.github.com/repos/MRN-Code/quarterback/forks","keys_url":"https://api.github.com/repos/MRN-Code/quarterback/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MRN-Code/quarterback/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MRN-Code/quarterback/teams","hooks_url":"https://api.github.com/repos/MRN-Code/quarterback/hooks","issue_events_url":"https://api.github.com/repos/MRN-Code/quarterback/issues/events{/number}","events_url":"https://api.github.com/repos/MRN-Code/quarterback/events","assignees_url":"https://api.github.com/repos/MRN-Code/quarterback/assignees{/user}","branches_url":"https://api.github.com/repos/MRN-Code/quarterback/branches{/branch}","tags_url":"https://api.github.com/repos/MRN-Code/quarterback/tags","blobs_url":"https://api.github.com/repos/MRN-Code/quarterback/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MRN-Code/quarterback/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MRN-Code/quarterback/git/refs{/sha}","trees_url":"https://api.github.com/repos/MRN-Code/quarterback/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MRN-Code/quarterback/statuses/{sha}","languages_url":"https://api.github.com/repos/MRN-Code/quarterback/languages","stargazers_url":"https://api.github.com/repos/MRN-Code/quarterback/stargazers","contributors_url":"https://api.github.com/repos/MRN-Code/quarterback/contributors","subscribers_url":"https://api.github.com/repos/MRN-Code/quarterback/subscribers","subscription_url":"https://api.github.com/repos/MRN-Code/quarterback/subscription","commits_url":"https://api.github.com/repos/MRN-Code/quarterback/commits{/sha}","git_commits_url":"https://api.github.com/repos/MRN-Code/quarterback/git/commits{/sha}","comments_url":"https://api.github.com/repos/MRN-Code/quarterback/comments{/number}","issue_comment_url":"https://api.github.com/repos/MRN-Code/quarterback/issues/comments{/number}","contents_url":"https://api.github.com/repos/MRN-Code/quarterback/contents/{+path}","compare_url":"https://api.github.com/repos/MRN-Code/quarterback/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MRN-Code/quarterback/merges","archive_url":"https://api.github.com/repos/MRN-Code/quarterback/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MRN-Code/quarterback/downloads","issues_url":"https://api.github.com/repos/MRN-Code/quarterback/issues{/number}","pulls_url":"https://api.github.com/repos/MRN-Code/quarterback/pulls{/number}","milestones_url":"https://api.github.com/repos/MRN-Code/quarterback/milestones{/number}","notifications_url":"https://api.github.com/repos/MRN-Code/quarterback/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MRN-Code/quarterback/labels{/name}","releases_url":"https://api.github.com/repos/MRN-Code/quarterback/releases{/id}","deployments_url":"https://api.github.com/repos/MRN-Code/quarterback/deployments","created_at":"2016-04-08T22:53:27Z","updated_at":"2016-04-12T20:26:13Z","pushed_at":"2016-10-19T20:12:33Z","git_url":"git://github.com/MRN-Code/quarterback.git","ssh_url":"git@github.com:MRN-Code/quarterback.git","clone_url":"https://github.com/MRN-Code/quarterback.git","svn_url":"https://github.com/MRN-Code/quarterback","homepage":null,"size":13833,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":15,"forks":0,"open_issues":15,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/MRN-Code/quarterback/pulls/25"},"html":{"href":"https://github.com/MRN-Code/quarterback/pull/25"},"issue":{"href":"https://api.github.com/repos/MRN-Code/quarterback/issues/25"},"comments":{"href":"https://api.github.com/repos/MRN-Code/quarterback/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/MRN-Code/quarterback/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/MRN-Code/quarterback/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/MRN-Code/quarterback/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/MRN-Code/quarterback/statuses/fd7d6c77c6740a4b2e87a95aa4fb54a091fb0920"}}}}
{"actor":{"display_login":"drewlandis"}}