yahl7 0.1.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +47 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +27 -0
- data/.github/dependabot.yml +7 -0
- data/CHANGELOG.md +64 -0
- data/CODE_OF_CONDUCT.md +74 -25
- data/CONTRIBUTING.md +47 -0
- data/README.md +19 -3
- data/lib/yahl7/v2/{segment_field_names.rb → alias_field_names.rb} +14 -7
- data/lib/yahl7/v2/alias_person_name.rb +65 -0
- data/lib/yahl7/v2/data_type/cnn.rb +29 -0
- data/lib/yahl7/v2/data_type/dt.rb +28 -0
- data/lib/yahl7/v2/data_type/ft.rb +26 -0
- data/lib/yahl7/v2/data_type/ndl.rb +30 -0
- data/lib/yahl7/v2/data_type/ts.rb +24 -0
- data/lib/yahl7/v2/data_type/xad.rb +31 -0
- data/lib/yahl7/v2/data_type/xpn.rb +40 -0
- data/lib/yahl7/v2/data_type/xtn.rb +29 -0
- data/lib/yahl7/v2/data_type.rb +20 -0
- data/lib/yahl7/v2/date_time.rb +1 -1
- data/lib/yahl7/v2/error/invalid_format_error.rb +12 -0
- data/lib/yahl7/v2/message/adt.rb +2 -0
- data/lib/yahl7/v2/message/oru.rb +1 -0
- data/lib/yahl7/v2/message.rb +10 -0
- data/lib/yahl7/v2/segment/al1.rb +21 -0
- data/lib/yahl7/v2/segment/dg1.rb +36 -0
- data/lib/yahl7/v2/segment/evn.rb +23 -0
- data/lib/yahl7/v2/segment/in1.rb +68 -0
- data/lib/yahl7/v2/segment/msh.rb +4 -2
- data/lib/yahl7/v2/segment/nte.rb +3 -2
- data/lib/yahl7/v2/segment/obr.rb +13 -12
- data/lib/yahl7/v2/segment/obx.rb +11 -5
- data/lib/yahl7/v2/segment/orc.rb +8 -7
- data/lib/yahl7/v2/segment/pd1.rb +36 -0
- data/lib/yahl7/v2/segment/pid.rb +11 -10
- data/lib/yahl7/v2/segment/pv1.rb +7 -6
- data/lib/yahl7/v2.rb +6 -1
- data/lib/yahl7/version.rb +1 -1
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef377a8697c788223e781fce4c91d1885ed32b1e3445f918d2e9cbe2871080ba
|
4
|
+
data.tar.gz: 3dbb403452617207d14c78f446d4eea3db98dad27c2768bd8918a2ef2125be13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72961481942d814ce6c3719106b4daa74534f68115a1fd2ab5b953f08b1860d2f9d82529183e1924919f7980078c8407f066d3395e7d947782ad2d2c60a30d34
|
7
|
+
data.tar.gz: 61a0ad074ae8814f61b87e3a890d67ae11fda0b531b4e51d49b58bb24235563e15f6b67d907f25a371dba1bf2d300e15748d7fd98a52cd916d032c61ecceb86d
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Have you read our Code of Conduct? By filing an Issue, you are expected to comply with it, including treating everyone with respect: https://github.com/mylanconnolly/yahl7/blob/main/CODE_OF_CONDUCT.md
|
10
|
+
|
11
|
+
-->
|
12
|
+
|
13
|
+
### Prerequisites
|
14
|
+
|
15
|
+
* [ ] Put an X between the brackets on this line if you have done all of the following:
|
16
|
+
* Checked for a known issue here: <https://github.com/mylanconnolly/yahl7/blob/main/ERRATA.md>
|
17
|
+
* Checked that your issue isn't already filed: <https://github.com/mylanconnolly/yahl7/issues>
|
18
|
+
|
19
|
+
### Description
|
20
|
+
|
21
|
+
<!-- Description of the issue -->
|
22
|
+
|
23
|
+
### Steps to Reproduce
|
24
|
+
|
25
|
+
1. <!-- First Step -->
|
26
|
+
2. <!-- Second Step -->
|
27
|
+
3. <!-- and so on… -->
|
28
|
+
|
29
|
+
**Expected behavior:**
|
30
|
+
|
31
|
+
<!-- What you expect to happen -->
|
32
|
+
|
33
|
+
**Actual behavior:**
|
34
|
+
|
35
|
+
<!-- What actually happens -->
|
36
|
+
|
37
|
+
**Reproduces how often:**
|
38
|
+
|
39
|
+
<!-- What percentage of the time does it reproduce? -->
|
40
|
+
|
41
|
+
### Versions
|
42
|
+
|
43
|
+
<!-- Which version of the gem are you using? -->
|
44
|
+
|
45
|
+
### Additional Information
|
46
|
+
|
47
|
+
<!-- Any additional information, configuration or data that might be necessary to reproduce the issue. -->
|
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Have you read our Code of Conduct? By filing an Issue, you are expected to comply with it, including treating everyone with respect: https://github.com/mylanconnolly/yahl7/blob/main/CODE_OF_CONDUCT.md
|
10
|
+
|
11
|
+
-->
|
12
|
+
|
13
|
+
## Summary
|
14
|
+
|
15
|
+
<!-- One paragraph explanation of the feature. -->
|
16
|
+
|
17
|
+
## Motivation
|
18
|
+
|
19
|
+
<!-- Why are we doing this? What use cases does it support? What is the expected outcome? -->
|
20
|
+
|
21
|
+
## Describe alternatives you've considered
|
22
|
+
|
23
|
+
<!-- A clear and concise description of the alternative solutions you've considered. Be sure to explain why the existing functionality isn't suitable for this feature. -->
|
24
|
+
|
25
|
+
## Additional context
|
26
|
+
|
27
|
+
<!-- Add any other context or information about the feature request here. -->
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,70 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.3.2] - 2021-09-01
|
9
|
+
|
10
|
+
0.3.1 introduced a bug that is fixed in this release.
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
|
14
|
+
- A bug in 0.3.1. We should have returned `YAHL7::V2::Message` but `nil` was
|
15
|
+
returned instead, resulting in an inconsistent API. This release fixed that
|
16
|
+
behavior and makes the API consistent again.
|
17
|
+
|
18
|
+
## [0.3.1] - 2021-09-01
|
19
|
+
|
20
|
+
This release fixes a bug under certain circumstances. More details are listed
|
21
|
+
below.
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
|
25
|
+
- A bug that could be encountered where messages that do not contain a message
|
26
|
+
type field caused a crash. This crash should now be fixed. When calling
|
27
|
+
`YAHL7::V2::Message.message_type` on a message body that does not contain the
|
28
|
+
type field, `nil` should now be returned rather than crashing.
|
29
|
+
|
30
|
+
## [0.3.0] - 2021-08-31
|
31
|
+
|
32
|
+
The most significant part of this release is the addition of HL7 data types,
|
33
|
+
which should allow us to access data within the messages in a much more
|
34
|
+
convenient fashion.
|
35
|
+
|
36
|
+
### Added
|
37
|
+
|
38
|
+
- `YAHL7::V2::Error::InvalidFormatError` error class for when invalid input was
|
39
|
+
encountered during parsing.
|
40
|
+
- HL7 segments:
|
41
|
+
- `AL1` for patient allergy information
|
42
|
+
- `DG1` for patient diagnosis information
|
43
|
+
- `EVN` to describe event triggers
|
44
|
+
- HL7 data types:
|
45
|
+
- `CNN` for composite ID number and name fields
|
46
|
+
- `DT` for dates
|
47
|
+
- `FT` for formatted text
|
48
|
+
- `NDL` for name, date, and location
|
49
|
+
- `TS` for timestamps
|
50
|
+
- `XAD` for extended addresses
|
51
|
+
- `XPN` for extended person names
|
52
|
+
- `XTN` for extended telephone numbers
|
53
|
+
|
54
|
+
### Changed
|
55
|
+
|
56
|
+
- `DateTime::parse` now raises `YAHL7::V2::Error::InvalidFormatError` on an
|
57
|
+
unknown format rather than the default `RuntimeError`.
|
58
|
+
- Rename `YAHL7::V2::SegmentFieldNames` to `YAHL7::V2::AliasFieldNames` because
|
59
|
+
it is useful in custom data types as well as segments.
|
60
|
+
- Map created HL7 data types to applicable fields in segments.
|
61
|
+
|
62
|
+
## [0.2.0] - 2021-08-31
|
63
|
+
|
64
|
+
### Added
|
65
|
+
|
66
|
+
- `YAHL7::V2::Message` now has a `#to_s` method, which returns the original HL7
|
67
|
+
message string. Useful for persisting the original message somewhere after
|
68
|
+
processing
|
69
|
+
- `IN1` segment type
|
70
|
+
- `PD1` segment type
|
71
|
+
|
8
72
|
## [0.1.0] - 2021-08-31
|
9
73
|
|
10
74
|
Initial release
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,20 +1,30 @@
|
|
1
|
+
|
1
2
|
# Contributor Covenant Code of Conduct
|
2
3
|
|
3
4
|
## Our Pledge
|
4
5
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
We as members, contributors, and leaders pledge to make participation in our
|
7
|
+
community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
9
|
+
identity and expression, level of experience, education, socio-economic status,
|
10
|
+
nationality, personal appearance, race, caste, color, religion, or sexual identity
|
11
|
+
and orientation.
|
6
12
|
|
7
|
-
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
14
|
+
diverse, inclusive, and healthy community.
|
8
15
|
|
9
16
|
## Our Standards
|
10
17
|
|
11
|
-
Examples of behavior that contributes to a positive environment for our
|
18
|
+
Examples of behavior that contributes to a positive environment for our
|
19
|
+
community include:
|
12
20
|
|
13
21
|
* Demonstrating empathy and kindness toward other people
|
14
22
|
* Being respectful of differing opinions, viewpoints, and experiences
|
15
23
|
* Giving and gracefully accepting constructive feedback
|
16
|
-
* Accepting responsibility and apologizing to those affected by our mistakes,
|
17
|
-
|
24
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
25
|
+
and learning from the experience
|
26
|
+
* Focusing on what is best not just for us as individuals, but for the
|
27
|
+
overall community
|
18
28
|
|
19
29
|
Examples of unacceptable behavior include:
|
20
30
|
|
@@ -29,56 +39,95 @@ Examples of unacceptable behavior include:
|
|
29
39
|
|
30
40
|
## Enforcement Responsibilities
|
31
41
|
|
32
|
-
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
43
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
44
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
45
|
+
or harmful.
|
33
46
|
|
34
|
-
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
48
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
49
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
50
|
+
decisions when appropriate.
|
35
51
|
|
36
52
|
## Scope
|
37
53
|
|
38
|
-
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
55
|
+
an individual is officially representing the community in public spaces.
|
56
|
+
Examples of representing our community include using an official e-mail address,
|
57
|
+
posting via an official social media account, or acting as an appointed
|
58
|
+
representative at an online or offline event.
|
39
59
|
|
40
60
|
## Enforcement
|
41
61
|
|
42
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
63
|
+
reported to the community leaders responsible for enforcement at
|
64
|
+
mylan@mylan.io. All complaints will be reviewed and investigated promptly and
|
65
|
+
fairly.
|
43
66
|
|
44
|
-
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
All community leaders are obligated to respect the privacy and security of the
|
68
|
+
reporter of any incident.
|
45
69
|
|
46
70
|
## Enforcement Guidelines
|
47
71
|
|
48
|
-
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
73
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
49
74
|
|
50
75
|
### 1. Correction
|
51
76
|
|
52
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
78
|
+
unprofessional or unwelcome in the community.
|
53
79
|
|
54
|
-
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
**Consequence**: A private, written warning from community leaders, providing
|
81
|
+
clarity around the nature of the violation and an explanation of why the
|
82
|
+
behavior was inappropriate. A public apology may be requested.
|
55
83
|
|
56
84
|
### 2. Warning
|
57
85
|
|
58
|
-
**Community Impact**: A violation through a single incident or series
|
86
|
+
**Community Impact**: A violation through a single incident or series
|
87
|
+
of actions.
|
59
88
|
|
60
|
-
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
90
|
+
interaction with the people involved, including unsolicited interaction with
|
91
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
92
|
+
includes avoiding interactions in community spaces as well as external channels
|
93
|
+
like social media. Violating these terms may lead to a temporary or
|
94
|
+
permanent ban.
|
61
95
|
|
62
96
|
### 3. Temporary Ban
|
63
97
|
|
64
|
-
**Community Impact**: A serious violation of community standards, including
|
98
|
+
**Community Impact**: A serious violation of community standards, including
|
99
|
+
sustained inappropriate behavior.
|
65
100
|
|
66
|
-
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
102
|
+
communication with the community for a specified period of time. No public or
|
103
|
+
private interaction with the people involved, including unsolicited interaction
|
104
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
105
|
+
Violating these terms may lead to a permanent ban.
|
67
106
|
|
68
107
|
### 4. Permanent Ban
|
69
108
|
|
70
|
-
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
110
|
+
standards, including sustained inappropriate behavior, harassment of an
|
111
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
71
112
|
|
72
|
-
**Consequence**: A permanent ban from any sort of public interaction within
|
113
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
114
|
+
the community.
|
73
115
|
|
74
116
|
## Attribution
|
75
117
|
|
76
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
77
|
-
available at
|
78
|
-
|
79
|
-
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
118
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
119
|
+
version 2.1, available at
|
120
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
80
121
|
|
81
|
-
|
122
|
+
Community Impact Guidelines were inspired by
|
123
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
82
124
|
|
83
125
|
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
-
https://www.contributor-covenant.org/faq. Translations are available
|
126
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
127
|
+
at [https://www.contributor-covenant.org/translations][translations].
|
128
|
+
|
129
|
+
[homepage]: https://www.contributor-covenant.org
|
130
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
131
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
132
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
133
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Contributing to YAHL7
|
2
|
+
|
3
|
+
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
|
4
|
+
|
5
|
+
The following are guidelines for contributing to the YAHL7 gem.
|
6
|
+
|
7
|
+
## Code of Conduct
|
8
|
+
|
9
|
+
Please familiarize yourself with the
|
10
|
+
[code of conduct](https://github.com/mylanconnolly/yahl7/blob/main/CODE_OF_CONDUCT.md).
|
11
|
+
It is based on the [Contributor Covenant](https://www.contributor-covenant.org/)
|
12
|
+
and will be enforced.
|
13
|
+
|
14
|
+
## What Should I Know?
|
15
|
+
|
16
|
+
Some familiarity with Ruby and the HL7 standard will likely be necessary here.
|
17
|
+
|
18
|
+
## Reporting Bugs
|
19
|
+
|
20
|
+
When filing a bug report, please use the
|
21
|
+
[issue template](https://github.com/mylanconnolly/yahl7/blob/main/.github/ISSUE_TEMPLATE/bug_report.md).
|
22
|
+
This template contains items that are useful for us to resolve issues more
|
23
|
+
efficiently.
|
24
|
+
|
25
|
+
## Suggesting Enhancements
|
26
|
+
|
27
|
+
Is there some functionality missing that you'd like to see added? There is an
|
28
|
+
[issue template](https://github.com/mylanconnolly/yahl7/blob/main/.github/ISSUE_TEMPLATE/feature_request.md)
|
29
|
+
for that! In short, I'll be happy to consider any feature request, but there
|
30
|
+
should be some justification for it.
|
31
|
+
|
32
|
+
## Code Contribution
|
33
|
+
|
34
|
+
Contributing code is relatively easy. Create a pull request with the proposed
|
35
|
+
changes and I'll review it as soon as I'm able to. It's possible I'll request
|
36
|
+
some changes or ask for some justification, so if it's a large change, opening
|
37
|
+
an issue first to discuss specifics might save some effort all around.
|
38
|
+
|
39
|
+
Any new code should be tested where possible, in order to ensure the code is as
|
40
|
+
robust as possible.
|
41
|
+
|
42
|
+
All Ruby code should be run through [RuboCop](https://rubocop.org/) prior to
|
43
|
+
creating the pull request. This can be accomplished by running the command:
|
44
|
+
|
45
|
+
```bash
|
46
|
+
bundle exec rubocop -A
|
47
|
+
```
|
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# YAHL7 (yet another HL7 client)
|
2
2
|
|
3
3
|
[](https://github.com/mylanconnolly/yahl7/actions/workflows/main.yml)
|
4
|
+
[](https://badge.fury.io/rb/yahl7)
|
5
|
+
|
6
|
+
> **NOTE** Until this gem reaches version 1.0, you should consider the API to be
|
7
|
+
> unstable and minor or major changes may occur with any release. Once version
|
8
|
+
> 1.0 has been released, the API will be stable for all 1.x release in keeping
|
9
|
+
> with [Semantic Versioning](https://semver.org/).
|
4
10
|
|
5
11
|
This gem is used to parse HL7 data from strings or IO sources in Ruby. We
|
6
12
|
currently support any version of HL7 >= 2 and < 3 (which came with a change to
|
@@ -33,7 +39,17 @@ This should ensure that the code is reasonably cross-platform.
|
|
33
39
|
|
34
40
|
## Installation
|
35
41
|
|
36
|
-
|
42
|
+
Install the gem globally:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
gem install 'yahl7'
|
46
|
+
```
|
47
|
+
|
48
|
+
Or add the following to your Gemfile:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
gem 'yahl7'
|
52
|
+
```
|
37
53
|
|
38
54
|
## Usage
|
39
55
|
|
@@ -156,7 +172,7 @@ Bug reports and pull requests are welcome on GitHub at
|
|
156
172
|
https://github.com/mylanconnolly/yahl7. This project is intended to be a
|
157
173
|
safe, welcoming space for collaboration, and contributors are expected to adhere
|
158
174
|
to the
|
159
|
-
[code of conduct](https://github.com/mylanconnolly/yahl7/blob/
|
175
|
+
[code of conduct](https://github.com/mylanconnolly/yahl7/blob/main/CODE_OF_CONDUCT.md).
|
160
176
|
|
161
177
|
## License
|
162
178
|
|
@@ -167,4 +183,4 @@ The gem is available as open source under the terms of the
|
|
167
183
|
|
168
184
|
Everyone interacting in the HL7 project's codebases, issue trackers, chat rooms
|
169
185
|
and mailing lists is expected to follow the
|
170
|
-
[code of conduct](https://github.com/mylanconnolly/yahl7/blob/
|
186
|
+
[code of conduct](https://github.com/mylanconnolly/yahl7/blob/main/CODE_OF_CONDUCT.md).
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
module YAHL7
|
4
4
|
module V2
|
5
|
-
# This module can be included into a
|
6
|
-
#
|
7
|
-
#
|
5
|
+
# This module can be included into a class to make the `define_field_names`
|
6
|
+
# macro available. This macro allows you to define repetitive field name
|
7
|
+
# aliases in a quick and easy fashion.
|
8
8
|
#
|
9
9
|
# For example:
|
10
10
|
#
|
11
|
-
# include YAHL7::V2::
|
11
|
+
# include YAHL7::V2::AliasFieldNames
|
12
12
|
#
|
13
13
|
# define_field_names({ patient_identifier_list: 3 })
|
14
14
|
#
|
@@ -17,7 +17,7 @@ module YAHL7
|
|
17
17
|
#
|
18
18
|
# If you want to define more complex methods, you can exclude them from this
|
19
19
|
# hash and define them manually.
|
20
|
-
module
|
20
|
+
module AliasFieldNames
|
21
21
|
def self.included(base)
|
22
22
|
base.extend(ClassMethods)
|
23
23
|
end
|
@@ -25,8 +25,15 @@ module YAHL7
|
|
25
25
|
# This is the module that actually extends the segment.
|
26
26
|
module ClassMethods
|
27
27
|
def define_field_names(mappings)
|
28
|
-
mappings.each do |name,
|
29
|
-
|
28
|
+
mappings.each do |name, mapping|
|
29
|
+
case mapping
|
30
|
+
when Integer then define_method(name) { self[mapping] }
|
31
|
+
when Hash
|
32
|
+
define_method(name) do
|
33
|
+
value = self[mapping[:index]]
|
34
|
+
value.nil? || value == '' ? nil : mapping[:class].new(value)
|
35
|
+
end
|
36
|
+
end
|
30
37
|
end
|
31
38
|
end
|
32
39
|
end
|