JpVaccination
It provides data on infant vaccination in Japan. It also processes calculations of recommended and next available dates for vaccination.
These data are based on the vaccination schedule of the National Institute of Infectious Diseases. Currently, only regular and some optional vaccinations in infancy are covered, but in the future all vaccinations will be covered.
Installation
Add this line to your application's Gemfile:
gem 'jp_vaccination'And then execute:
$ bundle install
Or install it yourself as:
$ gem install jp_vaccination
Usage
require 'jp_vaccination'Check vaccination_keys.
You can check the list of vaccination_keys that can be passed as arguments.
JpVaccination.vaccination_keys
pp JpVaccination.vaccination_keys
=> [{ 'ヒブ 1回目' => 'hib_1' },
{ 'ヒブ 2回目' => 'hib_2' },
{ 'ヒブ 3回目' => 'hib_3' },
{ 'ヒブ 4回目' => 'hib_4' },
{ 'B型肝炎 1回目' => 'hepatitis_B_1' },
{ 'B型肝炎 2回目' => 'hepatitis_B_2' },
{ 'B型肝炎 3回目' => 'hepatitis_B_3' },
{ 'ロタウイルス 1回目' => 'rotavirus_1' },
{ 'ロタウイルス 2回目' => 'rotavirus_2' },
{ 'ロタウイルス 3回目' => 'rotavirus_3' },
{ '小児用肺炎球菌 1回目' => 'pneumococcus_1' },
{ '小児用肺炎球菌 2回目' => 'pneumococcus_2' },
{ '小児用肺炎球菌 3回目' => 'pneumococcus_3' },
{ '小児用肺炎球菌 4回目' => 'pneumococcus_4' },
{ '4種混合 第1期 1回目' => 'DPT_IPV_1' },
{ '4種混合 第1期 2回目' => 'DPT_IPV_2' },
{ '4種混合 第1期 3回目' => 'DPT_IPV_3' },
{ '4種混合 第1期 4回目' => 'DPT_IPV_4' },
{ '2種混合 第2期' => 'DT_1' },
{ 'BCG ' => 'BCG_1' },
{ '麻しん・風しん混合 第1期' => 'MR_1' },
{ '麻しん・風しん混合 第2期' => 'MR_2' },
{ '水痘 1回目' => 'chickenpox_1' },
{ '水痘 2回目' => 'chickenpox_2' },
{ 'おたふくかぜ 1回目' => 'mumps_1' },
{ 'おたふくかぜ 2回目' => 'mumps_2' },
{ '日本脳炎 第1期 1回目' => 'Japanese_encephalitis_1' },
{ '日本脳炎 第1期 2回目' => 'Japanese_encephalitis_2' },
{ '日本脳炎 第1期 3回目' => 'Japanese_encephalitis_3' },
{ '日本脳炎 第2期' => 'Japanese_encephalitis_4' }]Access to vaccination data.
Pass the argument as a string for the vaccination_key.
JpVaccination.find(vaccination_key)
chickenpox_1st = JpVaccination.find('chickenpox_1')
chickenpox_1st.name # => "水痘"
chickenpox_1st.period # => "1回目"
chickenpox_1st.regular # => true
chickenpox_1st.type # => "生ワクチン"
chickenpox_1st.recommended # => {:month=>12}
chickenpox_1st.deadline # => {:date_type=>"month", :start=>12, :end=>15, :less_than=>true}
chickenpox_1st.interval # => nil
# name + period
chickenpox_1st.formal_name # => "水痘 1回目"Example data.
| column | data | example | title |
|---|---|---|---|
| name | String | "水痘" | 予防接種名 |
| period | String | "2回目" | 期間 |
| regular | true/false | true | 定期/任意 |
| type1 | String | "生ワクチン" | 種類 |
| recommended | Hash | { month: 18 } | 推奨接種月齢 |
| deadline2 | Hash | { date_type: "month", start: 15, end: 36, less_than: true } |
接種期日 |
| interval2 | Hash | { date_type: "month", start: 3, end: 12 } |
接種間隔 |
Calculate all recommended dates of vaccination
JpVaccination.recommended_days(birthday, convert_to_strings)
default convert_to_string: nil
birthday = '2022-03-01'
pp JpVaccination.recommended_days(birthday, convert_to_strings = true)
# default convert_to_string: nil
=> [{:name=>"ヒブ 1回目", :date=>"2022-05-01"},
{:name=>"ヒブ 2回目", :date=>"2022-06-01"},
{:name=>"ヒブ 3回目", :date=>"2022-07-01"},
{:name=>"ヒブ 4回目", :date=>"2023-03-01"},
{:name=>"B型肝炎 1回目", :date=>"2022-05-01"},
{:name=>"B型肝炎 2回目", :date=>"2022-06-01"},
{:name=>"B型肝炎 3回目", :date=>"2022-10-01"},
{:name=>"ロタウイルス 1回目", :date=>"2022-05-01"},
{:name=>"ロタウイルス 2回目", :date=>"2022-06-01"},
{:name=>"ロタウイルス 3回目", :date=>"2022-07-01"},
{:name=>"小児用肺炎球菌 1回目", :date=>"2022-05-01"},
{:name=>"小児用肺炎球菌 2回目", :date=>"2022-06-01"},
{:name=>"小児用肺炎球菌 3回目", :date=>"2022-07-01"},
{:name=>"小児用肺炎球菌 4回目", :date=>"2023-03-01"},
{:name=>"4種混合 第1期 1回目", :date=>"2022-06-01"},
{:name=>"4種混合 第1期 2回目", :date=>"2022-07-01"},
{:name=>"4種混合 第1期 3回目", :date=>"2022-08-01"},
{:name=>"4種混合 第1期 4回目", :date=>"2023-03-01"},
{:name=>"2種混合 第2期", :date=>"2033-03-01"},
{:name=>"BCG ", :date=>"2022-08-01"},
{:name=>"麻しん・風しん混合 第1期", :date=>"2023-03-01"},
{:name=>"麻しん・風しん混合 第2期", :date=>"2027-04-01〜2028-04-01"},
{:name=>"水痘 1回目", :date=>"2023-03-01"},
{:name=>"水痘 2回目", :date=>"2023-09-01"},
{:name=>"おたふくかぜ 1回目", :date=>"2023-03-01"},
{:name=>"おたふくかぜ 2回目", :date=>"2027-04-01〜2028-04-01"},
{:name=>"日本脳炎 第1期 1回目", :date=>"2025-03-01"},
{:name=>"日本脳炎 第1期 2回目", :date=>"2025-04-01"},
{:name=>"日本脳炎 第1期 3回目", :date=>"2026-03-01"},
{:name=>"日本脳炎 第2期", :date=>"2031-03-01"}]Sort recommended vaccination dates in ascending order
JpVaccination.recommended_schedules(birthday, convert_to_strings = nil)
You can turn Date into String by setting convert_to_strings to true
birthday = '2022-03-01'
pp JpVaccination.recommended_schedules(birthday, convert_to_strings = true)
# default convert_to_string: nil
=> {"2022-05-01"=>["ヒブ 1回目", "ロタウイルス 1回目", "小児用肺炎球菌 1回目", "B型肝炎 1回目"],
"2022-06-01"=>["ヒブ 2回目", "ロタウイルス 2回目", "小児用肺炎球菌 2回目", "4種混合 第1期 1回目", "B型肝炎 2回目"],
"2022-07-01"=>["ヒブ 3回目", "ロタウイルス 3回目", "小児用肺炎球菌 3回目", "4種混合 第1期 2回目"],
"2022-08-01"=>["4種混合 第1期 3回目", "BCG "],
"2022-10-01"=>["B型肝炎 3回目"],
"2023-03-01"=>["おたふくかぜ 1回目", "ヒブ 4回目", "小児用肺炎球菌 4回目", "水痘 1回目", "麻しん・風しん混合 第1期", "4種混合 第1期 4回目"],
"2023-09-01"=>["水痘 2回目"],
"2025-03-01"=>["日本脳炎 第1期 1回目"],
"2025-04-01"=>["日本脳炎 第1期 2回目"],
"2026-03-01"=>["日本脳炎 第1期 3回目"],
"2027-04-01〜2028-03-31"=>["おたふくかぜ 2回目", "麻しん・風しん混合 第2期"],
"2031-03-01"=>["日本脳炎 第2期"],
"2033-03-01"=>["2種混合 第2期"]}JpVaccination.recommended_schedules(birthday, nil) or
JpVaccination.recommended_schedules(birthday)
pp JpVaccination.recommended_schedules('2022-03-01')
=> {#<Date: 2022-05-01 ((2459701j,0s,0n),+0s,2299161j)>=>["小児用肺炎球菌 1回目", "ヒブ 1回目", "ロタウイルス 1回目", "B型肝炎 1回目"],…Calculate the next available vaccination date from the date of the previous vaccination.
JpVaccination.next_day(vaccination_key, last_time)
pp JpVaccination.next_day('hepatitis_B_2', '2020-04-01')
=> {:name=>"B型肝炎 2回目", :date=>#<Date: 2020-04-28 ((2458968j,0s,0n),+0s,2299161j)>}If you want to find the date of the first vaccination, in short, the last character of the vaccination_key is 1, enter the date of birth in last_time.
JpVaccination.next_day(vaccination_1, birthday)
birthday = '2022-02-01'
pp JpVaccination.next_day('hepatitis_B_1', birthday)
=> {:name=>"B型肝炎 1回目", :date=>#<Date: 2022-04-01 ((2458968j,0s,0n),+0s,2299161j)>}Argument Error
If the vaccination_key is incorrect, the following error occurs.
# hepatitis_B_4 is incorrect.
puts JpVaccination.next_day(vaccination_key: 'hepatitis_B_4', last_time: '2020-04-01')
# error
jp_vaccination/lib/jp_vaccination.rb:99:in `output_argument_error': The vaccination_key 'hepatitis_B_4' doesn't exist. (ArgumentError)
About vaccination_key
The key formation is (vaccination's English translation)_(period-number).
Each vaccination and corresponding key is as follows.
| vaccination_key | name | period |
|---|---|---|
| hib_1 | ヒブ | 1回目 |
| hib_2 | ヒブ | 2回目 |
| hib_3 | ヒブ | 3回目 |
| hib_4 | ヒブ | 4回目 |
| hepatitis_B_1 | B型肝炎 | 1回目 |
| hepatitis_B_2 | B型肝炎 | 2回目 |
| hepatitis_B_3 | B型肝炎 | 3回目 |
| rotavirus_1 | ロタウイルス | 1回目 |
| rotavirus_2 | ロタウイルス | 2回目 |
| rotavirus_3 | ロタウイルス | 3回目 |
| pneumococcus_1 | 小児用肺炎球菌 | 1回目 |
| pneumococcus_2 | 小児用肺炎球菌 | 2回目 |
| pneumococcus_3 | 小児用肺炎球菌 | 3回目 |
| pneumococcus_4 | 小児用肺炎球菌 | 4回目 |
| DPT_IPV_1 | 4種混合 | 第1期 1回目 |
| DPT_IPV_2 | 4種混合 | 第1期 2回目 |
| DPT_IPV_3 | 4種混合 | 第1期 3回目 |
| DPT_IPV_4 | 4種混合 | 第2期 |
| DT_1 | 2種混合 | 第2期 |
| BCG_1 | BCG | - |
| MR_1 | 麻しん・風しん混合 | 第1期 |
| MR_2 | 麻しん・風しん混合 | 第2期 |
| chickenpox_1 | 水痘 | 1回目 |
| chickenpox_2 | 水痘 | 2回目 |
| mumps_1 | おたふくかぜ | 1回目 |
| mumps_2 | おたふくかぜ | 2回目 |
| Japanese_encephalitis_1 | 日本脳炎 | 第1期 1回目 |
| Japanese_encephalitis_2 | 日本脳炎 | 第1期 2回目 |
| Japanese_encephalitis_3 | 日本脳炎 | 第1期 3回目 |
| Japanese_encephalitis_4 | 日本脳炎 | 第2期 |
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/napple29/jp_vaccination. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the JpVaccination project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Footnotes
-
nil except for live vaccines.↩ -
5~36 months:{date_type:"month",start:15,end:36},
less_than:trueis less than.less_than:falseis below. ↩ ↩2