lib/MGH_Biostat/TravEpi/SimpleRulesBase/Countries.pm


package MGH_Biostat::TravEpi::SimpleRulesBase::Countries;
use Modern::Perl '2012';
use experimental 'switch';
use Set::Tiny 'set';
no autovivification;

# @TODO look into making this a constant or readonly
our $countries = _load_country_map();

# returns a set of the legitimate countries
sub valid_countries {
    state $keys_set = set( keys %$countries );
    return $keys_set;
}

# returns a set containing the mapped countries
sub mapped_countries {
    my $orig;
    given ( ref( $_[ 0 ] ) ) {
        when ('Set::Tiny') { $orig = shift; }
        when ('ARRAY')     { $orig = set(shift); }
        default            { $orig = set(@_); }
    }
    return set(
        map    { $countries->{$_}; }
          grep { defined( $countries->{$_} ) }
          $orig->elements()
    );
}

# country list
sub _load_country_map {
    return {
        'afghanistan'                          => 'afghanistan',
        'albania'                              => 'albania',
        'algeria'                              => 'algeria',
        'american-samoa'                       => 'american-samoa',
        'andorra'                              => 'andorra',
        'anegada'                              => 'british-virgin-islands',
        'angola'                               => 'angola',
        'anguilla'                             => 'anguilla',
        'antarctica'                           => 'antarctica',
        'antigua-and-barbuda'                  => 'antigua-and-barbuda',
        'argentina'                            => 'argentina',
        'armenia'                              => 'armenia',
        'aruba'                                => 'aruba',
        'austral-islands'                      => 'french-polynesia',
        'australia'                            => 'australia',
        'austria'                              => 'austria',
        'azerbaijan'                           => 'azerbaijan',
        'azores'                               => 'azores',
        'bahrain'                              => 'bahrain',
        'bangladesh'                           => 'bangladesh',
        'barbados'                             => 'barbados',
        'barbuda'                              => 'antigua-and-barbuda',
        'belarus'                              => 'belarus',
        'belgium'                              => 'belgium',
        'belize'                               => 'belize',
        'benin'                                => 'benin',
        'bermuda'                              => 'bermuda',
        'bhutan'                               => 'bhutan',
        'bolivia'                              => 'bolivia',
        'bonaire'                              => 'bonaire',
        'bora-bora'                            => 'french-polynesia',
        'bosnia-and-herzegovina'               => 'bosnia-and-herzegovina',
        'botswana'                             => 'botswana',
        'brazil'                               => 'brazil',
        'british-indian-ocean-territory'       => 'british-indian-ocean-territory',
        'british-virgin-islands'               => 'british-virgin-islands',
        'brunei'                               => 'brunei',
        'bulgaria'                             => 'bulgaria',
        'burkina-faso'                         => 'burkina-faso',
        'burma'                                => 'burma',
        'burundi'                              => 'burundi',
        'caicos-islands'                       => 'turks-and-caicos',
        'cambodia'                             => 'cambodia',
        'cameroon'                             => 'cameroon',
        'canada'                               => 'canada',
        'canary-islands'                       => 'canary-islands',
        'cape-verde'                           => 'cape-verde',
        'cayman-islands'                       => 'cayman-islands',
        'central-african-republic'             => 'central-african-republic',
        'chad'                                 => 'chad',
        'chile'                                => 'chile',
        'china'                                => 'china',
        'christmas-island'                     => 'christmas-island',
        'cocos-islands'                        => 'cocos-islands',
        'colombia'                             => 'colombia',
        'comoros'                              => 'comoros',
        'congo'                                => 'congo',
        'cook-islands'                         => 'cook-islands',
        'costa-rica'                           => 'costa-rica',
        'croatia'                              => 'croatia',
        'cuba'                                 => 'cuba',
        'curacao'                              => 'curacao',
        'cyprus'                               => 'cyprus',
        'czech-republic'                       => 'czech-republic',
        'democratic-republic-of-congo'         => 'democratic-republic-of-congo',
        'denmark'                              => 'denmark',
        'djibouti'                             => 'djibouti',
        'dominica'                             => 'dominica',
        'dominican-republic'                   => 'dominican-republic',
        'dubai'                                => 'united-arab-emirates',
        'east-timor'                           => 'east-timor',
        'easter-island'                        => 'easter-island',
        'ecuador'                              => 'ecuador',
        'egypt'                                => 'egypt',
        'el-salvador'                          => 'el-salvador',
        'england'                              => 'united-kingdom',
        'equatorial-guinea'                    => 'equatorial-guinea',
        'eritrea'                              => 'eritrea',
        'estonia'                              => 'estonia',
        'ethiopia'                             => 'ethiopia',
        'falkland-islands'                     => 'falkland-islands',
        'faroe-island'                         => 'faroe-island',
        'fiji'                                 => 'fiji',
        'finland'                              => 'finland',
        'france'                               => 'france',
        'french-guiana'                        => 'french-guiana',
        'french-polynesia'                     => 'french-polynesia',
        'gabon'                                => 'gabon',
        'galapagos-islands'                    => 'ecuador',
        'georgia'                              => 'georgia',
        'germany'                              => 'germany',
        'ghana'                                => 'ghana',
        'gibraltar'                            => 'gibraltar',
        'greece'                               => 'greece',
        'greenland'                            => 'greenland',
        'grenada'                              => 'grenada',
        'grenadines'                           => 'saint-vincent-and-the-grenadines',
        'guadeloupe'                           => 'guadeloupe',
        'guam'                                 => 'guam',
        'guatemala'                            => 'guatemala',
        'guernsey'                             => 'united-kingdom',
        'guinea-bissau'                        => 'guinea-bissau',
        'guinea'                               => 'guinea',
        'guyana'                               => 'guyana',
        'haiti'                                => 'haiti',
        'holy-see'                             => 'italy',
        'honduras'                             => 'honduras',
        'hong-kong-sar'                        => 'hong-kong-sar',
        'hungary'                              => 'hungary',
        'iceland'                              => 'iceland',
        'india'                                => 'india',
        'indonesia'                            => 'indonesia',
        'iran'                                 => 'iran',
        'iraq'                                 => 'iraq',
        'ireland'                              => 'ireland',
        'isle-of-man'                          => 'united-kingdom',
        'israel'                               => 'israel',
        'italy'                                => 'italy',
        'ivory-coast'                          => 'ivory-coast',
        'jamaica'                              => 'jamaica',
        'japan'                                => 'japan',
        'jersey'                               => 'united-kingdom',
        'jordan'                               => 'jordan',
        'jost-van-dyke'                        => 'british-virgin-islands',
        'kazakhstan'                           => 'kazakhstan',
        'kenya'                                => 'kenya',
        'kiribati'                             => 'kiribati',
        'kosovo'                               => 'kosovo',
        'kuwait'                               => 'kuwait',
        'kyrgyzstan'                           => 'kyrgyzstan',
        'laos'                                 => 'laos',
        'latvia'                               => 'latvia',
        'lebanon'                              => 'lebanon',
        'lesotho'                              => 'lesotho',
        'liberia'                              => 'liberia',
        'libya'                                => 'libya',
        'liechtenstein'                        => 'liechtenstein',
        'lithuania'                            => 'lithuania',
        'luxembourg'                           => 'luxembourg',
        'macau-sar'                            => 'macau-sar',
        'macedonia'                            => 'macedonia',
        'madagascar'                           => 'madagascar',
        'maderia-islands'                      => 'maderia-islands',
        'malawi'                               => 'malawi',
        'malaysia'                             => 'malaysia',
        'maldives'                             => 'maldives',
        'mali'                                 => 'mali',
        'malta'                                => 'malta',
        'marquesas-islands'                    => 'french-polynesia',
        'marshall-islands'                     => 'marshall-islands',
        'martinique'                           => 'martinique',
        'mauritania'                           => 'mauritania',
        'mauritius'                            => 'mauritius',
        'mayotte'                              => 'mayotte',
        'mexico'                               => 'mexico',
        'micronesia'                           => 'micronesia',
        'moldova'                              => 'moldova',
        'monaco'                               => 'monaco',
        'mongolia'                             => 'mongolia',
        'montenegro'                           => 'montenegro',
        'montserrat'                           => 'montserrat',
        'moorea'                               => 'french-polynesia',
        'morocco'                              => 'morocco',
        'mozambique'                           => 'mozambique',
        'namibia'                              => 'namibia',
        'nauru'                                => 'nauru',
        'nepal'                                => 'nepal',
        'netherlands'                          => 'netherlands',
        'new-caledonia'                        => 'new-caledonia',
        'new-zealand'                          => 'new-zealand',
        'nicaragua'                            => 'nicaragua',
        'niger'                                => 'niger',
        'nigeria'                              => 'nigeria',
        'niue'                                 => 'niue',
        'norfolk-island'                       => 'norfolk-island',
        'north-korea'                          => 'north-korea',
        'northern-ireland'                     => 'united-kingdom',
        'northern-mariana-islands'             => 'northern-mariana-islands',
        'norway'                               => 'norway',
        'oman'                                 => 'oman',
        'pakistan'                             => 'pakistan',
        'palau'                                => 'palau',
        'panama'                               => 'panama',
        'papua-new-guinea'                     => 'papua-new-guinea',
        'paraguay'                             => 'paraguay',
        'peru'                                 => 'peru',
        'philippines'                          => 'philippines',
        'pitcairn-islands'                     => 'pitcairn-islands',
        'poland'                               => 'poland',
        'portugal'                             => 'portugal',
        'puerto-rico'                          => 'puerto-rico',
        'qatar'                                => 'qatar',
        'reunion'                              => 'reunion',
        'romania'                              => 'romania',
        'rota'                                 => 'northern-mariana-islands',
        'rurutu'                               => 'french-polynesia',
        'russia'                               => 'russia',
        'rwanda'                               => 'rwanda',
        'saba'                                 => 'saba',
        'saint-barthelemy'                     => 'saint-barthelemy',
        'saint-croix'                          => 'usvirgin-islands',
        'saint-helena'                         => 'saint-helena',
        'saint-john'                           => 'usvirgin-islands',
        'saint-lucia'                          => 'saint-lucia',
        'saint-martin'                         => 'saint-martin',
        'saint-pierre-and-miquelon'            => 'saint-pierre-and-miquelon',
        'saint-thomas'                         => 'usvirgin-islands',
        'saint-vincent-and-the-grenadines'     => 'saint-vincent-and-the-grenadines',
        'saipan'                               => 'northern-mariana-islands',
        'samoa'                                => 'samoa',
        'san-marino'                           => 'san-marino',
        'sao-tome-and-principe'                => 'sao-tome-and-principe',
        'saudi-arabia'                         => 'saudi-arabia',
        'scotland'                             => 'united-kingdom',
        'senegal'                              => 'senegal',
        'serbia'                               => 'serbia',
        'seychelles'                           => 'seychelles',
        'sierra-leone'                         => 'sierra-leone',
        'singapore'                            => 'singapore',
        'sint-eustatius'                       => 'sint-eustatius',
        'sint-maarten'                         => 'sint-maarten',
        'slovakia'                             => 'slovakia',
        'slovenia'                             => 'slovenia',
        'society-islands'                      => 'french-polynesia',
        'solomon-islands'                      => 'solomon-islands',
        'somalia'                              => 'somalia',
        'south-africa'                         => 'south-africa',
        'south-georgia-south-sandwich-islands' => 'south-georgia-south-sandwich-islands',
        'south-korea'                          => 'south-korea',
        'south-sandwich-islands'               => 'south-georgia-south-sandwich-islands',
        'south-sudan'                          => 'south-sudan',
        'spain'                                => 'spain',
        'sri-lanka'                            => 'sri-lanka',
        'st-kitts-and-nevis'                   => 'st-kitts-and-nevis',
        'sudan'                                => 'sudan',
        'suriname'                             => 'suriname',
        'swaziland'                            => 'swaziland',
        'sweden'                               => 'sweden',
        'switzerland'                          => 'switzerland',
        'syria'                                => 'syria',
        'tahiti'                               => 'french-polynesia',
        'taiwan'                               => 'taiwan',
        'tajikistan'                           => 'tajikistan',
        'tanzania'                             => 'tanzania',
        'thailand'                             => 'thailand',
        'the-bahamas'                          => 'the-bahamas',
        'the-gambia'                           => 'the-gambia',
        'tinian'                               => 'northern-mariana-islands',
        'tobago'                               => 'trinidad-and-tobago',
        'togo'                                 => 'togo',
        'tokelau'                              => 'tokelau',
        'tonga'                                => 'tonga',
        'tortola'                              => 'british-virgin-islands',
        'trinidad-and-tobago'                  => 'trinidad-and-tobago',
        'tubuai'                               => 'french-polynesia',
        'tunisia'                              => 'tunisia',
        'turkey'                               => 'turkey',
        'turkmenistan'                         => 'turkmenistan',
        'turks-and-caicos'                     => 'turks-and-caicos',
        'tuvalu'                               => 'tuvalu',
        'uganda'                               => 'uganda',
        'ukraine'                              => 'ukraine',
        'united-arab-emirates'                 => 'united-arab-emirates',
        'united-kingdom'                       => 'united-kingdom',
        'united-states'                        => 'united-states',
        'uruguay'                              => 'uruguay',
        'usvirgin-islands'                     => 'usvirgin-islands',
        'uzbekistan'                           => 'uzbekistan',
        'vanuatu'                              => 'vanuatu',
        'vatican-city'                         => 'italy',
        'venezuela'                            => 'venezuela',
        'vietnam'                              => 'vietnam',
        'virgin-gorda'                         => 'british-virgin-islands',
        'wake-island'                          => 'wake-island',
        'wales'                                => 'united-kingdom',
        'western-sahara'                       => 'western-sahara',
        'yemen'                                => 'yemen',
        'zambia'                               => 'zambia',
        'zanzibar'                             => 'tanzania',
        'zimbabwe'                             => 'zimbabwe',
    };
}

1;