package com.diagbot.facade;

import com.diagbot.dto.LisResult;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import com.diagbot.vo.SearchVo;

import java.util.List;

/**
 * <p>
 *  数据处理业务层
 * </p>
 *
 * @author Mark Huang
 * @since 2019-03-04
 */
@Component
public class ClinicalFacade {
    /**
     * 处理临床数据
     *
     * @param searchVo
     * @return SearchVo
     */
    public SearchVo processClinicalData(@RequestBody SearchVo searchVo) {
        SearchVo sData = searchVo;

        sData.setLisArr(processLis(sData.getLisArr()));

        return sData;
    }

    private List<LisResult> processLis(List<LisResult> lisArr) {

        String Otherval = "";

        for (int i=0; i<lisArr.size(); i++) {
            LisResult lisres = lisArr.get(i);

            Otherval = (lisres.getOtherValue().trim().length() > 0)? lisres.getOtherValue().trim()+"\n":"";

            if (lisres.getMaxValue() != null && lisres.getValue() > lisres.getMaxValue()) {
                lisres.setOtherValue(Otherval + "超出标准");
            }
            else if (lisres.getMinValue() != null && lisres.getValue() < lisres.getMinValue()) {
                lisres.setOtherValue(Otherval + "低于标准");
            }
        }

        return lisArr;
    }
}
