// Path: rsterminology-core/src/main/java/com/eldrix/terminology/snomedct/Search.java
// public interface ResultItem {
// 	public String getTerm();
// 	public long getConceptId();
// 	public String getPreferredTerm();
// }
// 
// Path: rsterminology-core/src/main/java/com/eldrix/terminology/snomedct/semantic/Category.java
// public enum Category {
// 	SNOMED_CT_ROOT(138875005L),
// 	DISEASE(64572001L),
// 	CLINICAL_FINDING(404684003L),
// 	PROCEDURE(71388002L),
// 	PHARMACEUTICAL_OR_BIOLOGICAL_PRODUCT(373873005L);
// 	public final long conceptId;
// 	Category(long conceptId) {
// 		this.conceptId = conceptId;
// 	}
// }


import static org.junit.Assert.*;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.configuration.server.ServerRuntime;
import org.apache.cayenne.query.ObjectSelect;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.eldrix.terminology.snomedct.Search.ResultItem;
import com.eldrix.terminology.snomedct.semantic.Category;
package com.eldrix.terminology.snomedct;





public class TestProject {
	static ServerRuntime _runtime;

	public ServerRuntime getRuntime() {
		return _runtime;
	}

	@BeforeClass
	public static void setUp() throws Exception {
		_runtime = ServerRuntime.builder().addConfig("cayenne-project.xml").build();
	}

	@AfterClass
	public static void tearDown() throws Exception {
		_runtime.shutdown();
	}


	
	@Test
	public void testFetchProject() throws IOException {
		ObjectContext context = getRuntime().newContext();
		final String ACUTE_PAEDS_NAME="CAVACUTEPAEDS";
		Project p = ObjectSelect.query(Project.class, Project.NAME.eq(ACUTE_PAEDS_NAME)).selectOne(context);
		assertEquals(ACUTE_PAEDS_NAME, p.getName());

		// how many projects?
		long numberProjects = ObjectSelect.query(Project.class).count().selectOne(context);
		assertNotEquals(0, numberProjects);
		
		// calculate a list of common concepts manually rather than in a single fetch
		HashSet<Concept> common = new HashSet<Concept>();
		p.getOrderedParents().forEach(proj -> common.addAll(proj.getCommonConcepts()));

		// and now perform a filtered search...
		Search search = Search.getInstance();
		List<ResultItem> result = new Search.Request.Builder(search)
				.search("bronchio").onlyActive().withoutFullySpecifiedNames()
// Path: rsterminology-core/src/main/java/com/eldrix/terminology/snomedct/Search.java
// public interface ResultItem {
// 	public String getTerm();
// 	public long getConceptId();
// 	public String getPreferredTerm();
// }
// 
// Path: rsterminology-core/src/main/java/com/eldrix/terminology/snomedct/semantic/Category.java
// public enum Category {
// 	SNOMED_CT_ROOT(138875005L),
// 	DISEASE(64572001L),
// 	CLINICAL_FINDING(404684003L),
// 	PROCEDURE(71388002L),
// 	PHARMACEUTICAL_OR_BIOLOGICAL_PRODUCT(373873005L);
// 	public final long conceptId;
// 	Category(long conceptId) {
// 		this.conceptId = conceptId;
// 	}
// }


// Path: rsterminology-core/src/test/java/com/eldrix/terminology/snomedct/TestProject.java
import static org.junit.Assert.*;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.configuration.server.ServerRuntime;
import org.apache.cayenne.query.ObjectSelect;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.eldrix.terminology.snomedct.Search.ResultItem;
import com.eldrix.terminology.snomedct.semantic.Category;

package com.eldrix.terminology.snomedct;





public class TestProject {
	static ServerRuntime _runtime;

	public ServerRuntime getRuntime() {
		return _runtime;
	}

	@BeforeClass
	public static void setUp() throws Exception {
		_runtime = ServerRuntime.builder().addConfig("cayenne-project.xml").build();
	}

	@AfterClass
	public static void tearDown() throws Exception {
		_runtime.shutdown();
	}


	
	@Test
	public void testFetchProject() throws IOException {
		ObjectContext context = getRuntime().newContext();
		final String ACUTE_PAEDS_NAME="CAVACUTEPAEDS";
		Project p = ObjectSelect.query(Project.class, Project.NAME.eq(ACUTE_PAEDS_NAME)).selectOne(context);
		assertEquals(ACUTE_PAEDS_NAME, p.getName());

		// how many projects?
		long numberProjects = ObjectSelect.query(Project.class).count().selectOne(context);
		assertNotEquals(0, numberProjects);
		
		// calculate a list of common concepts manually rather than in a single fetch
		HashSet<Concept> common = new HashSet<Concept>();
		p.getOrderedParents().forEach(proj -> common.addAll(proj.getCommonConcepts()));

		// and now perform a filtered search...
		Search search = Search.getInstance();
		List<ResultItem> result = new Search.Request.Builder(search)
				.search("bronchio").onlyActive().withoutFullySpecifiedNames()
				.withRecursiveParent(Category.DISEASE.conceptId).build()