-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from tom-and-the-toothfairies/iteration1-2
Iteration 1 - Again
- Loading branch information
Showing
60 changed files
with
2,653 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def enrich(ddis): | ||
def _enrich(ddi): | ||
result = {'harmful': bool(hash(ddi['uri']) % 2), | ||
'spacing': abs(hash(ddi['uri']))%14 + 1} | ||
result.update(ddi) | ||
return result | ||
|
||
return [_enrich(ddi) for ddi in ddis] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
process foo { | ||
task { | ||
action baz { | ||
tool { "pills" } | ||
script { "eat the pills" } | ||
agent { "patient" } | ||
requires { | ||
drug { "paracetamol" } | ||
} | ||
provides { "a cured patient" } | ||
} | ||
action baz2 { | ||
tool { "pills" } | ||
script { "eat the pills" } | ||
agent { "patient" } | ||
requires { | ||
drug { "cocaine" } | ||
} | ||
provides { "a cured patient" } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Feature: PML Download | ||
In order to refine PML analysis | ||
As a clinician | ||
I should be able to download the PML file resulting from PML TX transformations | ||
|
||
Scenario: uploading a valid PML file | ||
Given I am on the home page | ||
When I select "ddis.pml" | ||
And I submit the upload form | ||
Then I should see the PML download button | ||
And the PML download button should have the correct href |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Then(/^I should see the PML download button$/) do | ||
button = find('#pml-download-anchor') | ||
|
||
expect(button).to be_visible | ||
end | ||
|
||
Then(/^the PML download button should have the correct href$/) do | ||
button = find('#pml-download-anchor') | ||
|
||
expect(button[:href]).to have_content('authorization_token=') | ||
expect(button[:href]).to have_content('ast=') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule Panacea.Pml.Analysis do | ||
alias __MODULE__ | ||
alias Panacea.Pml.Analysis.{Drugs, Unnamed} | ||
|
||
defstruct [:drugs, :unnamed, :ast] | ||
|
||
def run(ast) do | ||
drugs = Drugs.run(ast) | ||
unnamed = Unnamed.run(ast) | ||
|
||
encoded_ast = | ||
ast | ||
|> :erlang.term_to_binary() | ||
|> Base.encode64() | ||
|
||
{:ok, %Analysis{drugs: drugs, unnamed: unnamed, ast: encoded_ast}} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Panacea.Pml.Analysis.Drugs do | ||
|
||
def run(ast) do | ||
analyse([], ast) | ||
end | ||
|
||
defp analyse(result, {:requires, _, {:drug, [line: line], label}}) do | ||
[%{label: strip_quotes(label), line: line} | result] | ||
end | ||
defp analyse(result, {_, _, children}) when is_list(children) do | ||
Enum.reduce(children, result, fn(child, acc) -> | ||
analyse(acc, child) | ||
end) | ||
end | ||
defp analyse(result, _), do: result | ||
|
||
defp strip_quotes(char_list) do | ||
char_list | ||
|> :string.strip(:both, ?") | ||
|> to_string() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Panacea.Pml.Analysis.Unnamed do | ||
|
||
@composite [:task, :sequence, :branch, :selection, :iteration, :action, :process] | ||
|
||
def run(ast) do | ||
analyse([], ast) | ||
end | ||
|
||
defp analyse(result, {type, attrs, children}) when type in @composite do | ||
result = | ||
if !Keyword.has_key?(attrs, :name) do | ||
[%{type: type, line: Keyword.get(attrs, :line)} | result] | ||
else | ||
result | ||
end | ||
|
||
Enum.reduce(children, result, fn (child, acc) -> | ||
analyse(acc, child) | ||
end) | ||
end | ||
defp analyse(result, _), do: result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule Panacea.Pml.Ast do | ||
@multi_line_constructs ~w(process action task sequence selection branch iteration)a | ||
@single_line_constructs ~w(requires provides agent tool script input output)a | ||
|
||
@doc """ | ||
Takes an AST and returns the PML it represents in an IO-List | ||
""" | ||
def to_pml(ast) do | ||
do_unquote(ast, 0) | ||
end | ||
|
||
defp do_unquote({type, attrs, children}, depth) when type in @multi_line_constructs do | ||
optional_name = get_with_default(attrs, :name) | ||
optional_type = get_with_default(attrs, :type) | ||
|
||
[indent(depth), to_string(type), optional_name, optional_type, " {\n", | ||
Enum.map(children, fn(child) -> [do_unquote(child, depth + 1), "\n"] end), | ||
indent(depth), "}" | ||
] | ||
end | ||
|
||
defp do_unquote({type, _, value}, depth) when type in @single_line_constructs do | ||
[indent(depth), to_string(type), " { ", do_unquote(value), " }"] | ||
end | ||
|
||
defp do_unquote({:expression, _, value}), do: value | ||
defp do_unquote({:drug, _, value}), do: ["drug { ", value, " }"] | ||
defp do_unquote(x) when is_list(x), do: x | ||
|
||
defp indent(depth), do: String.duplicate(" ", 2 * depth) | ||
|
||
defp get_with_default(attrs, key) do | ||
case Keyword.get(attrs, key) do | ||
nil -> "" | ||
x -> [" ", x] | ||
end | ||
end | ||
end |
Oops, something went wrong.