Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drug labels in pml #107

Merged
merged 29 commits into from
Mar 9, 2017
Merged

Drug labels in pml #107

merged 29 commits into from
Mar 9, 2017

Conversation

c-brenn
Copy link
Contributor

@c-brenn c-brenn commented Mar 8, 2017

new drug format as per customer's requests.

shawa and others added 12 commits March 8, 2017 14:23
* removes ddi fetching from pml controller
* adds endpoint for fetching ddis for a given list of dinto uris
* adds endpoint for fetching dinto uris for a given list of drugs
drugs are now specified in PML using `drug { "..." }`.
ugly code but works :older-woman:
@c-brenn
Copy link
Contributor Author

c-brenn commented Mar 8, 2017

drugs can be specified in PML like so

requires { drug { "paracetamol" } }
  • /api/pml returns the list of english drugs in a pml file
  • /api/uris takes a list of english drugs and uses the new asclpius endpoints to find their uris
  • api/ddis takes a list of uris and returns their ddis

The front-end code works but is nice and ugly. The content-type has to be explicitly set to application/json or else phoenix thinks it's text/plain

if (uris_response.ok) {
const data = await uris_response.json();
const uris = Object.keys(data.uris.found);
console.log(uris);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove this

##### Request Body

```json
{"labels": [ "paracetamol", "flat seven up", "cocaine"]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be labels or can we just send the list with no object around it?

```json
{"drugs": ["chebi:421707", "chebi:465284", "dinto:DB00503", "chebi:9342"]}
{
"drugs": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be drugs or can we just send the list with no object around it? Realise this is an old one but sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps not needed - I kind of like the context that the outer object gives though.


```json
{
"found": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we want this instead

{
  "found": [
    {
      "uri": "http://purl.obolibrary.org/obo/CHEBI_27958",
      "label": "cocaine"
    },
    {
      "uri": "http://purl.obolibrary.org/obo/CHEBI_46195",
      "label": "paracetamol"
    }
  ],
  "not_found": [
    "flat seven up"
  ]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our reasoning for the current format is that when DDIs are returned the front-end will need to lookup the names of the drugs in each DDI. The DDIs return URIs for the participating drugs. The map format makes this easy.

def drugs(labels=None):

if labels is not None:
if not isinstance(labels, frozenset):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need to catch this, we should accept any hashable, if it's not hashable then the lru_cache will throw anyway

@sparql
def ddi_from_drugs(drugs):
if not isinstance(drugs, frozenset):
raise ValueError("for cachability, `drugs` must be given as a frozenset")

print(drugs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presume this isn't needed

@@ -12,17 +12,47 @@ async function submitFile() {
hideFileForm();
hideResults();
try {
const response = await fetch(this.action, {
const drugs_response = await fetch(this.action, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A style thing for the JS bits camelCase it

@@ -12,17 +12,47 @@ async function submitFile() {
hideFileForm();
hideResults();
try {
const response = await fetch(this.action, {
const drugs_response = await fetch(this.action, {
method: 'POST',
body: new FormData(this),
credentials: 'same-origin',
headers: new Headers({authorization: apiAccessToken})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably want 'Accept': 'application/json, text/plain, */*' headers on all of these requests

@22a
Copy link
Contributor

22a commented Mar 8, 2017

Working on the live updates(drugs show up before ddis are queried), pls don't merge yet 💇‍♂️

"""
params = request.get_json()
if params is None or 'labels' not in params or not params['labels']:
raise InvalidUsage("Expecting {'labels': [...]} with at least two labels")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message doesn't really match up

shawa and others added 4 commits March 8, 2017 21:03
added display panel for unidentified drugs
removed superfluous class addition to panels
if (urisResponse.ok) {
const data = await urisResponse.json();
const uris = Object.keys(data.uris.found);
const unidentifiedDrugs = Object.values(data.uris.not_found);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if you need Object.values here. I think not_found is just a list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops lol

@22a
Copy link
Contributor

22a commented Mar 8, 2017

few things going on in that last commit:

  • added unidentified drugs panel
  • added sample pml file with silly "drugs" for manual visual testing of panels
  • removed superfluous class removal in the display functions (the classes get reset at the start of the request chain)

the unidentified panel looks like this:
screen shot 2017-03-08 at 21 37 27

it also raises a few questions:

  • what do we want to display to the user when the request chain is broken at the different points (when found URI's is less than 2 and when identifiable drugs is less than 0{thinking about this, this should also probably be 2, as there's no point getting the uri of one drug alone})
  • do we want to make the error panel more expressive (where we can change the panel header as well)

@22a
Copy link
Contributor

22a commented Mar 8, 2017

also, the request chain is getting quite hairy now(v nested), perhaps we could consider breaking the chain out to separate handlers? bleugh

@c-brenn
Copy link
Contributor Author

c-brenn commented Mar 8, 2017

Nice work.

👍 yeah I'm all for refactoring the request chain.

I think we need a bigger discussion about the UI that's beyond the scope of this PR.

displayError(await urisResponse.json());
}
else {
displayError({"message": "No drugs found"});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is old syntax, {message: "bleugh"} would be nicer, i see we have used it above

@c-brenn
Copy link
Contributor Author

c-brenn commented Mar 9, 2017

think this is ready to go - any further changes needed?

This was referenced Mar 9, 2017
@22a
Copy link
Contributor

22a commented Mar 9, 2017

Looks good to 🚢 the 🐶 to me. @houli will need to approve his requested changes as I feel dismissing his review would be a breach of interpersonal trust and set a worrying precedent

@c-brenn
Copy link
Contributor Author

c-brenn commented Mar 9, 2017

Actually, the frontend changes should go in he change log.

  • the unidentified drugs
  • change in spinner behaviour

@22a
Copy link
Contributor

22a commented Mar 9, 2017

Good spot, will add those now

`found` is now a list of objects instead of one big map
@c-brenn c-brenn merged commit 4a2b6f1 into release-1 Mar 9, 2017
@c-brenn c-brenn deleted the drug-labels-in-pml branch March 9, 2017 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants