Exemple #1
0
 def reduce_content_size(self, content):
     to_delete = []
     for key, value in iteritems(content):
         if value is not None:
             if value['type'] in ('sequence',
                                  'choice') and value.get('content'):
                 try:
                     new_value = (value['type'],
                                  tuple((x['ref'], (x.get('min', 0),
                                                    x.get('max', -1)))
                                        for x in value['content']))
                 except:
                     new_value = None
             elif value['type'] == 'annotation':
                 new_value = ('leaf', value['datatype'],
                              value.get('libraryLongName'),
                              value.get('table'))
             else:
                 new_value = None
             if new_value is None:
                 to_delete.append(key)
             else:
                 content[key] = new_value
     for k in to_delete:
         del content[k]
Exemple #2
0
 def parse_datatypes(self):
     """
     Parses the datatypes.xsd file found in the input_path and stores
     the results in the datatypes.py module.
     """
     parse_res = self.parse_schema("datatypes.xsd")
     content, types = parse_res[0], parse_res[2]
     content.update(types)
     content = {k: v for k, v in iteritems(content) if not k.endswith("_CONTENT")}
     self.generate_module("datatypes.py", content)
Exemple #3
0
 def parse_datatypes(self):
     """
     Parses the datatypes.xsd file found in the input_path and stores
     the results in the datatypes.py module.
     """
     parse_res = self.parse_schema("datatypes.xsd")
     content, types = parse_res[0], parse_res[2]
     content.update(types)
     content = {
         k: v
         for k, v in iteritems(content) if not k.endswith("_CONTENT")
     }
     self.generate_module("datatypes.py", content)
Exemple #4
0
 def parse_messages(self):
     """
     Retrieves XSD files list from messages.xsd for parsing and stores
     all the results in the messages.py module.
     """
     parse_res = self.parse_schema("messages.xsd")
     content, includes = parse_res[0], parse_res[1]
     message_files = includes
     message_def = {}
     groups = {}
     for f in message_files:  # each file describes an HL7 message
         message, ext = os.path.splitext(f)
         content = self.parse_schema(f)[0]
         message_def[message] = content[message.upper()]
         groups.update(g for g in iteritems(content) if g[0] != message)
     self.generate_module("messages.py", message_def)
     self.generate_module("groups.py", groups)
Exemple #5
0
 def parse_messages(self):
     """
     Retrieves XSD files list from messages.xsd for parsing and stores
     all the results in the messages.py module.
     """
     parse_res = self.parse_schema("messages.xsd")
     content, includes = parse_res[0], parse_res[1]
     message_files = includes
     message_def = {}
     groups = {}
     for f in message_files:  # each file describes an HL7 message
         message, ext = os.path.splitext(f)
         content = self.parse_schema(f)[0]
         message_def[message] = content[message.upper()]
         groups.update(g for g in iteritems(content) if g[0] != message)
     self.generate_module("messages.py", message_def)
     self.generate_module("groups.py", groups)
Exemple #6
0
 def reduce_content_size(self, content):
     to_delete = []
     for key, value in iteritems(content):
         if value is not None:
             if value['type'] in ('sequence', 'choice') and value.get('content'):
                 try:
                     new_value = (value['type'],
                                  tuple((x['ref'], (x.get('min', 0), x.get('max', -1))) for x in value['content']))
                 except:
                     new_value = None
             elif value['type'] == 'annotation':
                 new_value = ('leaf', value['datatype'], value.get('libraryLongName'), value.get('table'))
             else:
                 new_value = None
             if new_value is None:
                 to_delete.append(key)
             else:
                 content[key] = new_value
     for k in to_delete:
         del content[k]
Exemple #7
0
        ('PN_3', DATATYPES['PN_3'], (0, 1), 'CMP'),
        ('PN_4', DATATYPES['PN_4'], (0, 1), 'CMP'),
        ('PN_5', DATATYPES['PN_5'], (0, 1), 'CMP'),
        ('PN_6', DATATYPES['PN_6'], (0, 1), 'CMP'),
    ),
    'RI': (
        ('RI_1', DATATYPES['RI_1'], (0, 1), 'CMP'),
        ('RI_2', DATATYPES['RI_2'], (0, 1), 'CMP'),
    ),
    'TQ': (
        ('TQ_1', DATATYPES['TQ_1'], (0, 1), 'CMP'),
        ('TQ_2', DATATYPES['TQ_2'], (0, 1), 'CMP'),
        ('TQ_3', DATATYPES['TQ_3'], (0, 1), 'CMP'),
        ('TQ_4', DATATYPES['TQ_4'], (0, 1), 'CMP'),
        ('TQ_5', DATATYPES['TQ_5'], (0, 1), 'CMP'),
        ('TQ_6', DATATYPES['TQ_6'], (0, 1), 'CMP'),
        ('TQ_7', DATATYPES['TQ_7'], (0, 1), 'CMP'),
        ('TQ_8', DATATYPES['TQ_8'], (0, 1), 'CMP'),
        ('TQ_9', DATATYPES['TQ_9'], (0, 1), 'CMP'),
        ('TQ_10', DATATYPES['TQ_10'], (0, 1), 'CMP'),
    ),
    'TS': (
        ('TS_1', DATATYPES['TS_1'], (0, 1), 'CMP'),
        ('TS_2', DATATYPES['TS_2'], (0, 1), 'CMP'),
    ),
}

for k, v in iteritems(DATATYPES):
    if v[0] == 'sequence':
        v[1] = DATATYPES_STRUCTS[v[2]]
Exemple #8
0
    )),
    'ORU_R01_PATIENT_RESULT': ('sequence', (
        ['ORU_R01_PATIENT', None, (0, 1), 'GRP'],
        ['ORU_R01_ORDER_OBSERVATION', None, (1, -1), 'GRP'],
    )),
    'ORU_R03_OBSERVATION': ('sequence', (
        ['OBX', None, (0, 1), 'SEG'],
        ['NTE', None, (0, -1), 'SEG'],
    )),
    'ORU_R03_ORDER_OBSERVATION': ('sequence', (
        ['ORC', None, (0, 1), 'SEG'],
        ['OBR', None, (1, 1), 'SEG'],
        ['NTE', None, (0, -1), 'SEG'],
        ['ORU_R03_OBSERVATION', None, (1, -1), 'GRP'],
    )),
    'ORU_R03_PATIENT': ('sequence', (
        ['PID', None, (1, 1), 'SEG'],
        ['NTE', None, (0, -1), 'SEG'],
        ['PV1', None, (0, 1), 'SEG'],
    )),
    'ORU_R03_PATIENT_RESULT': ('sequence', (
        ['ORU_R03_PATIENT', None, (0, 1), 'GRP'],
        ['ORU_R03_ORDER_OBSERVATION', None, (1, -1), 'GRP'],
    )),
}

for k, v in iteritems(GROUPS):
    for item in v[1]:
        if item[3] == 'GRP':
            item[1] = GROUPS[item[0]]
Exemple #9
0
    'ORR_O02_ORDER': ('sequence',
                      (['ORC', SEGMENTS['ORC'], (1, 1), 'SEG'],
                       ['ORR_O02_ORDER_DETAIL', None, (0, 1), 'GRP'],
                       ['NTE', SEGMENTS['NTE'], (0, -1), 'SEG'],)),
    'ORR_O02_ORDER_DETAIL': ('sequence',
                             (['ORR_O02_CHOICE', None, (1, 1), 'GRP'],)),
    'ORR_O02_PATIENT': ('sequence',
                        (['PID', SEGMENTS['PID'], (0, 1), 'SEG'],
                         ['NTE', SEGMENTS['NTE'], (0, -1), 'SEG'],
                         ['ORR_O02_ORDER', None, (1, -1), 'GRP'],)),
    'ORU_R01_OBSERVATION': ('sequence',
                            (['OBX', SEGMENTS['OBX'], (0, 1), 'SEG'],
                             ['NTE', SEGMENTS['NTE'], (0, -1), 'SEG'],)),
    'ORU_R01_ORDER_OBSERVATION': ('sequence',
                                  (['ORC', SEGMENTS['ORC'], (0, 1), 'SEG'],
                                   ['OBR', SEGMENTS['OBR'], (1, 1), 'SEG'],
                                   ['NTE', SEGMENTS['NTE'], (0, -1), 'SEG'],
                                   ['ORU_R01_OBSERVATION', None, (1, -1), 'GRP'],)),
    'ORU_R01_PATIENT': ('sequence',
                        (['PID', SEGMENTS['PID'], (1, 1), 'SEG'],
                         ['NTE', SEGMENTS['NTE'], (0, -1), 'SEG'],
                         ['PV1', SEGMENTS['PV1'], (0, 1), 'SEG'],)),
    'ORU_R01_PATIENT_RESULT': ('sequence',
                               (['ORU_R01_PATIENT', None, (0, 1), 'GRP'],
                                ['ORU_R01_ORDER_OBSERVATION', None, (1, -1), 'GRP'],)),
}
for k, v in iteritems(GROUPS):
    for item in v[1]:
        if item[3] == 'GRP':
            item[1] = GROUPS[item[0]]
Exemple #10
0
           ('XON_4', DATATYPES['XON_4'], (0, 1), 'CMP'),
           ('XON_5', DATATYPES['XON_5'], (0, 1), 'CMP'),
           ('XON_6', DATATYPES['XON_6'], (0, 1), 'CMP'),
           ('XON_7', DATATYPES['XON_7'], (0, 1), 'CMP'),
           ('XON_8', DATATYPES['XON_8'], (0, 1), 'CMP'),
           ('XON_9', DATATYPES['XON_9'], (0, 1), 'CMP'),),
    'XPN': (
           ('XPN_1', DATATYPES['XPN_1'], (0, 1), 'CMP'),
           ('XPN_2', DATATYPES['XPN_2'], (0, 1), 'CMP'),
           ('XPN_3', DATATYPES['XPN_3'], (0, 1), 'CMP'),
           ('XPN_4', DATATYPES['XPN_4'], (0, 1), 'CMP'),
           ('XPN_5', DATATYPES['XPN_5'], (0, 1), 'CMP'),
           ('XPN_6', DATATYPES['XPN_6'], (0, 1), 'CMP'),
           ('XPN_7', DATATYPES['XPN_7'], (0, 1), 'CMP'),
           ('XPN_8', DATATYPES['XPN_8'], (0, 1), 'CMP'),),
    'XTN': (
           ('XTN_1', DATATYPES['XTN_1'], (0, 1), 'CMP'),
           ('XTN_2', DATATYPES['XTN_2'], (0, 1), 'CMP'),
           ('XTN_3', DATATYPES['XTN_3'], (0, 1), 'CMP'),
           ('XTN_4', DATATYPES['XTN_4'], (0, 1), 'CMP'),
           ('XTN_5', DATATYPES['XTN_5'], (0, 1), 'CMP'),
           ('XTN_6', DATATYPES['XTN_6'], (0, 1), 'CMP'),
           ('XTN_7', DATATYPES['XTN_7'], (0, 1), 'CMP'),
           ('XTN_8', DATATYPES['XTN_8'], (0, 1), 'CMP'),
           ('XTN_9', DATATYPES['XTN_9'], (0, 1), 'CMP'),),
}

for k, v in iteritems(DATATYPES):
    if v[0] == 'sequence':
        v[1] = DATATYPES_STRUCTS[v[2]]