Ejemplo n.º 1
0
    def testPythonVisitor(self):
        python = PythonVisitor("parse_278")
        parse_278.visit(python)
        text = python.getSource()
        sample = """from tigershark.X12.parse import Message, Loop, Segment, Composite, Element, Properties
parse_278 = Message( '278', Properties(desc='HIPAA Health Care Services Review: Request X094A1-278'),
  Loop( 'ISA', Properties(req_sit='R',repeat='1',desc='ISA'),
    Segment( 'ISA', Properties(),
    ),
    Loop( 'GS', Properties(req_sit='R',repeat='1',desc='GS'),
      Segment( 'GS', Properties(),
      ),
      Loop( 'ST', Properties(req_sit='R',repeat='1',desc='ST'),
        Segment( 'ST', Properties(qual=(1, '278'),req_sit='R',repeat='1',desc='Transaction Set Header'),
          Element( 'ST01', Properties(desc=None, req_sit=None, data_type=(None,None,None), position=1,
            codes=['278'] ) ),
        ),
        Segment( 'BHT', Properties(req_sit='R',repeat='1',desc='Beginning of Hierarchical Transaction'),
        ),
        Loop( '2000A', Properties(req_sit='R',repeat='1',desc='2000A'),
          Segment( 'HL', Properties(qual=(3, '20'),req_sit='R',repeat='1',desc='Utilization Management Organization (UMO) Level'),
            Element( 'HL03', Properties(desc=None, req_sit=None, data_type=(None,None,None), position=3,
              codes=['20'] ) ),
          ),
          Loop( '2010A', Properties(req_sit='R',repeat='>1',desc='2010A'),
            Segment( 'NM1', Properties(qual=(1, 'X3'),req_sit='R',repeat='1',desc='Utilization Management Organization (UMO) Name'),
              Element( 'NM101', Properties(desc=None, req_sit=None, data_type=(None,None,None), position=1,
                codes=['X3'] ) ),
            ),
          ),"""
        tLines = text.splitlines()
        sLines = sample.splitlines()
        for i in range(len(sLines)):
            self.assertEqual(tLines[i].rstrip(), sLines[i].rstrip())
Ejemplo n.º 2
0
    def testPythonVisitor( self ):
        python= PythonVisitor( "parse_278" )
        parse_278.visit( python )
        text= python.getSource()
        sample="""from tigershark.X12.parse import Message, Loop, Segment, Composite, Element, Properties
parse_278 = Message( '278', Properties(desc='HIPAA Health Care Services Review: Request X094A1-278'),
  Loop( 'ISA', Properties(req_sit='R',repeat='1',desc='ISA'),
    Segment( 'ISA', Properties(),
    ),
    Loop( 'GS', Properties(req_sit='R',repeat='1',desc='GS'),
      Segment( 'GS', Properties(),
      ),
      Loop( 'ST', Properties(req_sit='R',repeat='1',desc='ST'),
        Segment( 'ST', Properties(qual=(1, '278'),req_sit='R',repeat='1',desc='Transaction Set Header'),
          Element( 'ST01', Properties(desc=None, req_sit=None, data_type=(None,None,None), position=1,
            codes=['278'] ) ),
        ),
        Segment( 'BHT', Properties(req_sit='R',repeat='1',desc='Beginning of Hierarchical Transaction'),
        ),
        Loop( '2000A', Properties(req_sit='R',repeat='1',desc='2000A'),
          Segment( 'HL', Properties(qual=(3, '20'),req_sit='R',repeat='1',desc='Utilization Management Organization (UMO) Level'),
            Element( 'HL03', Properties(desc=None, req_sit=None, data_type=(None,None,None), position=3,
              codes=['20'] ) ),
          ),
          Loop( '2010A', Properties(req_sit='R',repeat='>1',desc='2010A'),
            Segment( 'NM1', Properties(qual=(1, 'X3'),req_sit='R',repeat='1',desc='Utilization Management Organization (UMO) Name'),
              Element( 'NM101', Properties(desc=None, req_sit=None, data_type=(None,None,None), position=1,
                codes=['X3'] ) ),
            ),
          ),"""
        tLines= text.splitlines()
        sLines= sample.splitlines()
        for i in range(len(sLines)):
            self.assertEqual( tLines[i].rstrip(), sLines[i].rstrip() )
Ejemplo n.º 3
0
 def test_PythonVisitor(self):
     python = PythonVisitor("parse_278")
     parse_278.visit(python)
     text = python.getSource()
     with open('tests/278-sample.txt') as f:
         sample = f.read()
     tLines = text.splitlines()
     sLines = sample.splitlines()
     for i in range(len(sLines)):
         self.assertEqual(tLines[i].rstrip(), sLines[i].rstrip())
Ejemplo n.º 4
0
 def test_PythonVisitor(self):
     python = PythonVisitor("parse_278")
     parse_278.visit(python)
     text = python.getSource()
     with open('tests/278-sample.txt') as f:
         sample = f.read()
     tLines = text.splitlines()
     sLines = sample.splitlines()
     for i in range(len(sLines)):
         self.assertEqual(tLines[i].rstrip(), sLines[i].rstrip())
Ejemplo n.º 5
0
def writeFile(aFile, name, x12, structure="flat"):
    """Write the x12 python module to a file.
    
    :param aFile: Filename of destination file.
    :type aFile: String
    :param name: The name of the generated class.
    :type name: String
    :param x12: The `X12.parse.Message` object to write.
    :type x12: `X12.parse.Message`
    """
    if structure == "nested":
        pyMap = PythonVisitor(name)
    else:
        pyMap = FlatPythonVisitor(name)
    x12.visit(pyMap)
    pySrc = pyMap.getSource()
    with open(aFile, 'w') as f:
        f.write("#\n# Generated by TigerShark.tools.convertPyX12 on %s\n#\n" %
                datetime.now())
        f.write(pySrc)
        f.write('\n\n')
Ejemplo n.º 6
0
def writeFile(aFile, name, x12, structure="flat"):
    """Write the x12 python module to a file.

    :param aFile: Filename of destination file.
    :type aFile: String
    :param name: The name of the generated class.
    :type name: String
    :param x12: The `X12.parse.Message` object to write.
    :type x12: `X12.parse.Message`
    """
    if structure == "nested":
        pyMap= PythonVisitor( name )
    else:
        pyMap= FlatPythonVisitor( name )
    x12.visit( pyMap )
    pySrc= pyMap.getSource()
    with open(aFile, 'w') as f:
        f.write("#\n# Generated by TigerShark.tools.convertPyX12 on %s\n#\n" %
                datetime.now())
        f.write( pySrc )
        f.write( '\n\n' )