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

import org.snomed.langauges.ecl.ECLException;
import org.snomed.langauges.ecl.ECLQueryBuilder;
import in.cdac.medinfo.csnotk.csnolib.ecl.constraint.SConstraint;

//Changes
import in.cdac.medinfo.csnotk.csnolib.model.Concept;
import java.util.Set;

public class ExpressionConstraintLanguageService {

    private final ECLQueryBuilder eclQueryBuilder;

    public ExpressionConstraintLanguageService() {
        eclQueryBuilder = new ECLQueryBuilder(new SECLObjectFactory());
    }

    public Set<Concept> getEclConstraints(String ecl) {
        try {
            SConstraint constraint = doGetConstraint(ecl);
            return constraint.addQuery();
        } catch (ECLException eclException) {
            throw new IllegalArgumentException(String.format("ECL syntax error. %s", eclException.getMessage()));
        }
    }

    public SConstraint doGetConstraint(String ecl) {
        return (SConstraint) eclQueryBuilder.createQuery(ecl);
    }

}
