Skip to content

Commit

Permalink
refactor: removed duplicate code
Browse files Browse the repository at this point in the history
- this was not needed, all unit tests pass except still the three we are trying to fix
- un-ignore the tests to start troubleshooting #14
  • Loading branch information
Bugs5382 committed Jun 25, 2024
1 parent ba5f282 commit 053fcce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 41 deletions.
9 changes: 3 additions & 6 deletions __tests__/hl7.build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,15 @@ describe('node hl7 client - builder tests', () => {
expect(message.toString()).toContain('PV1|||||||^Jones^John')
})

// not working...
test.skip('...should be able to set repeating fields', async () => {
test('...should be able to set repeating fields', async () => {
message.set('PID.3').set(0).set('PID.3.1', 'abc')
message.set('PID.3').set(0).set('PID.3.5', 'MRN')
message.set('PID.3').set(1).set('PID.3.1', 123)
message.set('PID.3').set(1).set('PID.3.5', 'ID')
expect(message.toString()).toContain('PID|||abc^^^^MRN~123^^^^ID')
})

// not working...
test.skip('...can chain component setters', async () => {
test('...can chain component setters', async () => {
message.set('PV1.7').set(0).set('PV1.7.2', 'Jones').set('PV1.7.3', 'John')
message.set('PV1.7').set(1).set('PV1.7.2', 'Smith').set('PV1.7.3', 'Bob')
expect(message.toString()).toContain('PV1|||||||^Jones^John~^Smith^Bob')
Expand All @@ -355,8 +353,7 @@ describe('node hl7 client - builder tests', () => {
expect(message.toString()).toContain('PV1|||||||^Jones^John~^Smith^Bob')
})

// This is currently failing, why... I have no idea. Help!
test.skip('... add segment EVN field - using full path', async () => {
test('... add segment EVN field - using full path', async () => {
const segment = message.addSegment('EVN')
segment.set('EVN.2.1', '20081231')
expect(message.toString()).toBe('MSH|^~\\&|||||20081231||ADT^A01^ADT_A01|12345||2.7\rEVN||20081231')
Expand Down
36 changes: 1 addition & 35 deletions src/builder/modules/segment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Delimiters } from '../../utils/enum.js'
import { HL7FatalError } from '../../utils/exception.js'
import { isHL7Number, isHL7String } from '../../utils/utils.js'
import { isHL7String } from '../../utils/utils.js'
import { Field } from './field.js'
import { NodeBase } from './nodeBase.js'
import { HL7Node } from '../interface/hL7Node.js'
Expand Down Expand Up @@ -43,40 +43,6 @@ export class Segment extends NodeBase {
return typeof field !== 'undefined' && path.length > 0 ? field.read(path) : field
}

/** @internal */
set (path: string | number, value?: any): HL7Node {
if (arguments.length === 1) {
return this.ensure(path)
}

if (typeof path === 'string') {
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
this.set(`${path}.${i + 1}`, value[i])
}
} else {
const _path = this.preparePath(path)
this.write(_path, this.prepareValue(value))
}

return this
} else if (isHL7Number(path)) {
if (Array.isArray(value)) {
const child = this.ensure(path)
for (let i = 0, l = value.length; i < l; i++) {
child.set(i, value[i])
}
return this
} else {
this.setChild(this.createChild(this.prepareValue(value), path), path)
}

return this
}

throw new HL7FatalError('Path must be a string or number.')
}

/** @internal */
protected writeCore (path: string[], value: string): HL7Node {
let index = parseInt(path.shift() as string)
Expand Down

0 comments on commit 053fcce

Please sign in to comment.