/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beans.report;
import framework.beans.report.ReportBeanRemote;
import beans.directory.enterprise.Enterprise;
import framework.beans.HardCodedIDs;
import framework.beans.config.server.ConfigBeanRemoteM;
import framework.beans.config.server.ConfigParametrAbstract;
import beans.directory.certificate.entity.CertificateType;
import beans.directory.lpu.entity.Lpu;
import framework.beans.report.ReportDefinition;
import beans.user.collaborator.entities.Collaborator;
import framework.audit.AuditDoc;
import framework.beans.address.entities.Address;
import framework.beans.report.ReportBeanAbstract;
import framework.generic.ClipsServerException;
import framework.generic.EDataIntegrity;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateful;
/**
* @author finder
*/
@Stateful(mappedName="clips-beans/ReportBean")
public class ReportBean extends ReportBeanAbstract
implements ReportBeanRemote{
public ReportBean() {
super();
}
@Override
protected void onRemove(ReportDefinition entity, List<AuditDoc> audit)
throws ClipsServerException {
if (!HardCodedIDs.canRemove(entity.getClass(), entity.getId())) {
throw new EDataIntegrity("Попытка удалить специальный отчет");
}
Field[] fields = new Field[]{
new Field("reportDefinition", entity)
};
if (getEntityCount(CertificateType.class, fields) > 0) {
throw new EDataIntegrity("На данный отчет ссылаются справки");
}
fields = new Field[]{
new Field("report", entity)
};
if (getEntityCount(DiseaseReport.class, fields) > 0) {
throw new EDataIntegrity("На данный отчет ссылаются отчеты по заболеваниям");
}
super.onRemove(entity, audit);
}
@Override
protected void getExtraDefaultParameters(Map<String, Object> target, ConfigBeanRemoteM config) throws ClipsServerException{
Collaborator collab = findEntity(Collaborator.class, getCollaboratorId());
Lpu lpu = collab.getLpu();
if (lpu != null) {
target.put("hospital_name", lpu.getTitle());
if (lpu.getAddress() != null) {
target.put("hospital_addres", lpu.getAddress().getAsStringShort());
}
Collaborator director = collab.getLpu().getChiefDoctor();
if (director != null){
target.put("director_fio", director.getClient().getFio());
}
target.put("id_ogrn_company_code", lpu.getOgrn() != null ? lpu.getOgrn() : "");
target.put("id_company_by_okpo", lpu.getOkpo() != null ? lpu.getOkpo() : "");
target.put("id_industry_by_okonh", lpu.getOkonh() != null ? lpu.getOkonh() : "");
target.put("id_action_type_by_okved", lpu.getOkved() != null ? lpu.getOkved() : "");
Address address = lpu.getAddress();
if (address != null && address.getAddressObject() != null) {
target.put("id_contry_by_okato", Long.toString(lpu.getAddress().getAddressObject().getOkato()));
}
target.put("id_department_by_okogu", lpu.getOkogu() != null ? lpu.getOkogu() : "");
target.put("id_type_of_company_by_okopf", lpu.getOkopf() != null ? lpu.getOkopf() : "");
target.put("id_pattern_of_ownership_okfc", lpu.getOkfc() != null ? lpu.getOkfc() : "");
}
}
}