Package Gnumed :: Package business :: Module gmPracSoftAU
[frames] | no frames]

Source Code for Module Gnumed.business.gmPracSoftAU

  1  """GNUmed to PracSoft(tm) AU connector classes. 
  2   
  3  The Australian PracSoft package writes patient data to a file 
  4  called PATIENTS.IN whenever patient data is added or edited. 
  5   
  6  This file has a de-facto format with one patient per line. The 
  7  line format has been derived empirically with no knowledge of 
  8  PracSoft internals whatsoever. The content is "ASCII" text of 
  9  fixed width fields. 
 10   
 11  This implementation is in the sole responsibility of the authors. 
 12  """ 
 13  #============================================================ 
 14  # $Source: /cvsroot/gnumed/gnumed/gnumed/client/business/gmPracSoftAU.py,v $ 
 15  # $Id: gmPracSoftAU.py,v 1.2 2007/02/13 17:05:22 ncq Exp $ 
 16  __license__ = "GPL" 
 17  __version__ = "$Revision: 1.2 $" 
 18  __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>" 
 19   
 20   
 21  # stdlib 
 22  import sys, codecs, time, datetime as pyDT 
 23   
 24   
 25  # GNUmed modules 
 26  if __name__ == '__main__': 
 27          sys.path.insert(0, '../../') 
 28  from Gnumed.pycommon import gmTools, gmDateTime 
 29  from Gnumed.business import gmPerson 
 30   
 31  PATIENTS_IN_line_len = 223 
 32  PATIENTS_IN_dob_format = '%d/%m/%Y' 
 33   
 34  #============================================================ 
35 -def read_persons_from_pracsoft_file(filename=None, encoding='ascii'):
36 37 pats_file = codecs.open(filename=filename, mode='rU', encoding=encoding) 38 dtos = [] 39 40 for line in pats_file: 41 if len(line) < PATIENTS_IN_line_len: 42 continue # perhaps raise Exception ? 43 44 dto = gmPerson.cDTO_person() 45 dto.external_ids = [ 46 {'PracSoft No.': line[0:9].strip(), 'issuer': 'AU PracSoft application', 'context': 'p'}, 47 {'CRN': line[166:180].replace(' ', ''), 'issuer': 'Centrelink (AU)', 'context': 'p'}, 48 {'DVA': line[180:194].replace(' ', ''), 'issuer': "Department of Veteran's Affairs (AU)", 'context': 'p'}, 49 {'AU-Medicare': line[153:166].replace(' ', ''), 'issuer': 'HIC (AU)', 'context': 'p'} 50 ] 51 52 dto.title = gmTools.capitalize(line[9:14].strip(), gmTools.CAPS_FIRST) 53 dto.firstnames = gmTools.capitalize(line[44:74].strip(), gmTools.CAPS_NAMES) 54 dto.lastnames = gmTools.capitalize(line[14:44].strip(), gmTools.CAPS_NAMES) 55 56 dto.gender = line[223].lower() 57 dob = time.strptime(line[143:153].strip(), PATIENTS_IN_dob_format) 58 dto.dob = pyDT.datetime(dob.tm_year, dob.tm_mon, dob.tm_mday, tzinfo = gmDateTime.gmCurrentLocalTimezone) 59 60 # this is the home address 61 dto.street = gmTools.capitalize(line[74:114].strip(), gmTools.CAPS_FIRST) 62 dto.zip = line[139:143].strip() 63 dto.urb = line[114:139].strip() 64 65 dto.comms = [ # types must correspond to GNUmed database comm type 66 {'homephone': line[194:208].replace(' ', '')}, 67 {'workphone': line[208:222].replace(' ', '')} 68 ] 69 dto.pracsoft_billing_flag = line[222] # P=pensioner R=repatriation 70 71 dtos.append(dto) 72 73 return dtos
74 #============================================================ 75 # main 76 #------------------------------------------------------------ 77 if __name__ == "__main__": 78 from Gnumed.pycommon import gmI18N 79 gmI18N.activate_locale() 80 gmI18N.install_domain() 81 gmDateTime.init() 82 83 patfile = sys.argv[1] 84 print "reading patient data from PATIENTS.IN PracSoft file [%s]" % patfile 85 86 dtos = read_persons_from_pracsoft_file(patfile) 87 for dto in dtos: 88 print "DTO:", dto 89 print "dto.dob:", dto.dob, type(dto.dob) 90 print "dto.dob.tz:", dto.dob.tzinfo 91 print "dto.zip: %s dto.urb: %s" % (dto.zip, dto.urb) 92 print "dto.street", dto.street 93 # searcher = gmPerson.cPatientSearcher_SQL() 94 # ident = searcher.get_identities(dto=dto)[0] 95 # print ident 96 97 #============================================================== 98 # $Log: gmPracSoftAU.py,v $ 99 # Revision 1.2 2007/02/13 17:05:22 ncq 100 # - slightly better CONST name 101 # 102 # Revision 1.1 2007/02/05 14:29:04 ncq 103 # - read PracSoft PATIENTS.IN file 104 # 105 # 106