List<Predicate<LabItemRange>> filterList = new ArrayList<>();
filterList.add(e->compareCode(e,report)&&compareAge(e,report)&&compareSex(e,report));
filterList.add(e ->Objects.isNull(e.getSex())&&compareCode(e,report)&&compareAge(e,report));
filterList.add(e ->Objects.isNull(e.getLowAge())&&Objects.isNull(e.getHighAge())&&compareCode(e,report)&&compareSex(e,report));
filterList.add(e ->Objects.isNull(e.getHighAge())&&Objects.isNull(e.getLowAge())&&Objects.isNull(e.getSex())&&compareCode(e,report));
filterList.add(e ->Objects.isNull(e.getSampleCode())&&compareAge(e,report)&&compareSex(e,report));
filterList.add(e ->Objects.isNull(e.getSampleCode())&&Objects.isNull(e.getSex())&&compareAge(e,report));
filterList.add(e ->Objects.isNull(e.getSampleCode())&&Objects.isNull(e.getLowAge())&&Objects.isNull(e.getHighAge())&&compareSex(e,report));
filterList.add(e ->Objects.isNull(e.getSampleCode())&&Objects.isNull(e.getLowAge())&&Objects.isNull(e.getHighAge())&&Objects.isNull(e.getSex()));
final LabItemRange[] labItemRange = { null };
filterList.forEach(i->{
if (labItemRangeList.stream().anyMatch(i)) {
labItemRange[0] = labItemRangeList.stream().filter(i).findFirst().get();
}
});
return labItemRange[0];
private boolean compareCode(LabItemRange itemRange,Report report){
if (itemRange.getSampleCode()==null||report.getSampleCode()==null) {
return false;
}
return Objects.equals(itemRange.getSampleCode(),report.getSampleCode());
}
private boolean compareAge(LabItemRange itemRange,Report report){
Integer age = report.getAge();
Integer ageUnit = report.getAgeUnit();
Integer lowAge = itemRange.getLowAge();
Integer highAge = itemRange.getHighAge();
Integer lowAgeUnit = itemRange.getLowAgeUnit();
Integer highAgeUnit = itemRange.getHighAgeUnit();
if (age==null||ageUnit==null||lowAge==null||highAge==null||lowAgeUnit==null||highAgeUnit==null) {
return false;
}
long ageSecond = age * AlisDateUtils.getSecondsByAgeUnit(ageUnit);
long lowAgeSecond = lowAge * AlisDateUtils.getSecondsByAgeUnit(lowAgeUnit);
long hignAgeSecond = highAge * AlisDateUtils.getSecondsByAgeUnit(highAgeUnit);
return ageSecond>=lowAgeSecond&&ageSecond<=hignAgeSecond;
}
private boolean compareSex(LabItemRange itemRange,Report report){
if (itemRange.getSex()==null||report.getSex()==null) {
return false;
}
return Objects.equals(itemRange.getSex(),report.getSex());
}