Package open.dolphin.client

Source Code of open.dolphin.client.StampTreeModules

package open.dolphin.client;

import java.util.Calendar;
import java.util.GregorianCalendar;
import open.dolphin.delegater.StampDelegater;
import open.dolphin.infomodel.IInfoModel;
import open.dolphin.infomodel.ModuleInfoBean;
import open.dolphin.infomodel.ModuleModel;
import open.dolphin.infomodel.StampModel;
import open.dolphin.util.BeanUtils;
import org.apache.log4j.Logger;

/**
* StampTree から ModuleModel を取り出す
* @author pns
*/
public class StampTreeModules {

    private Logger logger;
   
    private static int SHOSHIN = 0;
    private static int SHOSHIN_RYOTAN = 1;
    private static int SHOSHIN_YAKAN = 2;
    private static int SHOSHIN_RYOTAN_YAKAN = 3;
    private static int SAISHIN = 4;
    private static int SAISHIN_YAKAN = 5;
    private static String[] SHOSHIN_SAISHIN =
        {"初診", "初診(療養担当)", "初診(夜間・早朝等)", "初診(療養担当)(夜間・早朝等)",
         "再診(診療所)", "再診(診療所)(夜間・早朝等)"};
   
    private Chart context;
    private ChartMediator mediator;
    private GregorianCalendar today;
    private LastVisit lv;

    public StampTreeModules(ChartImpl context) {
        this.context = context;
        mediator = context.getChartMediator();
        today = new GregorianCalendar();
        lv = context.getLastVisit();

        logger = ClientContext.getBootLogger();
    }

    /**
     * entity のスタンプ箱から key に一致する module を探して返す。無ければ null が返る
     * ただし,フォルダの中身までは検索しない
     * @param entity
     * @param key
     * @return ModuleInfoBean or null
     */
    private ModuleModel getStampModule(String entity, String key) {
        StampTree tree =  mediator.getStampTree(entity);
        ModuleInfoBean stamp = null;
        ModuleModel mModel = null;

        for (int i=0; i<tree.getRowCount(); i++) {
            StampTreeNode sn = (StampTreeNode) tree.getPathForRow(i).getLastPathComponent();
            if (sn.isLeaf()) {
                ModuleInfoBean bean = sn.getStampInfo();
                String name = bean.getStampName();
                if (name.equals(key)) {
                    stamp = bean;
                    break;
                }
            }
        }
        if (stamp != null) {
            StampDelegater sdl = new StampDelegater();
            // Stamp モデルをデータベースから取ってくる
            StampModel sModel = sdl.getStamp(stamp.getStampId());
            // Stamp モデルから info モデルを作る
            IInfoModel iModel = (IInfoModel) BeanUtils.xmlDecode(sModel.getStampBytes());
            // info モデル(実体)と stamp(情報) を module model にセット
            mModel = new ModuleModel();
            mModel.setModel(iModel);
            mModel.setModuleInfo(stamp);
        }
        return mModel;
    }

    /**
     * テキストスタンプから title のスタンプを取ってきて返す
     * @return ModuleModel
     */
    public ModuleModel getTextStamp(String title) {

        ModuleModel mModel = getStampModule(IInfoModel.ENTITY_TEXT, title);
        if (mModel != null) {
            mModel.getModuleInfo().setStampRole(IInfoModel.ROLE_SOA);
        }
        return mModel;
    }

    /*
     * 初診・再診を判定して,module として返す
     */
    public ModuleModel getBaseCharge() {
        /*
         * 初診か再診か判定
         * 初診,初診(療養担当),初診(夜間・早朝等),初診(療養担当)(夜間・早朝等),再診(診療所),再診(診療所)(夜間・早朝等)
         */

        // 初診・再診の情報判定
        int index = 0;
        if (isShoshin()) {
            if (isRyotan()) {
                if (isYakan()) index = SHOSHIN_RYOTAN_YAKAN;
                else index = SHOSHIN_RYOTAN;
            } else {
                if (isYakan()) index = SHOSHIN_YAKAN;
                else index = SHOSHIN;
            }
        } else {
            if (isYakan()) index = SAISHIN_YAKAN;
            else index = SAISHIN;
        }

        //logger.info("initial stamp = " + SHOSHIN_SAISHIN[index]);

        // スタンプ選択
        return getStampModule(IInfoModel.ENTITY_BASE_CHARGE_ORDER, SHOSHIN_SAISHIN[index]);
    }

    public boolean isShoshin() {
        int[] lastVisit = lv.getLastVisitInHistoryYmd();

        // 受診歴が無ければ初診で返す
        if (lastVisit == null) return true;

        // 受診歴がある場合は,3ヶ月たったかどうか判定
        int dif_year = today.get(Calendar.YEAR) - lastVisit[0];
        int dif_month = today.get(Calendar.MONTH) - lastVisit[1];
        int dif_day = today.get(Calendar.DATE) - lastVisit[2];

        // 2年以上離れていたら初診
        if (dif_year >= 2) return true;
        // 1年差の場合は月差を調整
        if (dif_year == 1) dif_month = dif_month + 12;
        // 4ヶ月以上離れていたら初診
        if (dif_month >= 4) return true;
        // 3ヶ月離れている場合は,日付を比較
        else if (dif_month == 3) {
            if (dif_day >= 0) return true;
            else return false;
        // それ以外は再診
        } else return false;
    }

    private boolean isRyotan() {
        int month = today.get(Calendar.MONTH);
        // 5月~10月は療養担当手当なし
        if (month >=4 && month <=9) return false;
        return true;
    }

    private boolean isYakan() {
        // 土曜日で 12時以降なら夜間
        GregorianCalendar gc = lv.getLastVisitGc();
        // 今日受診していないのに新規カルテを作った場合は false に決め打ち(実際はあり得ない操作)
        if (gc == null) { return false; }
       
        if ((gc.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) &&
                (gc.get(Calendar.AM_PM) == Calendar.PM)) return true;
        else return false;
    }
}
TOP

Related Classes of open.dolphin.client.StampTreeModules

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.