Package clips.delegate.doctor.medexam

Source Code of clips.delegate.doctor.medexam.MedexamLocal$ResultList

/*
* DiseaseLocal.java
*
* Created on 12 Декабрь 2007 г., 11:57
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package clips.delegate.doctor.medexam;

import beans.doctor.medexam.MedexamBean;
import beans.doctor.medexam.MedexamBeanRemote;
import cli_fmw.main.ClipsException;
import cli_fmw.delegate.cache.Cache;
import cli_fmw.delegate.cache.DelegateExtraDataRO;
import cli_fmw.delegate.cache.ExtraDataManager;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.delegate.lists.DataChunkMapList;
import cli_fmw.utils.SelectorEditable;
import clips.delegate.DEC.DECDisease;
import clips.delegate.client.ClientLocal;
import clips.delegate.directory.simple.medexam.DirectoryMedexamType;
import clips.delegate.directory.simple.medexam.DirectoryMedexamTypeItem;
import clips.delegate.directory.simple.profcheckupResult.DirectoryProfcheckupResult;
import clips.delegate.directory.simple.profcheckupResult.DirectoryProfcheckupResultItem;
import clips.delegate.service.SerRenLocal;
import beans.service.medexam.MedSerrenResultDetails;
import beans.service.medexam.MedexamDetails;
import cli_fmw.delegate.AuditListener;
import clips.delegate.doctor.DiseaseLocal;
import clips.delegate.doctor.HasDiseaseLocal;
import clips.doctor.newEMC.init.generic.DelegateNode;
import framework.utils.ROList;
import java.util.HashMap;
import java.util.List;

public class MedexamLocal extends
    DelegateNode<MedexamBeanRemote, MedexamDetails, SerRenLocal>
        implements HasDiseaseLocal, HasSerrenResult {

  DelegateExtraDataRO<ClientLocal> clientCache = new DelegateExtraDataRO<ClientLocal>(getEDM()) {
    @Override
    protected ClientLocal init() throws Exception {
      return getDiseaseLocal().getEmcLocal().getClient();
    }

        @Override
        protected ClientLocal initNew() {
            return null;
        }
  };
    private DECDisease disease = new DECDisease(this, "случай заболевания, связанный с медосмотром", getAuditListener());
    private ResultList resultList = new ResultList(getEDM());
    private Cache<HashMap<Integer, SerRenLocal>> hashSerren = new Cache<HashMap<Integer, SerRenLocal>>();
    private Cache<String> packetTitle = new Cache<String>();

    public MedexamLocal(DiseaseLocal stt, MedexamDetails details, AuditListener al) throws ClipsException{
        super(details, al);
        this.disease.initBy(stt);
    }

    public MedexamLocal(ClientLocal client, MedexamDetails details, AuditListener al) throws ClipsException{
        super(details, al);
        this.clientCache.initBy(client);
    }

    @Override
    protected MedexamDetails getNewDetails() {
        return new MedexamDetails();
    }

    @Override
    public SelectorEditable<MedSerrenResultData> getResultList() throws ClipsException {
        return resultList.selector();
    }

    public DirectoryProfcheckupResultItem getFinalResult() throws ClipsException {
        DirectoryProfcheckupResult dir = DirectoryLocator.getDirectory(DirectoryProfcheckupResult.class);
        return dir.getItemFromID(getDetails().resultID);
    }

    public void setFinalResult(DirectoryProfcheckupResultItem item) throws ClipsException {
        getDetails().resultID = item.getID();
        fireContentStateEvent();
    }

    @Override
    public int getSerrenCount() throws ClipsException {
        if (!hashSerren.inCache()) {
            initSerrenCache();
        }
        return hashSerren.get().size();
    }

    /**
     * Возвращает услугу, связанную с результатом медосмотра по id результата
     * @param resultID
     * @return
     * @throws cli_fmw.main.ClipsException
     */
    @Override
    public SerRenLocal getSerRen(MedSerrenResultData resultData) throws ClipsException {
        if (!hashSerren.inCache()) {
            initSerrenCache();
        }
        return hashSerren.get().get(resultData.getId());
    }

    private void initSerrenCache() throws ClipsException{
            //Составим хеш результат - услуга
            List<SerRenLocal> serrenList = getDiseaseLocal().getSerrenList();
            SelectorEditable<MedSerrenResultData> resList = getResultList();
            HashMap<Integer, SerRenLocal> hash = new HashMap<Integer, SerRenLocal>();
            for (int i = 0; i < serrenList.size(); i++) {
                SerRenLocal serRenLocal = serrenList.get(i);
                for (int j = 0; j < resList.size(); j++) {
                    MedSerrenResultData res = resList.get(j);
                    if (res.getSerrenID() == serRenLocal.getID()) {
                        hash.put(res.getId(), serRenLocal);
                    }
                }
            }
            hashSerren.set(hash);
    }

    public DirectoryMedexamTypeItem getMedexamType() throws ClipsException {
        DirectoryMedexamType dir = DirectoryLocator.getDirectory(DirectoryMedexamType.class);
        return dir.getItemFromID(getDetails().medexamTypeID);
    }

    @Override
    public String toString() {
        return "Медосмотр";
    }


    @Override
    protected String getBeanName() {
        return MedexamBean.class.getSimpleName();
    }
   
    @Override
    public DiseaseLocal getDiseaseLocal() throws ClipsException {
        return disease.get();
    }

    public ClientLocal getClientLocal() throws ClipsException {
        return clientCache.get();
    }

    public String getPacketTitle() throws ClipsException {
        if (!packetTitle.inCache()) {
            try {
                packetTitle.set(getBean().getPacketTitle());
            } catch (Exception ex) {
                throw new ClipsException("Не удалось получить название медосмотра", ex);
            }
        }
        return packetTitle.get();
    }

    @Override
    protected void addChildImpl(SerRenLocal child) throws ClipsException {
        getDiseaseLocal().addChild(child);
    }

    @Override
    protected void removeChildImpl(SerRenLocal child) throws ClipsException {
        getDiseaseLocal().removeChildImpl(child);
    }

    @Override
    public ROList<SerRenLocal> getChildren() throws ClipsException {
        return getDiseaseLocal().getChildren();
    }

    @Override
    public int getChildCount() throws ClipsException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    private class ResultList extends DataChunkMapList<MedSerrenResultData, Integer> {

        public ResultList(ExtraDataManager contaner) {
            super(contaner);
        }

        @Override
        protected void deleteDB(MedSerrenResultData data) throws Exception {
            throw new ClipsException("Удаление не поддерживается");
        }

        @Override
        protected int saveDB(MedSerrenResultData data) throws Exception {
            return getBean().setMedSerrenResult(data.getDetails());
        }

        @Override
        protected void loadDB() throws Exception {
            List<MedSerrenResultDetails> list = getBean().getMedSerrenResultList();
            for (int i = 0; i < list.size(); i++) {
                MedSerrenResultData data = new MedSerrenResultData(list.get(i));
                initByDetails(data);
            }
        }
    }

}
TOP

Related Classes of clips.delegate.doctor.medexam.MedexamLocal$ResultList

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.