def packInfo(record): addressKList = [] name = record[4] npi = record[6] facilityId = record[0] totalPhysicians = record[15] if record[7] != None: addr = Address(record[7], record[8] + ' ' + record[9], record[10], record[11], record[12], record[14], msg='BillingAddress') else: addr = None addressKList.append(addr) conn = npidb.getConnection() addrs = npidb.gatFacilityAddress(conn, facilityId) for atuple in addrs: addressKList.append( Address(atuple[0], atuple[1] + " " + atuple[2], atuple[3], atuple[4], atuple[5], msg='FacilityAddress')) return (facilityId, name, npi, addressKList, totalPhysicians)
def testAddrToKeyStr(self): print('testAddrToKeyStr') a1 = Address('PO BOX 12345', 'l2', 'c', 's', 'z', 'n') self.assertEqual('12345 BOX C L2 PO S Z0000', a1.tokeystr()) self.assertEqual('0000 12345 BOX C L2 PO S Z0000', a1.tokeystr(usezip4=True)) a1 = Address('PO BOX 12345', 'l&2', 'c', 's', 'z', 'n') self.assertEqual('12345 2 BOX C L PO S Z0000', a1.tokeystr()) self.assertEqual('0000 12345 2 BOX C L PO S Z0000', a1.tokeystr(usezip4=True))
def testSearchAddrOrig(self): conn = npidb.getConnection() anAddr = Address('2615 NE LOOP 286', '', 'PARIS', 'TX', '75460') r = npidb.searchAddrInOrig(conn, anAddr) self.assertTrue(len(r) > 0) ra = r[0] anAddr = Address("601 CHATHAM MEDICAL PARK", "", "ELKIN", "NC", "28621") r = npidb.searchAddrInOrig(conn, anAddr) self.assertTrue(len(r) == 0) print(ra)
def testDistance(self): print('testDistance') a1 = Address('a', 'b', 'c', 's', 'z', 'n') a2 = Address('a', 'b', 'c', 's', 'z', 'n') dist = Distance(a1, a2) self.assertTrue(dist.isMatched()) a1 = Address('7500 SMOKE RANCH RD STE 200', '', 'LASVEGAS', 'NV', '891280000') a2 = Address('500 SMOKE RANCH RD', 'STE 200', 'LAS VEGAS', 'NV', '89128,0373') dist = Distance(a1, a2) print(dist.detail()) self.assertTrue(dist.isMatched())
def test2147219403(self): print("test2147219403") addr = Address('CARR. 21 S3 LAS LOMAS BO. MONACILLOS', 'OFFICE # 2', 'SAN JUAN', 'PR', '00956') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219403', msg[0]) self.assertEqual( 'Multiple addresses were found for the information you entered, and no default exists.', msg[1]) addr = Address('1218 SOUTH OLIVE AVE.', '', 'WEST PALM BEACH', 'FL', '33401') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219403', msg[0]) self.assertEqual( 'Multiple addresses were found for the information you entered, and no default exists.', msg[1]) addr = Address('1218 S OLIVE AVE.', '', 'WEST PALM BEACH', 'FL', '33401') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219403', msg[0]) self.assertEqual( 'Multiple addresses were found for the information you entered, and no default exists.', msg[1]) addr = Address('25 N. WINFIELD RD.', '', 'WINFIELD', 'IL', '60190') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219403', msg[0]) self.assertEqual( 'Multiple addresses were found for the information you entered, and no default exists.', msg[1]) addr = Address('25 WINFIELD RD.', '', 'WINFIELD', 'IL', '60190') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219403', msg[0]) self.assertEqual( 'Multiple addresses were found for the information you entered, and no default exists.', msg[1])
def testPOBOXDistance(self): print('testPOBOXDistance') a1 = Address('PO BOX 12345', '', 'c', 's', 'z', 'n') self.assertTrue(a1.isPOBox()) a2 = Address('PO BOX 67890', '', 'c', 's', 'z', 'n') self.assertTrue(a1.isPOBox()) dist = Distance(a1, a2) print(dist.detail()) a1 = Address('PO BOX 12345', '', 'c', 's', 'z', 'n') self.assertTrue(a1.isPOBox()) a2 = Address('PO BOX 92345', '', 'c', 's', 'z', 'n') self.assertTrue(a1.isPOBox()) dist = Distance(a1, a2) print(dist.detail())
def test2147219402(self): print("test2147219402") addr = Address('872 RED OAK AVE', '', 'LONDON', 'ONTARIO', 'N6H 5') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219402', msg[0]) self.assertEqual('Invalid State Code. ', msg[1]) addr = Address('HHC 121ST GENERAL HOSPITAL', 'BOX 675', 'APO', 'KOREA', 'AP000') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219402', msg[0]) self.assertEqual('Invalid State Code. ', msg[1])
def test2147219400(self): print("test2147219400") addr = Address('131-1 KAMEYACHO KOJINGUCHIDORI, VANTARISE 1-E', 'KAMIGYOKU', 'KYOTO', 'KYOTO', '60208') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219400', msg[0]) self.assertEqual('Invalid City. ', msg[1]) addr = Address('100 N ACADEMY AVE', '', 'PENNSYLVANIA', 'PA', '17822') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219400', msg[0]) self.assertEqual('Invalid City. ', msg[1])
def test2147219399(self): print("test2147219399") addr = Address('CONTRA CORNOLEO 11', '', 'VICENZA', 'VICENZA', '36100') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219399', msg[0]) self.assertEqual('Invalid Zip Code. ', msg[1]) addr = Address('VIA VINCENZO DI MARCO #29', '', 'PALERMO', 'PA', '90143') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219399', msg[0]) self.assertEqual('Invalid Zip Code. ', msg[1])
def rewriteAddr1Addr2(addr): newAddr = Address(addr.addr1, addr.addr2, addr.city, addr.state, addr.zip5); lex = AddressLexical(addr.addr1, addr.addr2); lex.replaceAbbr(); newAddr.addr1 = lex.addr1; newAddr.addr2 = lex.addr2; return newAddr;
def test80040B19(self): print("test80040B19") addr = Address('US HWY 160 & NAVAJO ROUTE 25 - RED MESA', '', 'TEECNOSPOS', 'AZ', '86514') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('80040B19', msg[0]) self.assertEqual( "XML Syntax Error: Please check the XML request to see if it can be parsed.", msg[1]) addr = Address('US HWY 160 and NAVAJO ROUTE 25 - RED MESA', '', 'TEECNOSPOS', 'AZ', '86514') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg)
def test80040B18(self): print("test80040B18") addr = Address('112 N 7TH ST', 'CHAMBERSBURG HOSPITAL-PHYSICAL MEDICINE DEPARTMENT', 'CHAMBERSBURG', 'PA', '17201') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg)
def test2147219401(self): print("test2147219401") addr = Address('113 HILLCREST DRE', '', 'SANFORD', 'NC', '27330') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219401', msg[0]) self.assertEqual('Address Not Found. ', msg[1])
def test2147219396(self): print("test2147219396") addr = Address('1 MEDICAL CENTER BLVD', 'POB I, SUITE 407', 'CHESTER', 'PA', '19013') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219396', msg[0]) self.assertEqual('Invalid Address. ', msg[1])
def packInfo(record): addressKList = [] name = record[4] npi = record[6] facilityId = record[0] if record[7] != None: addr = Address(record[7], record[8] + ' ' + record[9], record[10], record[11], record[12], record[14]) else: addr = None addressKList.append(addr) conn = npidb.getConnection() addrs = npidb.gatFacilityAddress(conn, facilityId) for atuple in addrs: addressKList.append( Address(atuple[0], atuple[1] + " " + atuple[2], atuple[3], atuple[4], atuple[5])) return (name, npi, addressKList)
def testFirmNameAndCity(self): print('testFirmNameAndCity') addr = Address('DIAGNOSTIC IMAGING SO NV', '', 'LAS VEGAS', 'NV', '89121') print(addr) aa, msg, alt = verify_by_google.reqGoogle(addr) for ga in alt: print(ga) print(Distance(addr, ga))
def testReturnFirmName(self): print('testReturnFirmName') addr = Address('DEPT 52519 PO BOX 950123', '', 'LOUISVILLE', 'KY', '402950000') print(addr) aa, msg, alt = verify_by_google.reqGoogle(addr) for ga in alt: print(ga) print(Distance(addr, ga))
def reqGoogle(addr): qs = buildGoogleReq(addr) #print ("qs = ", qs) #print (qs) r1 = urllib.request.urlopen(qs) #conn.request("GET", qs) #r1 = conn.getresponse() #print (r1.status, r1.reason) if r1.status != 200: return (None, (r1.status, r1.reason), []) #b'aaa'.encode(encoding='utf_8') result = r1.read().decode("utf-8") #print(result) resp = json.loads(result) #print (resp['status']) allReturnAddr = [] for r in resp['results']: #print ( r['formatted_address']) words = r['formatted_address'].upper().split(',') #print (words) if len(words) < 4: print() print(addr) print(words) print('This is not detail address, ignored.') continue nation = words[-1].strip() sp5 = words[-2].strip().split() if len(sp5) >= 1: s = sp5[0].strip() else: s = '--' if len(sp5) >= 2: p5 = sp5[1].strip() else: p5 = '00000' city = words[-3].strip() addr = words[-4].strip() newAddr = Address(addr, '', city, s, p5, nation) newAddr.placeid = r['place_id'] newAddr.lat = r['geometry']['location']['lat'] newAddr.lng = r['geometry']['location']['lng'] allReturnAddr.append(newAddr) if len(allReturnAddr) > 0: selected = allReturnAddr[0] else: selected = None return (selected, 'OK', allReturnAddr)
def testName(self): for a in addresses: print() ws = a.split(',') addr = Address(ws[0], ws[1], ws[2], ws[3], ws[4]) print(addr) aa, msg, alt = verify_by_google.reqGoogle(addr) for ga in alt: print(ga) print(Distance(addr, ga)) pass
def test2147221202(self): print("test2147221202") addr = Address('UPC CHILDREN&APOS;S HOSPITAL', '3901 BEAUBIEN 4TH FLOOR CARLS BLDG', 'DETROIT', 'MI', '48201') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147221202', msg[0]) self.assertEqual( "Reference to undeclared entity 'APOS'. Line 6, position 28.", msg[1]) addr = Address('UPC CHILDREN APOS HOSPITAL', '3901 BEAUBIEN 4TH FLOOR CARLS BLDG', 'DETROIT', 'MI', '48201') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg) self.assertEqual('-2147219401', msg[0]) self.assertEqual("Address Not Found. ", msg[1])
def testFirmName2(self): print('testFirmName2') addr = Address('6644 BAYWOOD AVE', '', 'MESA', 'AZ', '85206') print(addr) aa, msg, alt = verify_by_google.reqGoogle(addr) for ga in alt: print(ga) print(Distance(addr, ga).detail()) print('placeid :', ga.placeid) verify_by_google.reqPlaceDetail(ga.placeid) verify_by_google.reqSearch(ga.lat, ga.lng, 'BANNER BAYWOOD MEDICAL')
def wrongAbbr(addr): a1w = addr.addr1.split(); replaceWords = {} for w in a1w : w = w.strip(' .#'); if len(w) <= 4: dt = {}; for abbr in USMailAddress.suffixes : d = fuzz.ratio(w, abbr); dt[d] = abbr; dmax = max(dt.keys()); if dmax > 70 and dmax < 100: print (dmax, dt[dmax], w) replaceWords[w] = dt[dmax] continue; newstr = addr.addr1; for ow in replaceWords : nw = replaceWords[ow] newstr = newstr.replace(ow, nw); newAddr = Address(newstr, addr.addr2, addr.city, addr.state, addr.zip5 + addr.zip4); return newAddr;
def testAddrDistance(self): a1 = Address('90 MEMORIAL DR', '', 'PINEHURST', 'NC', '28374') a2 = Address('205 PAGE RD', '', 'PINEHURST', 'NC', '28374') print(Distance(a1, a2).detail())
def reqUSPS(addr): qs = urlString + urllib.parse.quote(buildxml(addr)) try: r1 = urllib.request.urlopen("http://production.shippingapis.com/" + qs) except socket.error: return (None, ('timeout', 'timeout')) #print (qs) #conn.request("GET", qs) #r1 = conn.getresponse() #print (r1.status, r1.reason) if r1.status != 200: return (None, (r1.status, r1.reason)) result = r1.read() dom = parseString(result) #conn.close() #print (result) bb = dom.getElementsByTagName('Error') if len(bb) > 0: #print( dom.toprettyxml()); errCode = getText(dom, 'Number') errDesc = getText(dom, 'Description') return (None, (errCode, errDesc)) #print ('********') a1 = getText(dom, 'Address2') if a1 == None: a1 = '' a2 = getText(dom, 'Address1') if a2 == None: a2 = '' c = getText(dom, 'City') if c == None: c = '' s = getText(dom, 'State') if s == None: s = '' z5 = getText(dom, 'Zip5') if z5 == None: z5 = '-----' z4 = getText(dom, 'Zip4') if z4 != None and z4 != '' and len(addr.zip4) == 4: pass else: z4 = '----' fn = getText(dom, 'FirmName') if fn == None: fn = '' #return (Address(a1, a2, c, s, z5 + z4), dom.toprettyxml(), distance); return (Address(a1.upper(), a2.upper(), c.upper(), s.upper(), z5.upper() + z4.upper(), msg=fn), '')
def replaceunctuation(addr): tranmap = str.maketrans('-#.&', ' ') a1 = addr.addr1.translate(tranmap) a2 = addr.addr2.translate(tranmap) return Address(a1, a2, addr.city, addr.state, addr.zip5 + addr.zip4);
Provider_First_Line_Business_Mailing_Address, Provider_Second_Line_Business_Mailing_Address, Provider_Business_Mailing_Address_City_Name, Provider_Business_Mailing_Address_State_Name, Provider_Business_Mailing_Address_Postal_Code, Provider_First_Line_Business_Practice_Location_Address, Provider_Second_Line_Business_Practice_Location_Address, Provider_Business_Practice_Location_Address_City_Name, Provider_Business_Practice_Location_Address_State_Name, Provider_Business_Practice_Location_Address_Postal_Code ''' zscList = vbox.uniqZSCList() print('check in %d city/state/zip5 group' % len(zscList)) resultset = npidb.searchNameByMZSC(conn, zscList) for row in resultset: mailAddr = Address(row[3], row[4], row[5], row[6], row[7]) practAddr = Address(row[8], row[9], row[10], row[11], row[12]) lastUdt = row[13] isSoleProprietor = row[14] vbox.add(row[0] + ', PN:', row[1], mailAddr, practAddr, (lastUdt, isSoleProprietor)) if row[2] != '': vbox.add(row[0] + ', ON:', row[2], mailAddr, practAddr, (lastUdt, isSoleProprietor)) print('total cost for this db access : %6.2f sec' % (time.time() - dbaccessstart)) result = vbox.choice() vbox.show(result) print('total cost for this record : %6.2f sec' %
def testAddrDistance(self): print('testAddrDistance') a1 = Address('488 SAINT LUKES DR', '', 'MONTGOMERY', 'AL', '361170000') a2 = Address('488 SAINT LUKES DR', '', 'MONTGOMERY', 'AL', '361177104') print(Distance(a1, a2).detail())
def testT(self): print("testT") addr = Address('1014 NE 7TH ST', '', 'GRANTS PASS', 'OR', '97526') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg)
def testEq(self): self.assertEqual('a', 'a') self.assertNotEqual('a', 'b') a1 = Address('a', 'b', 'c', 's', 'z', 'n') a2 = Address('a', 'b', 'c', 's', 'z', 'n') a3 = Address('b', 'a', 'c', 's', 'z', 'n') a4 = Address('c', 'a', 'c', 's', 'z', 'n') self.assertEqual(a1, a2) self.assertEqual(a1, a3) self.assertEqual(a2, a3) self.assertNotEqual(a1, a4) self.assertNotEqual(Address('a', 'b', 'c1', 's', 'z', 'n'), Address('a', 'b', 'c', 's', 'z', 'n')) self.assertNotEqual(Address('a', 'b', 'c', 's1', 'z', 'n'), Address('a', 'b', 'c', 's', 'z', 'n')) self.assertNotEqual(Address('a', 'b', 'c', 's', 'z1', 'n'), Address('a', 'b', 'c', 's', 'z', 'n')) self.assertNotEqual(Address('a', 'b', 'c', 's', 'z', 'n1'), Address('a', 'b', 'c', 's', 'z', 'n')) self.assertNotEqual(Address('a', 'b', 'c1', 's', 'z', 'n'), Address('a', 'b', 'c', 's', 'z')) self.assertNotEqual(Address('a', 'b', 'c', 's', 'z', 'n'), 'a') self.assertNotEqual(Address('a', 'b', 'c', 's', 'z', 'n'), None) self.assertNotEqual(None, Address('a', 'b', 'c', 's', 'z', 'n')) pass
def testF(self): print("testF") addr = Address('680 S WILTON PL', '', 'LOS ANGELES', 'CA', '90005') result, msg = verify_by_usps.reqUSPS(addr) print(result) print(msg)