Changeset 4159 for openmrs-modules/sockethl7listener/src/org/openmrs/module/sockethl7listener/MatchHandler.java
- Timestamp:
- 05/09/08 18:54:25 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs-modules/sockethl7listener/src/org/openmrs/module/sockethl7listener/MatchHandler.java
r4133 r4159 87 87 PersonAttribute bestNKAttribute = getBestNK(hl7Patient, resolvedPatient, encounterDate); 88 88 if (bestNKAttribute != null ){ 89 resolvedPatient.getAttribute(ATTRIBUTE_NEXT_OF_KIN).setVoided(true); 89 if (resolvedPatient.getAttribute(ATTRIBUTE_NEXT_OF_KIN) != null){ 90 resolvedPatient.getAttribute(ATTRIBUTE_NEXT_OF_KIN).setVoided(true); 91 } 90 92 resolvedPatient.addAttribute(bestNKAttribute); 91 93 } else { … … 95 97 PersonAttribute bestTelephoneAttr = getBestTel( hl7Patient, resolvedPatient, encounterDate); 96 98 if (bestTelephoneAttr != null ){ 97 resolvedPatient.getAttribute(ATTRIBUTE_TELEPHONE).setVoided(true); 99 if (resolvedPatient.getAttribute(ATTRIBUTE_TELEPHONE) != null){ 100 resolvedPatient.getAttribute(ATTRIBUTE_TELEPHONE).setVoided(true); 101 } 98 102 resolvedPatient.addAttribute(bestTelephoneAttr); 99 103 } else { … … 196 200 else if ( ! existingPreferredAddr.getDateCreated().after(hl7Address.getDateCreated())){ 197 201 //PID is newer or the same date 202 if (hl7Address.getAddress1() == null || hl7Address.getAddress1().equals("") ){ 203 hl7Address.setAddress1(existingPrefAddr1); 204 } 205 if (hl7Address.getAddress2() == null || hl7Address.getAddress2().equals("") ){ 206 hl7Address.setAddress2(existingPrefAddr2); 207 } 208 if (hl7Address.getCityVillage() == null || hl7Address.getCityVillage().equals("") ){ 209 hl7Address.setCityVillage(existingPrefCity); 210 } 211 if (hl7Address.getStateProvince() == null || hl7Address.getStateProvince().equals("") ){ 212 hl7Address.setStateProvince(existingState); 213 } 214 if (hl7Address.getCountry() == null ||hl7Address.getCountry().equals("") ){ 215 hl7Address.setCountry(existingPrefCountry); 216 } 217 if (hl7Address.getPostalCode() == null ||hl7Address.getPostalCode().equals("") ){ 218 hl7Address.setPostalCode(existingPrefPostalCode); 219 } 220 if (hl7Address.getCountyDistrict() == null || hl7Address.getCountyDistrict().equals("")){ 221 hl7Address.setCountyDistrict(existingPrefCounty); 222 } 198 223 bestAddress = hl7Address; 199 224 bestAddress.setDateCreated(encounterDate); … … 388 413 PersonAttribute hl7Attr = hl7Patient.getAttribute(MATCH_INFO); 389 414 390 415 391 416 String hl7Provln = ""; 392 417 String hl7Provid = ""; … … 395 420 String resProvfn = ""; 396 421 String resProvid = ""; 422 String hl7String = ""; 423 String matchString = ""; 397 424 398 String matchString = matchedAttr.getValue(); 399 if (matchString != null){ 400 resProvid = getAttributeComponent(matchString, "drid"); 401 resProvfn = getAttributeComponent(matchString, "drfn"); 402 resProvln = getAttributeComponent(matchString, "drln"); 425 if (matchedAttr != null){ 426 matchString = matchedAttr.getValue(); 427 if (matchString != null){ 428 resProvid = getAttributeComponent(matchString, "drid"); 429 resProvfn = getAttributeComponent(matchString, "drfn"); 430 resProvln = getAttributeComponent(matchString, "drln"); 431 } 403 432 } 404 433 405 String hl7String = hl7Attr.getValue(); 406 407 if (hl7String != null){ 408 hl7Provid = getAttributeComponent(matchString, "drid"); 409 hl7Provfn = getAttributeComponent(matchString, "drfn"); 410 hl7Provln = getAttributeComponent(matchString, "drln"); 434 if (hl7Attr != null){ 435 hl7String = hl7Attr.getValue(); 436 if (hl7String != null){ 437 hl7Provid = getAttributeComponent(hl7String, "drid"); 438 hl7Provfn = getAttributeComponent(hl7String, "drfn"); 439 hl7Provln = getAttributeComponent(hl7String, "drln"); 440 } 411 441 } 412 442 443 444 413 445 if (matchedAttr.getDateCreated().compareTo(encounterDate) <= 0) { 414 // hl7 message date is more recent 415 bestProvider.setFirstName(hl7Provln); 446 // hl7 message date is more recent 447 if (hl7Provfn.equals("")) { 448 hl7Provfn = resProvfn; 449 } 450 if (hl7Provln.equals("")) { 451 hl7Provln = resProvln; 452 } 453 if (hl7Provid.equals("")){ 454 hl7Provid = resProvid; 455 } 456 bestProvider.setLastName(hl7Provln); 416 457 bestProvider.setFirstName(hl7Provfn); 417 bestProvider.set FirstName(hl7Provid);458 bestProvider.setId(hl7Provid); 418 459 419 460 } else if (matchedAttr.getDateCreated().compareTo( … … 431 472 } 432 473 433 private PersonName parseProviderName(PersonAttribute provNameAttr) { 434 435 String ProvNameValue = provNameAttr.getValue(); 474 private PersonName parseNKName(PersonAttribute NKNameAttr) { 436 475 String firstname = ""; 437 476 String lastname = ""; 438 439 int index1 =ProvNameValue.indexOf("."); 440 if (index1 != -1){ 441 firstname = ProvNameValue.substring(0,index1); 442 lastname = ProvNameValue.substring(index1 + 1); 443 }else { 444 firstname = ProvNameValue; 445 } 446 PersonName provName = new PersonName(); 447 provName.setFamilyName(lastname); 448 provName.setGivenName(firstname); 449 450 return provName; 451 452 } 453 454 private PersonName parseNKName(PersonAttribute NKNameAttr) { 455 String NKnameValue = NKNameAttr.getValue(); 456 String firstname = ""; 457 String lastname = ""; 458 int index1 =NKnameValue.indexOf("|"); 459 if (index1 != -1){ 460 firstname = NKnameValue.substring(0,index1); 461 lastname = NKnameValue.substring(index1 + 1); 462 }else { 463 firstname = NKnameValue; 477 if (NKNameAttr != null) { 478 String NKnameValue = NKNameAttr.getValue(); 479 int index1 =NKnameValue.indexOf("|"); 480 if (index1 != -1){ 481 firstname = NKnameValue.substring(0,index1); 482 lastname = NKnameValue.substring(index1 + 1); 483 }else { 484 firstname = NKnameValue; 485 } 486 487 464 488 } 465 489 … … 677 701 String inputfnRaw = matching_input.substring(index2+1,index3); 678 702 String inputfn = inputfnRaw; 679 if (inputfnRaw == null ||inputfnRaw.equals("")){ 680 inputfn = "(Nullified)"; 681 } 703 682 704 683 705 String inputIdent = getAttributeComponent(matching_input, "mrn"); … … 760 782 } 761 783 762 String resCity , resState, resZip, resAddr1;784 String resCity = "", resState = "", resZip = "", resAddr1 = ""; 763 785 if (PA != null) { 764 if ((resAddr1 = PA.getAddress1())==null){ 786 resAddr1 = PA.getAddress1(); 787 if (resAddr1 == null ){ 765 788 resAddr1 = ""; 766 789 } 767 if ((resCity = PA.getCityVillage())== null){ 790 resCity = PA.getCityVillage(); 791 if (resCity == null){ 768 792 resCity = ""; 769 793 } 770 if ((resState = PA.getStateProvince())== null){ 794 resState = PA.getStateProvince(); 795 if (resState == null){ 771 796 resState = ""; 772 797 } 773 if ((resZip = PA.getPostalCode())== null){ 798 resZip = PA.getPostalCode(); 799 if (resZip == null){ 774 800 resZip = ""; 775 801 } 776 802 777 }else{778 resAddr1 = "";779 resCity = "";780 resState = "";781 resZip = "";782 803 } 783 804 … … 788 809 String resRace = raceAttr == null? "" : raceAttr.getValue(); 789 810 790 String fName = ""; 791 String lName= ""; 792 String ident = ""; 793 String test = resolvedPatient.getGivenName(); 794 for (PersonName pn : resolvedPatient.getNames()){ 811 String fName = resolvedPatient.getGivenName(); 812 String lName = resolvedPatient.getFamilyName(); 813 /*for (PersonName pn : resolvedPatient.getNames()){ 795 814 if (pn.getPreferred()) { 796 815 fName = pn.getGivenName(); … … 798 817 799 818 } 800 } 819 }*/ 801 820 802 821 … … 835 854 836 855 837 856 matchLogger.error("Result attribute string: \r\n" 857 + resolvedPatient.getAttribute(MATCH_INFO)); 838 858 matchLogger.error(mrn + fn + ln + gender + city + state + zip + db + mb + yb + tel + nkfn + nkln + drid + drfn + drln + openmrs_id); 839 859 } catch (IllegalFormatException e) { … … 856 876 if (bestIdentifier != null) { 857 877 resolvedPatientMRN = bestIdentifier.getIdentifier(); 878 if (resolvedPatientMRN == null) resolvedPatientMRN = ""; 858 879 } 859 880 … … 866 887 if (bestName != null) { 867 888 firstName = bestName.getGivenName(); 889 if (firstName == null) firstName = ""; 868 890 bestFamilyName = bestName.getFamilyName(); 891 if (bestFamilyName == null) bestFamilyName = ""; 869 892 } 870 893 resultMatchingAttribute = resultMatchingAttribute.replaceAll( … … 876 899 // gender 877 900 // If hl7 gender is null, use the matchedPatient results. 901 if (correctGender == null) correctGender = ""; 878 902 resultMatchingAttribute = resultMatchingAttribute.replaceAll( 879 903 ";sex:[^;]{0,};", ";sex:" + correctGender … … 899 923 // Provider ID 900 924 // PersonAttribute providerAttr 925 String prid = prov.getId(); 926 if (prid == null) prid = ""; 927 String prfn = prov.getFirstName(); 928 if (prfn == null) prfn = ""; 929 String prln = prov.getLastName(); 930 if (prln == null) prln = ""; 931 932 901 933 resultMatchingAttribute = resultMatchingAttribute.replaceAll( 902 934 ";drid:[^;]{0,};", ";drid:" + prov.getId() + ";"); … … 904 936 ";drfn:[^;]{0,};", ";drfn:" + prov.getFirstName() + ";"); 905 937 resultMatchingAttribute = resultMatchingAttribute.replaceAll( 906 ";drln:[^;]{0,} ;", ";drln:" + prov.getLastName() + ";");938 ";drln:[^;]{0,}", ";drln:" + prov.getLastName() + ";"); 907 939 908 940 // Address … … 910 942 if (bestAddress != null) { 911 943 city = bestAddress.getCityVillage(); 944 if (city == null) city = ""; 912 945 st = bestAddress.getStateProvince(); 946 if (st == null) st = ""; 913 947 zip = bestAddress.getPostalCode(); 948 if (zip == null) zip = ""; 914 949 } 915 950 … … 930 965 nkfn = nkname.substring(0,index); 931 966 nkln = nkname.substring(index + 1); 967 932 968 }else { 933 969 nkln = nkname; 934 970 } 971 if (nkfn == null) nkfn = ""; 972 if (nkln == null) nkln = ""; 973 935 974 resultMatchingAttribute = resultMatchingAttribute.replaceAll( 936 975 ";nkfn:[^;]{0,};", ";nkfn:" + nkfn + ";");