package in.cdac.medinfo.csnotk.csnolib.ecl.constraint;

import org.snomed.langauges.ecl.domain.expressionconstraint.RefinedExpressionConstraint;
import org.snomed.langauges.ecl.domain.expressionconstraint.SubExpressionConstraint;
import org.snomed.langauges.ecl.domain.refinement.EclRefinement;

//Changes
import in.cdac.medinfo.csnotk.csnolib.model.Concept;
import java.util.Set;
import com.google.common.collect.Sets;
import static com.google.common.collect.Sets.newHashSet;

public class SRefinedExpressionConstraint extends RefinedExpressionConstraint implements SConstraint {

    public SRefinedExpressionConstraint(SubExpressionConstraint subExpressionConstraint, EclRefinement eclRefinement) {
        super(subExpressionConstraint, eclRefinement);
    }

    @Override
    public Set<Concept> addQuery() {
        Set<Concept> subSctIds = getSubexpressionConstraint().addQuery();
        Set<Concept> refinementSctIds = getEclRefinement().addQuery();
        return Sets.intersection( subSctIds, refinementSctIds);
    }

    @Override
    public SSubExpressionConstraint getSubexpressionConstraint() {
        return (SSubExpressionConstraint) super.getSubexpressionConstraint();
    }

    @Override
    public SEclRefinement getEclRefinement() {
        return (SEclRefinement) super.getEclRefinement();
    }

    @Override
    public Set<String> getConceptIds() {
        Set<String> conceptIds = newHashSet();
        conceptIds.addAll(((SSubExpressionConstraint) subexpressionConstraint).getConceptIds());
        conceptIds.addAll(((SEclRefinement) eclRefinement).getConceptIds());
        return conceptIds;
    }
}
