2013-11-14 07:00:38 -08:00
|
|
|
package DDG::Goodie::BloodDonor;
|
|
|
|
# ABSTRACT: Returns available donors for a blood type
|
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
2013-11-14 07:00:38 -08:00
|
|
|
use DDG::Goodie;
|
|
|
|
|
2014-06-22 12:13:35 -07:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2014-10-28 11:36:15 -07:00
|
|
|
triggers startend => 'donor compatibility', 'donor', 'donors for',
|
2014-06-22 12:13:35 -07:00
|
|
|
'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-09-27 06:42:57 -07:00
|
|
|
zci is_cached => 1;
|
2013-11-14 07:00:38 -08:00
|
|
|
|
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
|
|
|
);
|
|
|
|
|
2013-11-14 07:00:38 -08:00
|
|
|
handle remainder => sub {
|
2015-07-08 15:17:35 -07:00
|
|
|
|
|
|
|
return unless ($_ =~ /^(O|A|B|AB)(\-|\+)$/i);
|
2013-11-14 07:00:38 -08:00
|
|
|
|
2015-07-08 15:17:35 -07:00
|
|
|
my $type = uc $1;
|
|
|
|
my $rh = $2;
|
2013-11-14 07:00:38 -08:00
|
|
|
|
2015-07-08 15:17:35 -07:00
|
|
|
my @idealResults = ();
|
|
|
|
my @criticalResults = ();
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2015-07-08 15:17:35 -07:00
|
|
|
return unless defined $typeMap{$type};
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2015-07-08 15:17:35 -07:00
|
|
|
# ideally same Rh
|
|
|
|
foreach our $donorType (split(",", $typeMap{$type})) {
|
|
|
|
push(@idealResults, $donorType . $rh);
|
2014-06-22 12:13:35 -07:00
|
|
|
if($rh eq '+') {
|
2015-07-08 15:17:35 -07:00
|
|
|
# only when access to same Rh is impossible
|
|
|
|
push(@criticalResults, $donorType . '-');
|
2014-06-22 12:13:35 -07:00
|
|
|
}
|
2013-11-14 07:00:38 -08:00
|
|
|
}
|
2015-07-08 15:17:35 -07:00
|
|
|
|
|
|
|
my $idealStr = join(' or ', @idealResults);
|
|
|
|
my $criticalStr = join(' or ', @criticalResults);
|
|
|
|
|
|
|
|
my %record_data = (
|
|
|
|
"Ideal donor" => uc($_),
|
|
|
|
"Other donors" => $idealStr,
|
|
|
|
);
|
|
|
|
my @record_keys = ("Ideal donor", "Other donors");
|
|
|
|
|
|
|
|
if($rh eq '+') {
|
|
|
|
push @record_keys,"Only if no Rh(+) found";
|
|
|
|
$record_data{"Only if no Rh(+) found"} = $criticalStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub to_text
|
2015-07-09 22:32:14 -07:00
|
|
|
{
|
|
|
|
my ($data, $keys) = @_;
|
|
|
|
return join "\n", map {"$_: $data->{$_}";} @{$keys};
|
|
|
|
}
|
2015-07-08 15:17:35 -07:00
|
|
|
|
|
|
|
return to_text(\%record_data, \@record_keys), structured_answer => {
|
2015-07-11 02:02:59 -07:00
|
|
|
id => 'blood_donor',
|
|
|
|
name => 'Blood Donors',
|
2015-07-08 15:17:35 -07:00
|
|
|
description => 'Returns available donors for a blood type',
|
2015-07-11 02:02:59 -07:00
|
|
|
meta => {
|
|
|
|
sourceName => 'Wikipedia',
|
|
|
|
sourceUrl => 'https://en.wikipedia.org/wiki/Blood_type',
|
|
|
|
},
|
2015-07-08 15:17:35 -07:00
|
|
|
templates => {
|
|
|
|
group => 'list',
|
|
|
|
options => {
|
|
|
|
content => 'record'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data => {
|
|
|
|
title => "Donors for blood type ".uc($_),
|
|
|
|
record_data => \%record_data,
|
|
|
|
record_keys => \@record_keys
|
|
|
|
}
|
|
|
|
};
|
2013-11-14 07:00:38 -08:00
|
|
|
};
|
2014-08-26 12:32:09 -07:00
|
|
|
1;
|