Package open.dolphin.delegater

Source Code of open.dolphin.delegater.DocumentDelegater

package open.dolphin.delegater;

import java.awt.Dimension;
import java.awt.Image;
import java.util.*;
import javax.naming.NamingException;
import javax.swing.ImageIcon;
import open.dolphin.client.ImageEntry;
import open.dolphin.dto.*;
import open.dolphin.ejb.RemoteKarteService;
import open.dolphin.infomodel.*;
import open.dolphin.util.BeanUtils;

/**
* Session と Document の送受信を行う Delegater クラス。
*
* @author Kazushi Minagawa
*/
public class  DocumentDelegater extends BusinessDelegater {
   
    /**
     * 患者のカルテを取得する。
     * @param patientPk 患者PK
     * @param fromDate 履歴の検索開始日
     * @return カルテ
     */
    public KarteBean getKarte(long patientPk, Date fromDate) {
       
        KarteBean karte = null;
       
        try {
            karte = getService().getKarte(patientPk, fromDate);
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return karte;
    }
   
    /**
     * Documentを保存する。
     * @param karteModel KarteModel
     * @return Result Code
     */
    public long putKarte(DocumentModel karteModel) {
       
        long retCode = 0;
       
        try {
            // 確定日、適合開始日、記録日、ステータスを
            // DocInfo から DocumentModel(KarteEntry) に移す
            karteModel.toPersist();
           
            // 保存する
            retCode = getService().addDocument(karteModel);
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return retCode;
    }
   
    /**
     * Documentを検索して返す。
     * @param id DocumentID
     * @return DocumentValue
     */
    public List<DocumentModel> getDocuments(List<Long> ids) {

        List<DocumentModel> ret = null;
       
        // 検索する
        try {
            ret = getService().getDocuments(ids);
            for (DocumentModel doc : ret) {
               
                // Module byte をオブジェクトへ戻す
                Collection<ModuleModel> mc = doc.getModules();
                for (ModuleModel module : mc) {
                    module.setModel((InfoModel) BeanUtils.xmlDecode(module.getBeanBytes()));
                    //module.toDetuch();
                }
               
                // JPEG byte をアイコンへ戻す
                Collection<SchemaModel> sc = doc.getSchema();
                for (SchemaModel schema : sc) {
                    ImageIcon icon = new ImageIcon(schema.getJpegByte());
                    schema.setIcon(icon);
                }
            }
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }

        return ret;
    }
   
    /**
     * 文書履歴を検索して返す。
     * @param spec DocumentSearchSpec 検索仕様
     * @return DocInfoModel の Collection
     */
    public List getDocumentList(DocumentSearchSpec spec) {
       
        if (spec.getDocType().equals(IInfoModel.DOCTYPE_KARTE)) {
            return getKarteList(spec);
        }
       
        return null;
    }
   
    private List getKarteList(DocumentSearchSpec spec) {
       
        List ret= null;
       
        try {
            ret = getService().getDocumentList(spec);
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return ret;
    }
   
    /**
     * ドキュメントを論理削除する。
     * @param pk 論理削除するドキュメントの prmary key
     * @return 削除件数
     */
    public int deleteDocument(long pk) {
       
        try {
            return getService().deleteDocument(pk);
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return 0;
    }
   
    /**
     * 文書履歴のタイトルを変更する。
     * @param pk Document の pk
     * @return 変更した件数
     */
    public int updateTitle(DocInfoModel docInfo) {
       
        try {
            return getService().updateTitle(docInfo.getDocPk(), docInfo.getTitle());
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return 0;
    }
   
   
    /**
     * Moduleを検索して返す。
     * @param spec ModuleSearchSpec 検索仕様
     * @return Module の Collection
     */
    public List getModuleList(ModuleSearchSpec spec) {
       
        List<List> ret= null;
       
        try {
            ret = getService().getModules(spec);
            for (List list : ret) {
                for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                    ModuleModel module = (ModuleModel)iter.next();
                    module.setModel((InfoModel)BeanUtils.xmlDecode(module.getBeanBytes()));
                    //module.toDetuch();
                }
            }
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return ret;
    }
   
    /**
     * イメージを取得する。
     * @param id 画像のId
     * @return SchemaModel
     */
    public SchemaModel getImage(long id) {
       
        SchemaModel model = null;
       
        try {
            model = getService().getImage(id);
           
            if (model != null) {
                byte[] bytes = model.getJpegByte();
                ImageIcon icon = new ImageIcon(bytes);
                if (icon != null) {
                    model.setIcon(icon);
                }
            }
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return model;
    }
   
    /**
     * Imageを検索して返す。
     * @param spec ImageSearchSpec 検索仕様
     * @return Imageリストのリスト
     */
    public List getImageList(ImageSearchSpec spec) {
       
        List<List> ret= new ArrayList<List>(3);
       
        try {
            // 検索結果
            List result = getService().getImages(spec);
            //logger.debug("got result, count = " + result.size());
           
            //System.out.println("got image list");
           
            for (Iterator iter = result.iterator(); iter.hasNext(); ) {
               
                // 抽出期間毎のリスト
                List periodList = (List)iter.next();
               
                // ImageEntry 用のリスト
                List<ImageEntry> el = new ArrayList<ImageEntry>();
               
                // 抽出期間をイテレートする
                for (Iterator iter2 = periodList.iterator(); iter2.hasNext(); ) {
                    // シェーマモデルをエントリに変換しリストに加える
                    SchemaModel model = (SchemaModel)iter2.next();
                    ImageEntry entry = getImageEntry(model, spec.getIconSize());
                    el.add(entry);
                }
               
                // リターンリストへ追加する
                ret.add(el);
            }
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return ret;
    }
   
    /**
     * シェーマモデルをエントリに変換する。
     * @param schema シェーマモデル
     * @param iconSize アイコンのサイズ
     * @return ImageEntry
     */
    private ImageEntry getImageEntry(SchemaModel schema, Dimension iconSize) {
       
        ImageEntry model = new ImageEntry();
       
        model.setId(schema.getId());
        //model.setConfirmDate(ModelUtils.getDateTimeAsString(schema.getConfirmDate()));  // First?
        model.setConfirmDate(ModelUtils.getDateTimeAsString(schema.getConfirmed()))// First?
        model.setContentType(schema.getExtRef().getContentType());
        model.setTitle(schema.getExtRef().getTitle());
        model.setMedicalRole(schema.getExtRef().getMedicalRole());
       
        byte[] bytes = schema.getJpegByte();
       
        // Create ImageIcon
        ImageIcon icon = new ImageIcon(bytes);
        if (icon != null) {
            model.setImageIcon(adjustImageSize(icon, iconSize));
        }
       
        return model;
    }
   
    public List<Long> putDiagnosis(List<RegisteredDiagnosisModel> beans) {
       
        List<Long> ret = null;
       
        try {
            ret = getService().addDiagnosis(beans);
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return ret;
    }
   
    public int updateDiagnosis(List<RegisteredDiagnosisModel> beans) {
       
        int retCode = 0;
       
        try {
            retCode = getService().updateDiagnosis(beans);
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return retCode;
    }
   
    public int removeDiagnosis(List<Long> ids) {
       
        int retCode = 0;
       
        try {
            retCode = getService().removeDiagnosis(ids);
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return retCode;
    }
   
    /**
     * Diagnosisを検索して返す。
     * @param spec DiagnosisSearchSpec 検索仕様
     * @return DiagnosisModel の Collection
     */
    public List getDiagnosisList(DiagnosisSearchSpec spec) {
       
        List ret= null;
       
        try {
            ret = getService().getDiagnosis(spec);
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return ret;
    }
   
    public List<Long> addObservations(List<ObservationModel> observations) {
       
        try {
            return getService().addObservations(observations);
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
        return null;
    }
   
   
    public List<ObservationModel> getObservations(ObservationSearchSpec spec) {
       
        try {
            return getService().getObservations(spec);
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
        return null;
    }
   
    public int updateObservations(List<ObservationModel> observations) {
       
        try {
            return getService().updateObservations(observations);
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
        return 0;
    }
   
    public int removeObservations(List<Long> ids) {
       
        try {
            return getService().removeObservations(ids);
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
        return 0;
    }
   
    public int updatePatientMemo(PatientMemoModel pm) {
       
        try {
            return getService().updatePatientMemo(pm);
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
        return 0;
    }
   
    public List getAppoinmentList(ModuleSearchSpec spec) {
       
        List ret = null;
       
        try {
            ret = getService().getAppointmentList(spec);
           
        } catch (NamingException e) {
            e.printStackTrace(System.err);
            processError(e);
        }
       
        return ret;
    }
   
    private RemoteKarteService getService() throws NamingException {
        return (RemoteKarteService) getService("RemoteKarteService");
    }
   
    private ImageIcon adjustImageSize(ImageIcon icon, Dimension dim) {
       
        if ( (icon.getIconHeight() > dim.height) ||
                (icon.getIconWidth() > dim.width) ) {
            Image img = icon.getImage();
            float hRatio = (float)icon.getIconHeight() / dim.height;
            float wRatio = (float)icon.getIconWidth() / dim.width;
            int h, w;
           
            if (hRatio > wRatio) {
                h = dim.height;
                w = (int)(icon.getIconWidth() / hRatio);
               
            } else {
                w = dim.width;
                h = (int)(icon.getIconHeight() / wRatio);
            }
           
            img = img.getScaledInstance(w, h, Image.SCALE_SMOOTH);
            return new ImageIcon(img);
           
        } else {
            return icon;
        }
    }
}
TOP

Related Classes of open.dolphin.delegater.DocumentDelegater

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.