}
return null;
}
private ArrayList<AuditDetails> unionEMC(Client dst, Client src) throws ClipsServerException {
Emc emc1 = null;
Emc emc2 = null;
List<Emc> emcL = findEntityList(Emc.class, "client.id", src.getId());
if (!emcL.isEmpty()) {
emc2 = emcL.get(0);
}
else {
return null;
}
emcL = findEntityList(Emc.class, "client.id", dst.getId());
if (emcL.isEmpty()) {
AuditDoc<Emc> auditEmc = new AuditDoc<Emc>(emc2, getCollaborator());
emc2.setClient(dst);
saveEntity(emc2);
System.out.println(" EMC2=" + emc2.getId() + "-->cl=" + emc2.getClient().getId());
auditEmc.check(emc2);
ArrayList<AuditDetails> target = new ArrayList<AuditDetails>(1);
target.add(persistAudit(auditEmc));
return target;
} else {
ArrayList<AuditDetails> target = new ArrayList<AuditDetails>();
emc1 = emcL.get(0);
AuditDoc<Emc> auditEmc = new AuditDoc<Emc>(emc1, getCollaborator());
System.out.println(" EMC1 id=" + emc1.getId() + " №" + emc1.getNumber() + " | EMC2 id=" + emc2.getId() + " №" + emc2.getNumber());
if (emc1.getNumber() == null || emc1.getNumber().isEmpty()) {
emc1.setNumber(emc2.getNumber());
}
if (emc1.getAnamnez() == null || emc1.getAnamnez().isEmpty()) {
emc1.setAnamnez(emc2.getAnamnez());
}
saveEntity(emc1);
auditEmc.check(emc1);
target.add(persistAudit(auditEmc));
List<Disease> disL = findEntityList(Disease.class, "emc.id", emc2.getId());
for (Disease d : disL) {
AuditDoc<Disease> auditDisease = new AuditDoc<Disease>(d, getCollaborator());
d.setEmc(emc1);
saveEntity(d);
System.out.println(" d.id=" + d.getId() + " d.emc.id" + d.getEmc().getId());