2013-11-14 07:00:38 -08:00
|
|
|
package DDG::Goodie::BloodDonor;
|
|
|
|
# ABSTRACT: Returns available donors for a blood type
|
|
|
|
|
|
|
|
use DDG::Goodie;
|
|
|
|
|
2014-06-22 12:13:35 -07:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
triggers startend => 'donor compatibility', 'donor', 'donors for',
|
|
|
|
'blood donor', 'blood donors for', 'blood donor for',
|
|
|
|
'blood type', 'blood compatibility', 'compatibility', 'blood donor compatibility';
|
2014-05-31 07:44:29 -07:00
|
|
|
|
2013-11-14 07:00:38 -08:00
|
|
|
zci answer_type => "blood_donor";
|
|
|
|
|
2014-03-14 23:12:20 -07:00
|
|
|
primary_example_queries 'donor O+';
|
2013-11-14 07:00:38 -08:00
|
|
|
secondary_example_queries 'donor AB+';
|
2014-03-14 23:12:20 -07:00
|
|
|
description 'Donor types for a given blood type';
|
2013-11-14 07:00:38 -08:00
|
|
|
name 'BloodDonor';
|
2014-03-14 23:12:20 -07:00
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/BloodDonor.pm';
|
2013-11-14 07:00:38 -08:00
|
|
|
category 'special';
|
|
|
|
topics 'everyday';
|
|
|
|
attribution github => ['https://github.com/faraday', 'faraday'];
|
|
|
|
|
2014-03-14 23:12:20 -07:00
|
|
|
my %typeMap = (
|
2014-06-22 12:13:35 -07:00
|
|
|
'A' => 'A,O',
|
|
|
|
'O' => 'O',
|
|
|
|
'AB' => 'AB,A,B,O',
|
|
|
|
'B' => 'B,O',
|
2014-03-14 23:12:20 -07:00
|
|
|
);
|
|
|
|
|
2014-06-22 12:13:35 -07:00
|
|
|
sub apply_css($)
|
|
|
|
{
|
|
|
|
my ($html) = @_;
|
|
|
|
my $css = scalar share('style.css')->slurp;
|
|
|
|
return "<style type='text/css'>$css</style>\n$html";
|
|
|
|
}
|
|
|
|
|
2014-03-14 23:12:20 -07:00
|
|
|
sub table_data {
|
2014-06-22 12:13:35 -07:00
|
|
|
my ($label, $value) = @_;
|
|
|
|
return "<tr><td class='label'>$label</td><td class='value'>$value</td></tr>";
|
2014-03-14 23:12:20 -07:00
|
|
|
}
|
2013-11-14 07:00:38 -08:00
|
|
|
|
|
|
|
handle remainder => sub {
|
2014-03-14 23:12:20 -07:00
|
|
|
if ($_ =~ /^(O|A|B|AB)(\-|\+)$/i) {
|
2014-06-22 12:13:35 -07:00
|
|
|
my $type = uc $1;
|
|
|
|
my $rh = $2;
|
2013-11-14 07:00:38 -08:00
|
|
|
|
2014-06-22 12:13:35 -07:00
|
|
|
my @idealResults = ();
|
|
|
|
my @criticalResults = ();
|
2013-11-14 07:00:38 -08:00
|
|
|
|
2014-06-22 12:13:35 -07:00
|
|
|
return unless defined $typeMap{$type};
|
2014-04-16 15:05:44 -07:00
|
|
|
|
2014-06-22 12:13:35 -07:00
|
|
|
# ideally same Rh
|
|
|
|
foreach our $donorType (split(",", $typeMap{$type})) {
|
|
|
|
push(@idealResults, $donorType . $rh);
|
|
|
|
if($rh eq '+') {
|
|
|
|
# only when access to same Rh is impossible
|
|
|
|
push(@criticalResults, $donorType . '-');
|
|
|
|
}
|
|
|
|
}
|
2013-11-14 07:00:38 -08:00
|
|
|
|
2014-06-22 12:13:35 -07:00
|
|
|
my $output = '';
|
|
|
|
my $html = "<table class='blooddonor'>";
|
|
|
|
|
|
|
|
my $idealStr = join(' or ', @idealResults);
|
|
|
|
my $criticalStr = join(' or ', @criticalResults);
|
|
|
|
|
|
|
|
$output .= "Ideal donor: " . uc($_) . "\n";
|
|
|
|
$output .= "Other donors: " . $idealStr . "\n";
|
|
|
|
$html .= table_data("Ideal donor:", uc($_));
|
|
|
|
$html .= table_data("Other donors:", $idealStr);
|
|
|
|
|
|
|
|
if($rh eq '+') {
|
|
|
|
$output .= "Only if no Rh(+) found: " . $criticalStr . "\n";
|
|
|
|
$html .= table_data("<i>Only if</i> no Rh(+) found:", $criticalStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '</table>';
|
|
|
|
return $output, html => apply_css($html), heading => "Donors for blood type ".uc($_);
|
2013-11-14 07:00:38 -08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
1;
|