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  __license__ = "GPL v2 or later"
    15  __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>"
    16
    17
    18  # stdlib
    19  import sys, io, time, datetime as pyDT
    20
    21
    22  # GNUmed modules
    23  if __name__ == '__main__':
    24          sys.path.insert(0, '../../')
    25  from Gnumed.pycommon import gmTools, gmDateTime
    26  from Gnumed.business import gmPerson
    27
    28  PATIENTS_IN_line_len = 223
    29  PATIENTS_IN_dob_format = '%d/%m/%Y'
    30
    31  #============================================================
    32 -def read_persons_from_pracsoft_file(filename=None, encoding='ascii'):
    33
    34          pats_file = io.open(filename, mode = 'rt', encoding = encoding)
    35          dtos = []
    36
    37          for line in pats_file:
    38                  if len(line) < PATIENTS_IN_line_len:
    39                          continue                        # perhaps raise Exception ?
    40
    41                  dto = gmPerson.cDTO_person()
    42                  dto.external_ids = [
    43                          {'PracSoft No.': line[0:9].strip(), 'issuer': 'AU PracSoft application'},
    44                          {'CRN': line[166:180].replace(' ', ''), 'issuer': 'Centrelink (AU)'},
    45                          {'DVA': line[180:194].replace(' ', ''), 'issuer': "Department of Veteran's Affairs (AU)"},
    46                          {'AU-Medicare': line[153:166].replace(' ', ''), 'issuer': 'HIC (AU)'}
    47                  ]
    48
    49                  dto.title = gmTools.capitalize(line[9:14].strip(), gmTools.CAPS_FIRST)
    50                  dto.firstnames = gmTools.capitalize(line[44:74].strip(), gmTools.CAPS_NAMES)
    51                  dto.lastnames = gmTools.capitalize(line[14:44].strip(), gmTools.CAPS_NAMES)
    52
    53                  dto.gender = line[223].lower()
    54                  dob = time.strptime(line[143:153].strip(), PATIENTS_IN_dob_format)
    55                  dto.dob = pyDT.datetime(dob.tm_year, dob.tm_mon, dob.tm_mday, tzinfo = gmDateTime.gmCurrentLocalTimezone)
    56
    57                  # this is the home address
    58                  dto.street = gmTools.capitalize(line[74:114].strip(), gmTools.CAPS_FIRST)
    59                  dto.zip = line[139:143].strip()
    60                  dto.urb = line[114:139].strip()
    61
    62                  dto.comms = [                                   # types must correspond to GNUmed database comm type
    63                          {'homephone': line[194:208].replace(' ', '')},
    64                          {'workphone': line[208:222].replace(' ', '')}
    65                  ]
    66                  dto.pracsoft_billing_flag = line[222] # P=pensioner R=repatriation
    67
    68                  dtos.append(dto)
    69
    70          return dtos
    71  #============================================================
    72  # main
    73  #------------------------------------------------------------
    74  if __name__ == "__main__":
    75          from Gnumed.pycommon import gmI18N
    76          gmI18N.activate_locale()
    77          gmI18N.install_domain()
    78          gmDateTime.init()
    79
    80          patfile = sys.argv[1]
    81          print "reading patient data from PATIENTS.IN PracSoft file [%s]" % patfile
    82
    83          dtos = read_persons_from_pracsoft_file(patfile)
    84          for dto in dtos:
    85                  print "DTO:", dto
    86                  print "dto.dob:", dto.dob, type(dto.dob)
    87                  print "dto.dob.tz:", dto.dob.tzinfo
    88                  print "dto.zip: %s dto.urb: %s" % (dto.zip, dto.urb)
    89                  print "dto.street", dto.street
    90  #               searcher = gmPersonSearch.cPatientSearcher_SQL()
    91  #               ident = searcher.get_identities(dto=dto)[0]
    92  #               print ident
    93
    94  #==============================================================
    95