Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/09/08 18:54:25 (8 months ago)
Author:
msheley
Message:

sockethl7listener --
* Adjustments for blank name and address fields in hl7
* Added handling messages that have no date/times for encounters
* Moved location where createObsForProvider is called.
* Modified logging

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/sockethl7listener/src/org/openmrs/module/sockethl7listener/MatchHandler.java

    r4133 r4159  
    8787            PersonAttribute bestNKAttribute = getBestNK(hl7Patient, resolvedPatient, encounterDate); 
    8888            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                } 
    9092                resolvedPatient.addAttribute(bestNKAttribute); 
    9193            } else { 
     
    9597                PersonAttribute bestTelephoneAttr = getBestTel( hl7Patient, resolvedPatient, encounterDate); 
    9698                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                        } 
    98102                        resolvedPatient.addAttribute(bestTelephoneAttr); 
    99103                } else { 
     
    196200                else if ( ! existingPreferredAddr.getDateCreated().after(hl7Address.getDateCreated())){ 
    197201                        //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                        } 
    198223                        bestAddress = hl7Address; 
    199224                        bestAddress.setDateCreated(encounterDate); 
     
    388413        PersonAttribute hl7Attr = hl7Patient.getAttribute(MATCH_INFO); 
    389414        
    390      
     415         
    391416        String hl7Provln = ""; 
    392417        String hl7Provid = ""; 
     
    395420                String resProvfn = ""; 
    396421                String resProvid = ""; 
     422                String hl7String = ""; 
     423                String matchString = ""; 
    397424         
    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                } 
    403432        } 
    404433         
    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            } 
    411441        } 
    412442         
     443         
     444         
    413445                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); 
    416457                        bestProvider.setFirstName(hl7Provfn); 
    417                         bestProvider.setFirstName(hl7Provid); 
     458                        bestProvider.setId(hl7Provid); 
    418459 
    419460        } else if (matchedAttr.getDateCreated().compareTo( 
     
    431472        } 
    432473 
    433         private PersonName parseProviderName(PersonAttribute provNameAttr) { 
    434                  
    435                 String ProvNameValue = provNameAttr.getValue(); 
     474        private PersonName parseNKName(PersonAttribute NKNameAttr) { 
    436475                String firstname = ""; 
    437476                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                         
    464488                } 
    465489                 
     
    677701                String inputfnRaw = matching_input.substring(index2+1,index3); 
    678702                String inputfn = inputfnRaw; 
    679                 if (inputfnRaw == null ||inputfnRaw.equals("")){ 
    680                         inputfn = "(Nullified)"; 
    681                 } 
     703                 
    682704                 
    683705                String inputIdent = getAttributeComponent(matching_input, "mrn"); 
     
    760782                } 
    761783                 
    762                 String resCity, resState, resZip, resAddr1
     784                String resCity = "", resState = "", resZip = "", resAddr1 = ""
    763785                if (PA != null) { 
    764                         if ((resAddr1 = PA.getAddress1())==null){ 
     786                        resAddr1 = PA.getAddress1(); 
     787                        if (resAddr1 == null  ){ 
    765788                                resAddr1 = ""; 
    766789                        } 
    767                         if ((resCity = PA.getCityVillage())== null){ 
     790                        resCity = PA.getCityVillage(); 
     791                        if (resCity == null){ 
    768792                                resCity = ""; 
    769793                        } 
    770                         if ((resState = PA.getStateProvince())== null){ 
     794                        resState = PA.getStateProvince(); 
     795                        if (resState == null){ 
    771796                                resState = ""; 
    772797                        } 
    773                         if ((resZip = PA.getPostalCode())== null){ 
     798                        resZip = PA.getPostalCode(); 
     799                        if (resZip == null){ 
    774800                                resZip = ""; 
    775801                        } 
    776802                         
    777                 }else{ 
    778                         resAddr1 = ""; 
    779                         resCity = ""; 
    780                         resState = ""; 
    781                         resZip = ""; 
    782803                } 
    783804                 
     
    788809                String resRace  = raceAttr == null? "" : raceAttr.getValue(); 
    789810                 
    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()){ 
    795814                        if (pn.getPreferred()) { 
    796815                                fName = pn.getGivenName(); 
     
    798817                                 
    799818                        } 
    800                 } 
     819                }*/ 
    801820                 
    802821                 
     
    835854                         
    836855                         
    837                          
     856                        matchLogger.error("Result attribute string: \r\n"  
     857                                        + resolvedPatient.getAttribute(MATCH_INFO)); 
    838858                        matchLogger.error(mrn + fn + ln + gender +  city + state + zip + db + mb + yb + tel + nkfn + nkln + drid + drfn + drln + openmrs_id); 
    839859                } catch (IllegalFormatException e) { 
     
    856876                if (bestIdentifier != null) { 
    857877                        resolvedPatientMRN = bestIdentifier.getIdentifier(); 
     878                        if (resolvedPatientMRN == null) resolvedPatientMRN = ""; 
    858879                } 
    859880                 
     
    866887                if (bestName != null) { 
    867888                        firstName = bestName.getGivenName(); 
     889                        if (firstName == null) firstName = ""; 
    868890                        bestFamilyName = bestName.getFamilyName(); 
     891                        if (bestFamilyName == null) bestFamilyName = ""; 
    869892                } 
    870893                resultMatchingAttribute = resultMatchingAttribute.replaceAll( 
     
    876899                // gender 
    877900                // If hl7 gender is null, use the matchedPatient results. 
     901                if (correctGender == null) correctGender = ""; 
    878902                resultMatchingAttribute = resultMatchingAttribute.replaceAll( 
    879903                                        ";sex:[^;]{0,};", ";sex:" + correctGender 
     
    899923                // Provider ID 
    900924                // 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                 
    901933                resultMatchingAttribute = resultMatchingAttribute.replaceAll( 
    902934                                ";drid:[^;]{0,};", ";drid:" + prov.getId() + ";"); 
     
    904936                                ";drfn:[^;]{0,};", ";drfn:" + prov.getFirstName() + ";"); 
    905937                resultMatchingAttribute = resultMatchingAttribute.replaceAll( 
    906                                 ";drln:[^;]{0,};", ";drln:" + prov.getLastName() + ";"); 
     938                                ";drln:[^;]{0,}", ";drln:" + prov.getLastName() + ";"); 
    907939 
    908940                // Address 
     
    910942                if (bestAddress != null) { 
    911943                        city = bestAddress.getCityVillage(); 
     944                        if (city == null) city = ""; 
    912945                        st = bestAddress.getStateProvince(); 
     946                        if (st == null) st = ""; 
    913947                        zip = bestAddress.getPostalCode(); 
     948                        if (zip == null) zip = ""; 
    914949                } 
    915950 
     
    930965                  nkfn = nkname.substring(0,index); 
    931966                  nkln = nkname.substring(index + 1); 
     967                   
    932968                }else { 
    933969                        nkln = nkname; 
    934970                } 
     971                if (nkfn == null) nkfn = ""; 
     972                if (nkln == null) nkln = ""; 
     973                 
    935974                resultMatchingAttribute = resultMatchingAttribute.replaceAll( 
    936975                                ";nkfn:[^;]{0,};", ";nkfn:" + nkfn + ";");