def __find_or_create_test_type(loinc=None, name=None, pk_lab=None, unit=None, link_obj=None, abbrev=None): tt = gmPathLab.find_measurement_type(link_obj = link_obj, lab = pk_lab, name = name) if tt is None: _log.debug('test type [%s %s (%s)] not found for lab #%s, creating', name, unit, loinc, pk_lab) tt = gmPathLab.create_measurement_type(link_obj = link_obj, lab = pk_lab, abbrev = gmTools.coalesce(abbrev, name), unit = unit, name = name) if loinc is None: return tt if loinc.strip() == u'': return tt if tt['loinc'] is None: tt['loinc'] = loinc tt.save(conn = link_obj) return tt if tt['loinc'] != loinc: # raise ValueError('LOINC code mismatch between GM (%s) and HL7 (%s) for result type [%s]' % (tt['loinc'], loinc, name)) _log.error('LOINC code mismatch between GM (%s) and HL7 (%s) for result type [%s]', tt['loinc'], loinc, name) return tt
def __find_or_create_test_type(loinc=None, name=None, pk_lab=None, unit=None, link_obj=None, abbrev=None): tt = gmPathLab.find_measurement_type(link_obj = link_obj, lab = pk_lab, name = name) if tt is None: _log.debug('test type [%s::%s::%s] not found for lab #%s, creating', name, unit, loinc, pk_lab) tt = gmPathLab.create_measurement_type(link_obj = link_obj, lab = pk_lab, abbrev = gmTools.coalesce(abbrev, name), unit = unit, name = name) _log.debug('created as: %s', tt) if loinc is None: return tt if loinc.strip() == '': return tt if tt['loinc'] is None: tt['loinc'] = loinc tt.save(conn = link_obj) return tt if tt['loinc'] != loinc: # raise ValueError('LOINC code mismatch between GM (%s) and HL7 (%s) for result type [%s]' % (tt['loinc'], loinc, name)) _log.error('LOINC code mismatch between GM (%s) and HL7 (%s) for result type [%s]', tt['loinc'], loinc, name) return tt
def __handle_8410(self, result_data): if self.__request is None: _log.Log(gmLog.lErr, 'Kann Labordaten nicht ohne Zuordnung importieren.') return False # skip pseudo results if len(result_data) == 3: if ('8410' in result_data and # code '8411' in result_data and # name '8412' in result_data): # Abrechnungskennung _log.Log(gmLog.lInfo, 'skipping billing-only record') return True # verify essential fields # - numeric result try: vnum = '\n'.join(result_data['8420']) except KeyError: vnum = None # - alphanumeric result try: valpha = '\n'.join(result_data['8480']) except KeyError: valpha = None if (valpha is None) and (vnum is None): valpha = '' # - code try: vcode = result_data['8410'][0] except KeyError: _log.Log(gmLog.lWarn, 'adding default test type code') # - name try: vname = result_data['8411'][0] except KeyError: _log.Log(gmLog.lWarn, 'adding default test type name') # - unit try: vunit = result_data['8421'][0] except KeyError: vunit = '' # verify/create test type status, ttype = gmPathLab.create_measurement_type ( lab=self.__lab_name, code=vcode, # must be abbrev name=vname, unit=vunit ) if status in [False, None]: _log.Log(gmLog.lErr, 'cannot create/retrieve test type') return False if ttype['comment'] in [None, '']: ttype['comment'] = 'created [%s] by [$RCSfile: gmLDTimporter.py,v $ $Revision: 1.34 $] from [%s]' % (time.strftime('%Y-%m-%d %H:%M'), self.ldt_filename) ttype.save_payload() # try to create test result row whenfield = 'lab_rxd_when' # FIXME: make this configurable status, self.__lab_result = gmPathLab.create_lab_result( patient_id = self.__request.get_patient()[0], when_field = whenfield, when = self.__request[whenfield], test_type = ttype['pk'], val_num = vnum, val_alpha = valpha, unit = vunit, request = self.__request ) if status is False: _log.Log(gmLog.lErr, 'cannot create result record') _log.Log(gmLog.lInfo, str(result_data)[:500]) return False # FIXME: make this configurable (whether skipping or duplicating) if status is None: _log.Log(gmLog.lData, 'skipping duplicate lab result on import') _log.Log(gmLog.lData, 'in file: %s' % str(result_data)) return True # update result record from dict # - force these to None so we can add in the proper values self.__lab_result['val_num'] = None self.__lab_result['val_alpha'] = None # - preset some fields self.__lab_result['reviewed'] = 'false' if self.__ref_group_str != '': self.__lab_result['ref_group'] = self.__ref_group_str # - process lines for line_type in result_data.keys(): # get handler try: handle_line = cLDTImporter.__8410line_handler[line_type] except KeyError: _log.LogException('no handler for line [%s] in [8410] record' % line_type, sys.exc_info(), verbose=0) return False # ignore line if handle_line is None: continue if handle_line(self, result_data) is False: # FIXME: todo item _log.Log(gmLog.lErr, 'cannot handle [%s] line' % line_type) return False if (self.__lab_result['val_alpha'] is None) and (self.__lab_result['val_num'] is None): _log.Log(gmLog.lWarn, 'both result fields empty, setting alphanumeric default') self.__lab_result['val_alpha'] = '' saved, msg = self.__lab_result.save_payload() del self.__lab_result if not saved: _log.Log(gmLog.lErr, 'kann Laborwert (8410) nicht importieren') return False _log.Log(gmLog.lInfo, 'Laborwert (8410) erfolgreich importiert') return True
def __handle_8410(self, result_data): if self.__request is None: _log.Log(gmLog.lErr, 'Kann Labordaten nicht ohne Zuordnung importieren.') return False # skip pseudo results if len(result_data) == 3: if (result_data.has_key('8410') and # code result_data.has_key('8411') and # name result_data.has_key('8412')): # Abrechnungskennung _log.Log(gmLog.lInfo, 'skipping billing-only record') return True # verify essential fields # - numeric result try: vnum = '\n'.join(result_data['8420']) except KeyError: vnum = None # - alphanumeric result try: valpha = '\n'.join(result_data['8480']) except KeyError: valpha = None if (valpha is None) and (vnum is None): valpha = '' # - code try: vcode = result_data['8410'][0] except KeyError: _log.Log(gmLog.lWarn, 'adding default test type code') # - name try: vname = result_data['8411'][0] except KeyError: _log.Log(gmLog.lWarn, 'adding default test type name') # - unit try: vunit = result_data['8421'][0] except KeyError: vunit = '' # verify/create test type status, ttype = gmPathLab.create_measurement_type ( lab=self.__lab_name, code=vcode, # must be abbrev name=vname, unit=vunit ) if status in [False, None]: _log.Log(gmLog.lErr, 'cannot create/retrieve test type') return False if ttype['comment'] in [None, '']: ttype['comment'] = 'created [%s] by [$RCSfile: gmLDTimporter.py,v $ $Revision: 1.34 $] from [%s]' % (time.strftime('%Y-%m-%d %H:%M'), self.ldt_filename) ttype.save_payload() # try to create test result row whenfield = 'lab_rxd_when' # FIXME: make this configurable status, self.__lab_result = gmPathLab.create_lab_result( patient_id = self.__request.get_patient()[0], when_field = whenfield, when = self.__request[whenfield], test_type = ttype['pk'], val_num = vnum, val_alpha = valpha, unit = vunit, request = self.__request ) if status is False: _log.Log(gmLog.lErr, 'cannot create result record') _log.Log(gmLog.lInfo, str(result_data)[:500]) return False # FIXME: make this configurable (whether skipping or duplicating) if status is None: _log.Log(gmLog.lData, 'skipping duplicate lab result on import') _log.Log(gmLog.lData, 'in file: %s' % str(result_data)) return True # update result record from dict # - force these to None so we can add in the proper values self.__lab_result['val_num'] = None self.__lab_result['val_alpha'] = None # - preset some fields self.__lab_result['reviewed'] = 'false' if self.__ref_group_str != '': self.__lab_result['ref_group'] = self.__ref_group_str # - process lines for line_type in result_data.keys(): # get handler try: handle_line = cLDTImporter.__8410line_handler[line_type] except KeyError: _log.LogException('no handler for line [%s] in [8410] record' % line_type, sys.exc_info(), verbose=0) return False # ignore line if handle_line is None: continue if handle_line(self, result_data) is False: # FIXME: todo item _log.Log(gmLog.lErr, 'cannot handle [%s] line' % line_type) return False if (self.__lab_result['val_alpha'] is None) and (self.__lab_result['val_num'] is None): _log.Log(gmLog.lWarn, 'both result fields empty, setting alphanumeric default') self.__lab_result['val_alpha'] = '' saved, msg = self.__lab_result.save_payload() del self.__lab_result if not saved: _log.Log(gmLog.lErr, 'kann Laborwert (8410) nicht importieren') return False _log.Log(gmLog.lInfo, 'Laborwert (8410) erfolgreich importiert') return True