| 893 | | protected void formatDoctorName(XCN doctor, Provider provider) |
|---|
| 894 | | { |
|---|
| 895 | | String firstName = ""; |
|---|
| 896 | | String lastName = ""; |
|---|
| 897 | | if (doctor.getGivenName()!= null){ |
|---|
| 898 | | firstName = doctor.getGivenName().toString(); |
|---|
| 899 | | if (firstName == null) firstName = ""; |
|---|
| 900 | | } |
|---|
| 901 | | if (doctor.getGivenName()!= null){ |
|---|
| 902 | | lastName = doctor.getFamilyName().getSurname().toString(); |
|---|
| 903 | | if (lastName == null) lastName = ""; |
|---|
| 904 | | } |
|---|
| 905 | | provider.setFirstName(firstName); |
|---|
| 906 | | provider.setLastName(lastName); |
|---|
| 907 | | } |
|---|
| 908 | | |
|---|
| 909 | | public Provider setProviderFromPV1(PV1 pv1,Patient hl7Patient, |
|---|
| 910 | | Date encounterDate) { |
|---|
| | 882 | public Provider setProviderFromPV1(PV1 pv1,Patient hl7Patient) { |
|---|
| | 891 | |
|---|
| | 892 | |
|---|
| | 893 | //Load provider object with PV1 information |
|---|
| | 894 | |
|---|
| | 895 | if (doctor != null){ |
|---|
| | 896 | |
|---|
| | 897 | String id = ""; |
|---|
| | 898 | String firstName = ""; |
|---|
| | 899 | String lastName = ""; |
|---|
| | 900 | |
|---|
| | 901 | if (doctor.getIDNumber()!= null){ |
|---|
| | 902 | id = doctor.getIDNumber().toString(); |
|---|
| | 903 | } |
|---|
| | 904 | if (doctor.getGivenName()!= null){ |
|---|
| | 905 | firstName = doctor.getGivenName().toString(); |
|---|
| | 906 | } |
|---|
| | 907 | if (doctor.getGivenName()!= null){ |
|---|
| | 908 | lastName = doctor.getFamilyName().getSurname().toString(); |
|---|
| | 909 | } |
|---|
| | 910 | |
|---|
| | 911 | provider.setFirstName(firstName); |
|---|
| | 912 | provider.setLastName(lastName); |
|---|
| | 913 | provider.setId(id); |
|---|
| | 914 | //using npi for provider id |
|---|
| | 915 | SocketHL7ListenerService hl7ListService = (SocketHL7ListenerService) Context.getService(SocketHL7ListenerService.class); |
|---|
| | 916 | if (id == null ||id.equals("")){ |
|---|
| | 917 | String npi = hl7ListService.getNPI(provider.getFirstName(),provider.getLastName()); |
|---|
| | 918 | provider.setId(npi); |
|---|
| | 919 | } |
|---|
| | 920 | |
|---|
| | 921 | provider.createUserForProvider(provider); |
|---|
| | 922 | setPatientMatchingAttribute(provider, hl7Patient); |
|---|
| | 923 | |
|---|
| | 924 | |
|---|
| | 925 | } |
|---|
| | 926 | |
|---|
| 922 | | |
|---|
| 923 | | //Load provider object with PV1 information |
|---|
| 924 | | |
|---|
| 925 | | if (doctor != null){ |
|---|
| 926 | | |
|---|
| 927 | | String id = ""; |
|---|
| 928 | | |
|---|
| 929 | | if (doctor.getIDNumber()!= null){ |
|---|
| 930 | | id = doctor.getIDNumber().toString(); |
|---|
| 931 | | if (id == null) id = ""; |
|---|
| 932 | | } |
|---|
| 933 | | |
|---|
| 934 | | provider.setId(id); |
|---|
| 935 | | formatDoctorName(doctor,provider); |
|---|
| 936 | | provider.createUserForProvider(provider); |
|---|
| 937 | | //using npi for provider id |
|---|
| 938 | | SocketHL7ListenerService hl7ListService = (SocketHL7ListenerService) Context.getService(SocketHL7ListenerService.class); |
|---|
| 939 | | String npi = hl7ListService.getNPI(provider.getFirstName(),provider.getLastName()); |
|---|
| 940 | | provider.setId(npi); |
|---|
| 941 | | |
|---|
| 942 | | try { |
|---|
| 943 | | //May not need this attribute after storing provider as a user. |
|---|
| 944 | | PersonAttributeType providerIDAttrType = personService.getPersonAttributeType(PROVIDER_ID); |
|---|
| 945 | | if (providerIDAttrType == null){ |
|---|
| 946 | | createAttributeType(PROVIDER_ID); |
|---|
| 947 | | } |
|---|
| 948 | | PersonAttribute providerID = new PersonAttribute(providerIDAttrType,provider.getId()); |
|---|
| 949 | | providerID.setDateCreated(encounterDate); |
|---|
| 950 | | //providerID.setDateChanged(encounterDate); |
|---|
| 951 | | providerID.setCreator(Context.getAuthenticatedUser()); |
|---|
| 952 | | hl7Patient.addAttribute(providerID); |
|---|
| 953 | | |
|---|
| 954 | | PersonAttributeType providerNameAttrType = personService.getPersonAttributeType(PROVIDER_NAME); |
|---|
| 955 | | if (providerNameAttrType == null){ |
|---|
| 956 | | createAttributeType(PROVIDER_NAME); |
|---|
| 957 | | } |
|---|
| 958 | | |
|---|
| 959 | | PersonAttribute providerNameAttr = new PersonAttribute(providerNameAttrType,provider.getFirstName() |
|---|
| 960 | | + "." + provider.getLastName()); |
|---|
| 961 | | providerNameAttr.setDateCreated(encounterDate); |
|---|
| 962 | | providerNameAttr.setCreator(Context.getAuthenticatedUser()); |
|---|
| 963 | | hl7Patient.addAttribute(providerNameAttr); |
|---|
| 964 | | |
|---|
| 965 | | //Add to the attribute string used for matching |
|---|
| 966 | | //TODO If id is empty in the hl7 message, do we want to add |
|---|
| 967 | | //add that empty string for drid, or do we want to use |
|---|
| 968 | | //the referenced npi value? |
|---|
| 969 | | //concatMatchingAttribute("drid", id); |
|---|
| 970 | | concatMatchingAttribute("drid", provider.getId()); |
|---|
| 971 | | concatMatchingAttribute("drfn", provider.getFirstName()); |
|---|
| 972 | | concatMatchingAttribute("drln", provider.getLastName()); |
|---|
| 973 | | |
|---|
| 974 | | //Create the attribute type |
|---|
| 975 | | PersonAttributeType otherMatchingAttrType = personService.getPersonAttributeType(MATCH_INFO); |
|---|
| 976 | | if (otherMatchingAttrType == null){ |
|---|
| 977 | | createAttributeType(MATCH_INFO); |
|---|
| 978 | | } |
|---|
| 979 | | //Add the attribute type |
|---|
| 980 | | PersonAttribute matchingInfoAttribute = new PersonAttribute(otherMatchingAttrType,personAttrList); |
|---|
| 981 | | //matchingInfoAttribute.setDateChanged(encounterDate); |
|---|
| 982 | | matchingInfoAttribute.setDateCreated(encounterDate); |
|---|
| 983 | | matchingInfoAttribute.setCreator(Context.getAuthenticatedUser()); |
|---|
| 984 | | hl7Patient.addAttribute(matchingInfoAttribute); |
|---|
| 985 | | |
|---|
| 986 | | } catch (RuntimeException e) { |
|---|
| 987 | | logger.error("Unable to create attribute for provider id or provider name " + e.getMessage()); |
|---|
| 988 | | } |
|---|
| 989 | | } |
|---|
| | 989 | |
|---|
| | 990 | public String setPatientMatchingAttribute(Provider provider, Patient p){ |
|---|
| | 991 | String mrn = "", attribute = "", drid = "" , |
|---|
| | 992 | drfn = "", drln = "", nkfn = "", nkln = "", |
|---|
| | 993 | db = "", yb = "", mb = "", fn = "", ln = "", |
|---|
| | 994 | city = "", zip = "", st = "", race = "", tel = "", |
|---|
| | 995 | sex = "" , nkname = ""; |
|---|
| | 996 | |
|---|
| | 997 | |
|---|
| | 998 | if (provider != null){ |
|---|
| | 999 | drid = provider.getId(); |
|---|
| | 1000 | drfn = provider.getFirstName(); |
|---|
| | 1001 | drln = provider.getLastName(); |
|---|
| | 1002 | } |
|---|
| | 1003 | |
|---|
| | 1004 | fn = p.getGivenName(); |
|---|
| | 1005 | ln = p.getFamilyName(); |
|---|
| | 1006 | sex = p.getGender(); |
|---|
| | 1007 | if (p.getAttribute(ATTRIBUTE_RACE) != null){ |
|---|
| | 1008 | race = p.getAttribute(ATTRIBUTE_RACE).getValue().toLowerCase(); |
|---|
| | 1009 | } |
|---|
| | 1010 | if (p.getAttribute(ATTRIBUTE_TELEPHONE) != null) { |
|---|
| | 1011 | tel = p.getAttribute(ATTRIBUTE_TELEPHONE).getValue().toLowerCase(); |
|---|
| | 1012 | } |
|---|
| | 1013 | if (p.getPatientIdentifier()!= null) { |
|---|
| | 1014 | mrn = p.getPatientIdentifier().getIdentifier(); |
|---|
| | 1015 | } |
|---|
| | 1016 | if (p.getAttribute(ATTRIBUTE_NEXT_OF_KIN) != null){ |
|---|
| | 1017 | nkname = p.getAttribute(ATTRIBUTE_NEXT_OF_KIN).getValue().toLowerCase(); |
|---|
| | 1018 | } |
|---|
| | 1019 | int index = nkname.indexOf("|"); |
|---|
| | 1020 | if (index > 0){ |
|---|
| | 1021 | nkfn = nkname.substring(0,index); |
|---|
| | 1022 | nkln = nkname.substring(index + 1); |
|---|
| | 1023 | }else { |
|---|
| | 1024 | nkln = nkname; |
|---|
| | 1025 | } |
|---|
| | 1026 | |
|---|
| | 1027 | if (p.getPersonAddress()!= null){ |
|---|
| | 1028 | city = p.getPersonAddress().getCityVillage().toLowerCase(); |
|---|
| | 1029 | zip = p.getPersonAddress().getPostalCode().toLowerCase(); |
|---|
| | 1030 | st = p.getPersonAddress().getStateProvince().toLowerCase(); |
|---|
| | 1031 | } |
|---|
| | 1032 | |
|---|
| | 1033 | |
|---|
| | 1034 | Calendar cal = Calendar.getInstance(); |
|---|
| | 1035 | cal.setTime(p.getBirthdate()); |
|---|
| | 1036 | yb = Integer.toString(cal.get(Calendar.YEAR)); |
|---|
| | 1037 | mb = Integer.toString(cal.get(Calendar.MONTH ) + 1); |
|---|
| | 1038 | db = Integer.toString(cal.get(Calendar.DAY_OF_MONTH)); |
|---|
| | 1039 | attribute = "mrn:" + mrn + ";fn:" + fn + ";ln:" + ln + ";race:" |
|---|
| | 1040 | + race + ";nkfn:" + nkfn + ";nkln:" + nkln + ";db:" + db |
|---|
| | 1041 | + ";mb:" + mb + ";yb:" + yb + ";sex:" + sex + ";city:" |
|---|
| | 1042 | + city + ";st:" + st + ";zip:" + zip + ";tel:" + tel |
|---|
| | 1043 | + ";drid:" + drid + ";drfn:" + drfn + ";drln:" + drln; |
|---|
| | 1044 | |
|---|
| | 1045 | |
|---|
| | 1046 | PersonAttributeType otherMatchingAttrType = personService.getPersonAttributeType(MATCH_INFO); |
|---|
| | 1047 | |
|---|
| | 1048 | if (otherMatchingAttrType == null){ |
|---|
| | 1049 | createAttributeType(MATCH_INFO); |
|---|
| | 1050 | } |
|---|
| | 1051 | |
|---|
| | 1052 | PersonAttribute matchingInfoAttribute = new PersonAttribute(otherMatchingAttrType,attribute); |
|---|
| | 1053 | p.addAttribute(matchingInfoAttribute); |
|---|
| | 1054 | return attribute; |
|---|
| | 1055 | } |
|---|
| | 1056 | |
|---|