{"action":"created","issue":{"url":"https://api.github.com/repos/medic/medic-webapp/issues/1309","labels_url":"https://api.github.com/repos/medic/medic-webapp/issues/1309/labels{/name}","comments_url":"https://api.github.com/repos/medic/medic-webapp/issues/1309/comments","events_url":"https://api.github.com/repos/medic/medic-webapp/issues/1309/events","html_url":"https://github.com/medic/medic-webapp/issues/1309","id":107596736,"number":1309,"title":"map project form names to internal representation names","user":{"login":"btbonval","id":880439,"avatar_url":"https://avatars.githubusercontent.com/u/880439?v=3","gravatar_id":"","url":"https://api.github.com/users/btbonval","html_url":"https://github.com/btbonval","followers_url":"https://api.github.com/users/btbonval/followers","following_url":"https://api.github.com/users/btbonval/following{/other_user}","gists_url":"https://api.github.com/users/btbonval/gists{/gist_id}","starred_url":"https://api.github.com/users/btbonval/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btbonval/subscriptions","organizations_url":"https://api.github.com/users/btbonval/orgs","repos_url":"https://api.github.com/users/btbonval/repos","events_url":"https://api.github.com/users/btbonval/events{/privacy}","received_events_url":"https://api.github.com/users/btbonval/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"btbonval","id":880439,"avatar_url":"https://avatars.githubusercontent.com/u/880439?v=3","gravatar_id":"","url":"https://api.github.com/users/btbonval","html_url":"https://github.com/btbonval","followers_url":"https://api.github.com/users/btbonval/followers","following_url":"https://api.github.com/users/btbonval/following{/other_user}","gists_url":"https://api.github.com/users/btbonval/gists{/gist_id}","starred_url":"https://api.github.com/users/btbonval/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btbonval/subscriptions","organizations_url":"https://api.github.com/users/btbonval/orgs","repos_url":"https://api.github.com/users/btbonval/repos","events_url":"https://api.github.com/users/btbonval/events{/privacy}","received_events_url":"https://api.github.com/users/btbonval/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/medic/medic-webapp/milestones/35","html_url":"https://github.com/medic/medic-webapp/milestones/Iteration%202015-39:%20Mobile%20Application%20Ready%20for%20Internal%20Testing","labels_url":"https://api.github.com/repos/medic/medic-webapp/milestones/35/labels","id":1294425,"number":35,"title":"Iteration 2015-39: Mobile Application Ready for Internal Testing","description":"","creator":{"login":"browndav","id":763977,"avatar_url":"https://avatars.githubusercontent.com/u/763977?v=3","gravatar_id":"","url":"https://api.github.com/users/browndav","html_url":"https://github.com/browndav","followers_url":"https://api.github.com/users/browndav/followers","following_url":"https://api.github.com/users/browndav/following{/other_user}","gists_url":"https://api.github.com/users/browndav/gists{/gist_id}","starred_url":"https://api.github.com/users/browndav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/browndav/subscriptions","organizations_url":"https://api.github.com/users/browndav/orgs","repos_url":"https://api.github.com/users/browndav/repos","events_url":"https://api.github.com/users/browndav/events{/privacy}","received_events_url":"https://api.github.com/users/browndav/received_events","type":"User","site_admin":false},"open_issues":19,"closed_issues":10,"state":"open","created_at":"2015-09-07T23:17:19Z","updated_at":"2015-09-28T15:17:31Z","due_on":"2015-10-05T07:00:00Z","closed_at":null},"comments":4,"created_at":"2015-09-21T20:55:52Z","updated_at":"2015-09-28T16:01:24Z","closed_at":null,"body":"Calculations are much easier when the source of the data is the same, be it Spreadsheets or Postgres.\r\n\r\nSo when each project decides to have a different ANC registration form name (e.g. ANCR, R, P, a Nepalese character that I can't reproduce), yet the fields are pretty much the same, then we get into a situation where our calculations should work but won't due to missing pointers/tables/sheets.\r\n\r\nOne easy solution is to create a view like `formview_ANCR` and simply `SELECT  * FROM formview_$$$$` where `$$$$` is the project's form name.\r\n\r\nBut then a recent project has started using reserved form names for different reasons, so maybe instead of `formview_ANCR` we might want `useview_ANCR` so that there is no name collisions between what analysis wants to read from and what projects want to write to.\r\n\r\nThen we create a mapping between `formview_XXX` and `useview_YYY` in some table config. Some PL/pgSQL function would read the table config and generate a `useview` for each `formview`.\r\n\r\nThis covers the 75% use case. However there are some instances where `ANCR` is actually a combination of both `P` and `R` as a union, and one instance where `ANCR` is actually a combination of `P` and `R` as a partial union (`P` + `R` where `R` patient is not in `P`). The mapping might need to be able to define custom SQL or PL/pgSQL rather than just one `formview` mapped onto a `useview`."},"comment":{"url":"https://api.github.com/repos/medic/medic-webapp/issues/comments/143788593","html_url":"https://github.com/medic/medic-webapp/issues/1309#issuecomment-143788593","issue_url":"https://api.github.com/repos/medic/medic-webapp/issues/1309","id":143788593,"user":{"login":"btbonval","id":880439,"avatar_url":"https://avatars.githubusercontent.com/u/880439?v=3","gravatar_id":"","url":"https://api.github.com/users/btbonval","html_url":"https://github.com/btbonval","followers_url":"https://api.github.com/users/btbonval/followers","following_url":"https://api.github.com/users/btbonval/following{/other_user}","gists_url":"https://api.github.com/users/btbonval/gists{/gist_id}","starred_url":"https://api.github.com/users/btbonval/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btbonval/subscriptions","organizations_url":"https://api.github.com/users/btbonval/orgs","repos_url":"https://api.github.com/users/btbonval/repos","events_url":"https://api.github.com/users/btbonval/events{/privacy}","received_events_url":"https://api.github.com/users/btbonval/received_events","type":"User","site_admin":false},"created_at":"2015-09-28T16:01:24Z","updated_at":"2015-09-28T16:01:24Z","body":"It looks like views are not typed and are thus not actually tracked by many of the postgres column introspection capabilities noted here:\r\nhttp://www.alberton.info/postgresql_meta_info.html#.Vgli4bM2tyR\r\n\r\nPerhaps a try/catch/else around `SELECT field FROM view` would work.\r\nhttp://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING"}}