Skip to content

Commit

Permalink
Start by extracting the code from a private repo
Browse files Browse the repository at this point in the history
  • Loading branch information
CJHwong committed Apr 27, 2022
1 parent b301769 commit 7a7b28b
Show file tree
Hide file tree
Showing 17 changed files with 925 additions and 0 deletions.
Empty file added pyx12lib/__init__.py
Empty file.
Empty file added pyx12lib/common/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions pyx12lib/common/interchange/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import absolute_import

from .functional_group import GeRenderer, GsRenderer
from .interchange import IeaRenderer, IsaRenderer
from .transaction_set import SeRenderer, StRenderer
54 changes: 54 additions & 0 deletions pyx12lib/common/interchange/functional_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from builtins import str

import dateutil.parser

from pyx12lib.core.renderer import SegmentRenderer

from .grammar import GeSegment, GsSegment


class GsRenderer(SegmentRenderer):
grammar = GsSegment

@property
def element_value_getters(self):
return {
'GS01': lambda ele, data, stat: 'SO', # Shipping Instruction
'GS02': lambda ele, data, stat: data.sender_id,
'GS03': lambda ele, data, stat: data.vendor_id,
'GS04': self.gs04,
'GS05': self.gs05,
'GS06': lambda ele, data, stat: '{:d}'.format(data.functional_group_no),
'GS07': lambda ele, data, stat: 'X', # ANSI X12
'GS08': lambda ele, data, stat: '004010', # Version 4010
}

@staticmethod
def gs04(ele, data, stat):
if data.submit_datetime:
datetime = dateutil.parser.parse(data.submit_datetime)
return datetime.strftime("%Y%m%d")

return ''

@staticmethod
def gs05(ele, data, stat):
if data.submit_datetime:
datetime = dateutil.parser.parse(data.submit_datetime)
return datetime.strftime('%H%M')

return ''


class GeRenderer(SegmentRenderer):
grammar = GeSegment

@property
def element_value_getters(self):
return {
'GE01': lambda ele, data, stat: str(data.transaction_count),
'GE02': lambda ele, data, stat: '{:d}'.format(data.functional_group_no),
}
3 changes: 3 additions & 0 deletions pyx12lib/common/interchange/grammar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .functional_group import GeSegment, GsSegment
from .interchange import IeaSegment, IsaSegment
from .transaction_set import SeSegment, StSegment
100 changes: 100 additions & 0 deletions pyx12lib/common/interchange/grammar/functional_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from pyx12lib.core.grammar import Element
from pyx12lib.core.grammar.segment import USAGE_MANDATORY, BaseSegment


class GsSegment(BaseSegment):
segment_id = 'GS'
usage = 'M'
max_use = 1
elements = (
Element(
reference_designator='GS01',
name='Functional Identifier Code',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=2,
maximum=2,
),
Element(
reference_designator='GS02',
name='Application Sender\'s Code',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=2,
maximum=15,
),
Element(
reference_designator='GS03',
name='Application Receiver\'s Code',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=2,
maximum=15,
),
Element(
reference_designator='GS04',
name='Date',
usage=USAGE_MANDATORY,
element_type='DT',
minimum=8,
maximum=8,
),
Element(
reference_designator='GS05',
name='Time',
usage=USAGE_MANDATORY,
element_type='TM',
minimum=4,
maximum=8,
),
Element(
reference_designator='GS06',
name='Group Control Number',
usage=USAGE_MANDATORY,
element_type='N0',
minimum=1,
maximum=9,
),
Element(
reference_designator='GS07',
name='Responsible Agency Code',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=1,
maximum=2,
),
Element(
reference_designator='GS08',
name='Version / Release / Industry Identifier Code',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=1,
maximum=12,
),
)


class GeSegment(BaseSegment):
segment_id = 'GE'
max_use = 1
elements = (
Element(
reference_designator='GE01',
name='VNumber of Transaction Sets Included',
usage=USAGE_MANDATORY,
element_type='N0',
minimum=1,
maximum=6,
),
Element(
reference_designator='GE02',
name='Group Control Number',
usage=USAGE_MANDATORY,
element_type='N0',
minimum=1,
maximum=9,
),
)
164 changes: 164 additions & 0 deletions pyx12lib/common/interchange/grammar/interchange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from pyx12lib.core.grammar import Element
from pyx12lib.core.grammar.segment import USAGE_MANDATORY, BaseSegment


class IsaSegment(BaseSegment):
segment_id = 'ISA'
usage = 'M'
max_use = 1
elements = (
Element(
reference_designator='ISA01',
name='Authorization Information Qualifier',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=2,
maximum=2,
),
Element(
reference_designator='ISA02',
name='Authorization Information',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=10,
maximum=10,
),
Element(
reference_designator='ISA03',
name='Security Information Qualifier',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=2,
maximum=2,
),
Element(
reference_designator='ISA04',
name='Security Information',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=10,
maximum=10,
),
Element(
reference_designator='ISA05',
name='Interchange ID Qualifier',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=2,
maximum=2,
),
Element(
reference_designator='ISA06',
name='Interchange Sender ID',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=15,
maximum=15,
),
Element(
reference_designator='ISA07',
name='Interchange ID Qualifier',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=2,
maximum=2,
),
Element(
reference_designator='ISA08',
name='Interchange Receiver ID',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=15,
maximum=15,
),
Element(
reference_designator='ISA09',
name='Interchange Date',
usage=USAGE_MANDATORY,
element_type='DT',
minimum=6,
maximum=6,
),
Element(
reference_designator='ISA10',
name='Interchange Time',
usage=USAGE_MANDATORY,
element_type='TM',
minimum=4,
maximum=4,
),
Element(
reference_designator='ISA11',
name='Interchange Control Standards Identifier',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=1,
maximum=1,
),
Element(
reference_designator='ISA12',
name='Interchange Control Version Number',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=5,
maximum=5,
),
Element(
reference_designator='ISA13',
name='Interchange Control Number',
usage=USAGE_MANDATORY,
element_type='N0',
minimum=9,
maximum=9,
),
Element(
reference_designator='ISA14',
name='Acknowledgment Requested',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=1,
maximum=1,
),
Element(
reference_designator='ISA15',
name='Usage Indicator',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=1,
maximum=1,
),
Element(
reference_designator='ISA16',
name='Component Element Separator',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=1,
maximum=1,
),
)


class IeaSegment(BaseSegment):
segment_id = 'IEA'
max_use = 1
elements = (
Element(
reference_designator='IEA01',
name='Number of Included Functional Groups',
usage=USAGE_MANDATORY,
element_type='N0',
minimum=1,
maximum=5,
),
Element(
reference_designator='IEA02',
name='Interchange Control Number',
usage=USAGE_MANDATORY,
element_type='N0',
minimum=9,
maximum=9,
),
)
52 changes: 52 additions & 0 deletions pyx12lib/common/interchange/grammar/transaction_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from pyx12lib.core.grammar import Element
from pyx12lib.core.grammar.segment import USAGE_MANDATORY, BaseSegment


class StSegment(BaseSegment):
segment_id = 'ST'
usage = 'M'
max_use = 1
elements = (
Element(
reference_designator='ST01',
name='Transaction Set Identifier Code',
usage=USAGE_MANDATORY,
element_type='ID',
minimum=3,
maximum=3,
),
Element(
reference_designator='ST02',
name='Transaction Set Control Number',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=4,
maximum=9,
),
)


class SeSegment(BaseSegment):
segment_id = 'SE'
max_use = 1
elements = (
Element(
reference_designator='SE01',
name='Number of Included Segments',
usage=USAGE_MANDATORY,
element_type='N0',
minimum=1,
maximum=10,
),
Element(
reference_designator='SE02',
name='Transaction Set Control Number',
usage=USAGE_MANDATORY,
element_type='AN',
minimum=4,
maximum=9,
),
)
Loading

0 comments on commit 7a7b28b

Please sign in to comment.