private PatientIdCollection mergePatientIdentifiers(DomainFactory factory, Patient srcPat, Patient destPat) throws SQLException, DomainInterfaceException, StaleObjectException, UniqueKeyViolationException { ims.core.vo.Patient sourcePatient = PatientAssembler.create(srcPat); PatientIdCollection sourceIds = (PatientIdCollection) sourcePatient.getIdentifiers().clone(); srcPat.getIdentifiers().clear(); // Source identifiers moved to destination factory.save(srcPat); // Need to save source pat with no ids before assigning to destination as otherwise, hibernate complains //add (source) identifiers to new (destination) patient for(int i=0;i<sourceIds.size();i++) { PatientId id = (PatientId) sourceIds.get(i).clone(); // wdev-6169 Do not move the nhsn over if it's the same as the nhsn for the destination patient if (id.getType().getId() == PatIdType.NHSN.getID()) { if (getNHSN(destPat.getIdentifiers()).equals(id.getValue())) continue; // wdev-6148 If moving an NHSN value over and it is verified, set it to unverified id.setVerified(false); } // wdev-10710 Only merge the PATNUM identifier if the source is NOT an ICABDummy Patient if (id.getType().getId() == PatIdType.PATNUM.getID()) { if (sourcePatient.getNameIsNotNull() && sourcePatient.getName().getSurnameIsNotNull() && sourcePatient.getName().getSurname().equals(DUMMY_PATIENT)) continue; // Do no insert them } id.setMerged(true); destPat.getIdentifiers().add(PatientIdAssembler.extractPatientId(factory,id)); } return sourceIds; }
private PatientIdCollection mergePatientIdentifiers(DomainFactory factory, Patient srcPat, Patient destPat, boolean icabMergeRequest) throws SQLException, DomainInterfaceException, StaleObjectException, UniqueKeyViolationException { ims.core.vo.Patient sourcePatient = PatientAssembler.create(srcPat); PatientIdCollection sourceIds = (PatientIdCollection) sourcePatient.getIdentifiers().clone(); // WDEV-23955 If merging from ICAB and USE_PATIENT_NUMBER is true, we want to clear the GENERATE_PATID_TYPE from the destination before we start the move from source if (icabMergeRequest && ConfigFlag.DOM.USE_PATIENT_NUMBER.getValue() == true) { // WDEV-23561 - we only want to set this number if an identifier of this type does not exist for the patient. PatIdType patIdType = PatIdType.getNegativeInstance(ConfigFlag.GEN.GENERATE_PATID_TYPE.getValue()); if (patIdType != null) { ims.core.patient.domain.objects.PatientId destPatientId = getIdentifierForType(destPat.getIdentifiers(), patIdType); if (destPatientId != null) destPat.getIdentifiers().remove(destPatientId); } } srcPat.getIdentifiers().clear(); // Source identifiers moved to destination factory.save(srcPat); // Need to save source pat with no ids before assigning to destination as otherwise, hibernate complains //add (source) identifiers to new (destination) patient for(int i=0;i<sourceIds.size();i++) { PatientId id = (PatientId) sourceIds.get(i).clone(); // wdev-6169 Do not move the nhsn over if it's the same as the nhsn for the destination patient if (id.getType().getId() == PatIdType.NHSN.getID()) { if (getNHSN(destPat.getIdentifiers()).equals(id.getIdValue())) // WDEV-23955 - GetIdValue should be used as it does not include spaces continue; // wdev-6148 If moving an NHSN value over and it is verified, set it to unverified id.setVerified(false); } // wdev-10710 Only merge the PATNUM identifier if the source is NOT an ICABDummy Patient if (id.getType().getId() == PatIdType.PATNUM.getID()) { if (sourcePatient.getNameIsNotNull() && sourcePatient.getName().getSurnameIsNotNull() && sourcePatient.getName().getSurname().equals(DUMMY_PATIENT)) continue; // Do no insert them } id.setMerged(true); destPat.getIdentifiers().add(PatientIdAssembler.extractPatientId(factory,id)); } return sourceIds; }