Skip to content

Commit

Permalink
Merge pull request #17 from maur1th/master
Browse files Browse the repository at this point in the history
Error handling on segment.getComponent
  • Loading branch information
hitgeek committed Feb 8, 2016
2 parents 68a4680 + a362dea commit 3be97e4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/hl7/segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ segment.prototype.getField = function(index) {
}

segment.prototype.getComponent = function(fieldIndex, componentIndex) {
return this.fields[fieldIndex - 1].value[0][componentIndex - 1].value[0];
var field = this.getField(fieldIndex);
if (field && field[componentIndex - 1]) {
return field[componentIndex - 1].value[0];
} else {
return '';
}
}

segment.prototype.toString = function(delimiters) {
Expand Down

0 comments on commit 3be97e4

Please sign in to comment.