virgil/commit

Add reaction count to reactions api

authorMichiel Hildebrand
Fri Jul 12 15:53:20 2013 +0200
committerMichiel Hildebrand
Fri Jul 12 15:53:20 2013 +0200
commiteabce22c5829dbbbdb8c2eccff7e69181567ee3c
tree73da50dd7329ef4998d0f02cf8ed1d421db092bc
parent867a729d78cbba86372a0404ce9ed7ada94f1bf7
Diff style: patch stat
diff --git a/api/reactions.pl b/api/reactions.pl
index e121241..7f362f0 100644
--- a/api/reactions.pl
+++ b/api/reactions.pl
@@ -30,7 +30,14 @@ http_reactions(Request) :-
 	list_offset(Reactions, Offset, Reactions_Offset),
 	list_limit(Reactions_Offset, Limit, Reactions_Limit, _),
 	maplist(reaction_obj, Reactions_Limit, Reactions_JSON),
+
+	setof(Report-Reaction,
+		  reaction(DrugNames, [], Reaction, Report),
+		  Rs),
+	length(Rs, ReactionCount),
+
 	reply_json(json([totalNumberOfResults=Total_Reactions,
+			 reaction_count=ReactionCount,
 			 reactions=Reactions_JSON])).
 
 reaction_obj(C-R, json([reaction=R, count=C])).
@@ -67,7 +74,7 @@ http_total_reaction_count(Request) :-
 				  [
 				  ])
 			]),
-	setof(R-Drug, report(Drug, Reaction, [], R), Rs),
-	length(Rs, Count),
+	reaction_count(Reaction, Count),
 	reply_json(json([reaction=Reaction,
 			 reaction_count=Count])).
+
diff --git a/lib/aers_report.pl b/lib/aers_report.pl
index 70ebae8..5e2929f 100644
--- a/lib/aers_report.pl
+++ b/lib/aers_report.pl
@@ -21,7 +21,8 @@ flush_virgil_cache :-
 %%	report(+DrugMentionList, -ReactionTerms, +ReportFilter, -Report)
 
 report(Drugs, Reactions, Filter, Report) :-
-	(   Drugs = [_|_]
+	(   nonvar(Drugs),
+	    Drugs = [_|_]
 	->  report_by_drug(Drugs, Report)
 	;   true
 	),