Package beans.doctor.emc

Source Code of beans.doctor.emc.EmcBean

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package beans.doctor.emc;

import beans.doctor.diagnosis.DiagnosisDetails;
import framework.beans.EntityDetails;
import beans.doctor.disease.DiseaseDetails;
import framework.beans.FacadeBean;
import framework.beans.security.BeanRights;
import beans.doctor.disease.Disease;
import beans.followup.entity.Followup;
import beans.followup.entity.FollowupDetails;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import framework.generic.ClipsServerException;
import framework.generic.EDataIntegrity;
import javax.ejb.EJBException;
import javax.ejb.Stateful;
import framework.security.InaccessReasons;
import beans.UserRightsSet;
import beans.doctor.disease.DiseaseBean;
import framework.audit.AuditDoc;
import framework.security.RightChecker;
import framework.utils.Pair;
import java.util.Collections;
import java.util.Comparator;
import javax.persistence.Query;

/**
* @security - Ok.
* @author axe
*/
@Stateful(mappedName="clips-beans/EmcBean")
public class EmcBean extends FacadeBean<Emc>
        implements EmcBeanRemote {

    public EmcBean() {
        super(Emc.class);
    }

    @Override
    protected void initBeanRights() {
        int [] r = new int[4];
        r[COMMAND_READ] = RightPresence(UserRightsSet.READ_MEDICAL_DATA.id);
        int cmr = RightPresence(UserRightsSet.WRITE_MEDICAL_DATA_ANY_TIME.id);
        if (cmr < 0) {
            cmr = RightPresence(UserRightsSet.WRITE_MEDICAL_DATA_DURING_DAY.id);
        }
       
        r[COMMAND_CREATE] = cmr;
        r[COMMAND_MODIFY] = cmr;
        r[COMMAND_REMOVE] = InaccessReasons.COMMAND_UNACCESSABLE.id;
       
        rights = new BeanRights(r);
    }

    /**
     * Обновляет данные сущности.
     * @param details новые детали сущности
     * @throws EJBException в случае если обновление отвергнуто системой
     *          безопастности либо произошла ошибка
     * @return идентификатор сущности
     * Безопасность. Создание изменение и удаление по любому из прав WRITE_MEDICAL_DATA_DURING_DAY
     * или WRITE_MEDICAL_DATA_ANY_TIME
     */
    @Override
    protected void onUpdate(Emc entity, EntityDetails details,
            AuditDoc auditDoc, List<AuditDoc> auditDocList) throws ClipsServerException {
        EmcDetails d = (EmcDetails) details;

        if (!d.number.equals(getExistentEntity().getNumber())){
            Query    qery = manager.createQuery("select a.number from " + Emc.class.getSimpleName() + " a");
            @SuppressWarnings("unchecked")
            List<String> list = qery.getResultList();
            if (list.contains(d.number)) {
                throw new ClipsServerException("Уже существует ЭМК с данным номером");
            }
        }
        entity.setNumber(d.number);
        entity.setAnamnez(d.anamnez);
    }

    @Override
    protected void onRemove(Emc entity, List<AuditDoc> audit) throws ClipsServerException {
        throw new EDataIntegrity("Удаление ЭМК не предусмотрено");
    }

    /**
     * Возвращает список заболеваний для данного ЕМС
     * @return список, который может быть пустым, более того, детали диагноза могут быть нулл
     */
    @Override
    public List<Pair<DiseaseDetails, DiagnosisDetails>> getDiseaseList() throws ClipsServerException {
        checkCommandAccessibility(COMMAND_READ);
        Emc entity = getExistentEntity();
       
        List<Disease> list = findEntityList(Disease.class, "emc", entity);

        Collections.sort(list, new Comparator<Disease>() {
            @Override
            public int compare(Disease o1, Disease o2) {
                return o1.getCreated().compareTo(o2.getCreated());
            }
        });
        HashMap<Disease, DiagnosisDetails> map = DiseaseBean.getSpecificDiagnosis(entity, manager);

        Iterator i = list.iterator();
        List<Pair<DiseaseDetails, DiagnosisDetails>> detailsList = new ArrayList<Pair<DiseaseDetails, DiagnosisDetails>>();
        while(i.hasNext()) {
            Disease s = (Disease) i.next();
            DiagnosisDetails diagnosysDiagnosis = map.get(s);
            DiseaseDetails diseaseDetails = s.getDetails((RightChecker) this);
            detailsList.add(new Pair<DiseaseDetails, DiagnosisDetails>(diseaseDetails, diagnosysDiagnosis));
        }
        return detailsList;
    }
   
    /**
     * Возвращает список диспансеризаций для данного ЕМС
     * @return список, который модет быть пустым
     */
    @Override
    public List<FollowupDetails> getFollowupList() throws ClipsServerException {
        checkCommandAccessibility(COMMAND_READ);
        Emc entity = getExistentEntity();
       
        List list = findEntityList(Followup.class, "serrenUp.disease.emc", entity);

        Collections.sort(list, new Comparator<Followup>() {
            @Override
            public int compare(Followup o1, Followup o2) {
                return o1.getDateup().compareTo(o2.getDateup());
            }
        });

        Iterator i = list.iterator();
        List<FollowupDetails> res = new ArrayList<FollowupDetails>();
        while(i.hasNext()) {
            Followup s = (Followup) i.next();
            res.add(s.getDetails((RightChecker) this));
        }
        return res;
    }   
   
}
TOP

Related Classes of beans.doctor.emc.EmcBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.