Fixes to command line tool, clean-up and minor re-factoring.

This commit is contained in:
ianmarshall 2020-04-13 08:56:56 -04:00
parent e64d67f429
commit af11763dee
25 changed files with 41 additions and 1161 deletions

View File

@ -233,18 +233,20 @@ public class CommonConfig {
public EmbeddedElastic embeddedElasticSearch() {
String ELASTIC_VERSION = "6.5.4";
EmbeddedElastic embeddedElastic;
try {
embeddedElastic = EmbeddedElastic.builder()
.withElasticVersion(ELASTIC_VERSION)
.withSetting(PopularProperties.TRANSPORT_TCP_PORT, 0)
.withSetting(PopularProperties.HTTP_PORT, 0)
.withSetting(PopularProperties.CLUSTER_NAME, UUID.randomUUID())
.withStartTimeout(60, TimeUnit.SECONDS)
.build()
.start();
} catch (IOException | InterruptedException e) {
throw new ConfigurationException(e);
EmbeddedElastic embeddedElastic = null;
if(!ContextHolder.isExternalElasticsearch()) {
try {
embeddedElastic = EmbeddedElastic.builder()
.withElasticVersion(ELASTIC_VERSION)
.withSetting(PopularProperties.TRANSPORT_TCP_PORT, 0)
.withSetting(PopularProperties.HTTP_PORT, 0)
.withSetting(PopularProperties.CLUSTER_NAME, UUID.randomUUID())
.withStartTimeout(60, TimeUnit.SECONDS)
.build()
.start();
} catch (IOException | InterruptedException e) {
throw new ConfigurationException(e);
}
}
return embeddedElastic;

View File

@ -1,13 +0,0 @@
package ca.uhn.fhir.fhir;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@ -1,20 +0,0 @@
package ca.uhn.fhir.fhir;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}

View File

@ -285,8 +285,7 @@ public abstract class BaseConfig {
public static void configureEntityManagerFactory(LocalContainerEntityManagerFactoryBean theFactory, FhirContext theCtx) {
theFactory.setJpaDialect(hibernateJpaDialect(theCtx.getLocalizer()));
//TODO: Consider moving the jpa.dao.lastn.entity.* classes into jpa.entity at some point.
theFactory.setPackagesToScan("ca.uhn.fhir.jpa.model.entity", "ca.uhn.fhir.jpa.entity", "ca.uhn.fhir.jpa.dao.lastn.entity");
theFactory.setPackagesToScan("ca.uhn.fhir.jpa.model.entity", "ca.uhn.fhir.jpa.entity");
theFactory.setPersistenceProvider(new HibernatePersistenceProvider());
}

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.jpa.dao.data;
import ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedCodeCodeableConceptEntity;
import ca.uhn.fhir.jpa.model.entity.ObservationIndexedCodeCodeableConceptEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.jpa.dao.data;
import ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedCodeCodingEntity;
import ca.uhn.fhir.jpa.model.entity.ObservationIndexedCodeCodingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.jpa.dao.data;
import ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedSearchParamLastNEntity;
import ca.uhn.fhir.jpa.model.entity.ObservationIndexedSearchParamLastNEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

View File

@ -3,7 +3,7 @@ package ca.uhn.fhir.jpa.dao.lastn;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedCodeCodeableConceptSearchParamDao;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedCodeCodingSearchParamDao;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedSearchParamLastNDao;
import ca.uhn.fhir.jpa.dao.lastn.entity.*;
import ca.uhn.fhir.jpa.model.entity.*;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Observation;
@ -25,7 +25,6 @@ public class ObservationLastNIndexPersistDstu3Svc {
@Autowired
IObservationIndexedCodeCodingSearchParamDao myObservationIndexedCodeCodingSearchParamDao;
// TODO: Change theSubjectId to be a Long
public void indexObservation(Observation theObservation, String theSubjectId) {
ObservationIndexedSearchParamLastNEntity indexedObservation = new ObservationIndexedSearchParamLastNEntity();
String resourcePID = theObservation.getIdElement().getIdPart();

View File

@ -3,7 +3,7 @@ package ca.uhn.fhir.jpa.dao.lastn;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedCodeCodeableConceptSearchParamDao;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedCodeCodingSearchParamDao;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedSearchParamLastNDao;
import ca.uhn.fhir.jpa.dao.lastn.entity.*;
import ca.uhn.fhir.jpa.model.entity.*;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Observation;
@ -25,7 +25,6 @@ public class ObservationLastNIndexPersistR4Svc {
@Autowired
IObservationIndexedCodeCodingSearchParamDao myObservationIndexedCodeCodingSearchParamDao;
// TODO: Change theSubjectId to be a Long
public void indexObservation(Observation theObservation, String theSubjectId) {
ObservationIndexedSearchParamLastNEntity indexedObservation = new ObservationIndexedSearchParamLastNEntity();
String resourcePID = theObservation.getIdElement().getIdPart();

View File

@ -3,7 +3,7 @@ package ca.uhn.fhir.jpa.dao.lastn;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedCodeCodeableConceptSearchParamDao;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedCodeCodingSearchParamDao;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedSearchParamLastNDao;
import ca.uhn.fhir.jpa.dao.lastn.entity.*;
import ca.uhn.fhir.jpa.model.entity.*;
import org.hl7.fhir.r5.model.CodeableConcept;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.Observation;
@ -25,7 +25,6 @@ public class ObservationLastNIndexPersistR5Svc {
@Autowired
IObservationIndexedCodeCodingSearchParamDao myObservationIndexedCodeCodingSearchParamDao;
// TODO: Change theSubjectId to be a Long
public void indexObservation(Observation theObservation, String theSubjectId) {
ObservationIndexedSearchParamLastNEntity indexedObservation = new ObservationIndexedSearchParamLastNEntity();
String resourcePID = theObservation.getIdElement().getIdPart();

View File

@ -1,80 +0,0 @@
package ca.uhn.fhir.jpa.dao.lastn;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedCodeCodingSearchParamDao;
import ca.uhn.fhir.jpa.dao.lastn.entity.*;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedCodeCodeableConceptSearchParamDao;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedSearchParamLastNDao;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Observation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
//@Component
public class ObservationLastNIndexPersistSvc {
@Autowired
IObservationIndexedSearchParamLastNDao myResourceIndexedObservationLastNDao;
@Autowired
IObservationIndexedCodeCodeableConceptSearchParamDao myObservationIndexedCodeableConceptSearchParamDao;
@Autowired
IObservationIndexedCodeCodingSearchParamDao myObservationIndexedCodeCodingSearchParamDao;
public void indexObservation(Observation theObservation) {
ObservationIndexedSearchParamLastNEntity indexedObservation = new ObservationIndexedSearchParamLastNEntity();
String resourcePID = theObservation.getId();
indexedObservation.setIdentifier(resourcePID);
// TODO: Need to improve this as there are multiple use cases involving subject.
String subjectId = "Patient/" + theObservation.getSubject().getReference();
indexedObservation.setSubject(subjectId);
Date effectiveDtm = theObservation.getEffectiveDateTimeType().getValue();
indexedObservation.setEffectiveDtm(effectiveDtm);
// Build CodeableConcept entities for Observation.Category
Set<ObservationIndexedCategoryCodeableConceptEntity> categoryConcepts = new HashSet<>();
for(CodeableConcept categoryCodeableConcept : theObservation.getCategory()) {
// Build Coding entities for each category CodeableConcept
Set<ObservationIndexedCategoryCodingEntity> categoryCodingEntities = new HashSet<>();
ObservationIndexedCategoryCodeableConceptEntity categoryCodeableConceptEntity = new ObservationIndexedCategoryCodeableConceptEntity(categoryCodeableConcept.getText());
for(Coding categoryCoding : categoryCodeableConcept.getCoding()){
categoryCodingEntities.add(new ObservationIndexedCategoryCodingEntity(categoryCoding.getSystem(), categoryCoding.getCode(), categoryCoding.getDisplay()));
}
categoryCodeableConceptEntity.setObservationIndexedCategoryCodingEntitySet(categoryCodingEntities);
categoryConcepts.add(categoryCodeableConceptEntity);
}
indexedObservation.setCategoryCodeableConcepts(categoryConcepts);
// Build CodeableConcept entity for Observation.Code.
CodeableConcept codeCodeableConcept = theObservation.getCode();
String observationCodeNormalizedId = null;
// Determine if a Normalized ID was created previously for Observation Code
for (Coding codeCoding : codeCodeableConcept.getCoding()) {
if (codeCoding.hasCode() && codeCoding.hasSystem()) {
observationCodeNormalizedId = myObservationIndexedCodeCodingSearchParamDao.findForCodeAndSystem(codeCoding.getCode(), codeCoding.getSystem());
} else {
observationCodeNormalizedId = myObservationIndexedCodeCodingSearchParamDao.findForDisplay(codeCoding.getDisplay());
}
}
// Generate a new a normalized ID if necessary
if (observationCodeNormalizedId == null) {
observationCodeNormalizedId = UUID.randomUUID().toString();
}
// Create/update normalized Observation Code index record
ObservationIndexedCodeCodeableConceptEntity codeableConceptField = new ObservationIndexedCodeCodeableConceptEntity(codeCodeableConcept.getText(), observationCodeNormalizedId);
for (Coding codeCoding : codeCodeableConcept.getCoding()) {
codeableConceptField.addCoding(new ObservationIndexedCodeCodingEntity(codeCoding.getSystem(), codeCoding.getCode(), codeCoding.getDisplay(), observationCodeNormalizedId));
}
myObservationIndexedCodeableConceptSearchParamDao.save(codeableConceptField);
indexedObservation.setObservationCode(codeableConceptField);
indexedObservation.setCodeNormalizedId(observationCodeNormalizedId);
myResourceIndexedObservationLastNDao.save(indexedObservation);
}
}

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.jpa.dao.lastn.entity;
package ca.uhn.fhir.jpa.model.entity;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.jpa.dao.lastn.entity;
package ca.uhn.fhir.jpa.model.entity;
import ca.uhn.fhir.jpa.dao.lastn.util.CodeSystemHash;
import org.hibernate.search.annotations.Analyze;

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.jpa.dao.lastn.entity;
package ca.uhn.fhir.jpa.model.entity;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
@ -6,8 +6,6 @@ import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
@Entity
@Indexed(index = "code_index")

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.jpa.dao.lastn.entity;
package ca.uhn.fhir.jpa.model.entity;
import ca.uhn.fhir.jpa.dao.lastn.util.CodeSystemHash;
import org.hibernate.search.annotations.Analyze;

View File

@ -38,7 +38,7 @@ public class ElasticsearchBulkIndexSvcImpl {
}
String observationMapping = "{\n" +
" \"mappings\" : {\n" +
" \"ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedSearchParamLastNEntity\" : {\n" +
" \"ca.uhn.fhir.jpa.model.entity.ObservationIndexedSearchParamLastNEntity\" : {\n" +
" \"properties\" : {\n" +
" \"codeconceptid\" : {\n" +
" \"type\" : \"keyword\",\n" +
@ -100,7 +100,7 @@ public class ElasticsearchBulkIndexSvcImpl {
}
String codeMapping = "{\n" +
" \"mappings\" : {\n" +
" \"ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedCodeCodeableConceptEntity\" : {\n" +
" \"ca.uhn.fhir.jpa.model.entity.ObservationIndexedCodeCodeableConceptEntity\" : {\n" +
" \"properties\" : {\n" +
" \"codeable_concept_id\" : {\n" +
" \"type\" : \"keyword\",\n" +

View File

@ -73,7 +73,7 @@ public class ElasticsearchSvcImpl implements IElasticsearchSvc {
}
String observationMapping = "{\n" +
" \"mappings\" : {\n" +
" \"ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedSearchParamLastNEntity\" : {\n" +
" \"ca.uhn.fhir.jpa.model.entity.ObservationIndexedSearchParamLastNEntity\" : {\n" +
" \"properties\" : {\n" +
" \"codeconceptid\" : {\n" +
" \"type\" : \"keyword\",\n" +
@ -135,7 +135,7 @@ public class ElasticsearchSvcImpl implements IElasticsearchSvc {
}
String codeMapping = "{\n" +
" \"mappings\" : {\n" +
" \"ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedCodeCodeableConceptEntity\" : {\n" +
" \"ca.uhn.fhir.jpa.model.entity.ObservationIndexedCodeCodeableConceptEntity\" : {\n" +
" \"properties\" : {\n" +
" \"codeable_concept_id\" : {\n" +
" \"type\" : \"keyword\",\n" +

View File

@ -4,6 +4,6 @@ public class IndexConstants {
public static final String OBSERVATION_INDEX = "observation_index";
public static final String CODE_INDEX = "code_index";
public static final String OBSERVATION_DOCUMENT_TYPE = "ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedSearchParamLastNEntity";
public static final String CODE_DOCUMENT_TYPE = "ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedCodeCodeableConceptEntity";
public static final String OBSERVATION_DOCUMENT_TYPE = "ca.uhn.fhir.jpa.model.entity.ObservationIndexedSearchParamLastNEntity";
public static final String CODE_DOCUMENT_TYPE = "ca.uhn.fhir.jpa.model.entity.ObservationIndexedCodeCodeableConceptEntity";
}

View File

@ -2,8 +2,8 @@ package ca.uhn.fhir.jpa.dao.lastn;
import ca.uhn.fhir.jpa.dao.lastn.config.TestObservationIndexSearchConfig;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedCodeCodeableConceptSearchParamDao;
import ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedCodeCodeableConceptEntity;
import ca.uhn.fhir.jpa.dao.lastn.entity.ObservationIndexedSearchParamLastNEntity;
import ca.uhn.fhir.jpa.model.entity.ObservationIndexedCodeCodeableConceptEntity;
import ca.uhn.fhir.jpa.model.entity.ObservationIndexedSearchParamLastNEntity;
import ca.uhn.fhir.jpa.dao.data.IObservationIndexedSearchParamLastNDao;
import org.hl7.fhir.r4.model.*;
import org.junit.After;

View File

@ -1,195 +0,0 @@
package ca.uhn.fhir.jpa.search.lastn;
import ca.uhn.fhir.jpa.search.lastn.json.CodeJson;
import ca.uhn.fhir.jpa.search.lastn.json.ObservationJson;
import ca.uhn.fhir.jpa.search.lastn.util.SimpleStopWatch;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.TokenParam;
import com.fasterxml.jackson.databind.ObjectMapper;
/*
import org.shadehapi.elasticsearch.action.search.SearchRequest;
import org.shadehapi.elasticsearch.action.search.SearchResponse;
import org.shadehapi.elasticsearch.index.query.QueryBuilders;
import org.shadehapi.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.shadehapi.elasticsearch.index.query.functionscore.RandomScoreFunctionBuilder;
import org.shadehapi.elasticsearch.search.SearchHit;
import org.shadehapi.elasticsearch.search.aggregations.AggregationBuilders;
import org.shadehapi.elasticsearch.search.aggregations.Aggregations;
import org.shadehapi.elasticsearch.search.aggregations.bucket.terms.ParsedTerms;
import org.shadehapi.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.shadehapi.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.shadehapi.elasticsearch.search.aggregations.metrics.tophits.ParsedTopHits;
import org.shadehapi.elasticsearch.search.aggregations.support.ValueType;
import org.shadehapi.elasticsearch.search.builder.SearchSourceBuilder;
import org.shadehapi.elasticsearch.search.sort.SortOrder;
*/
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.junit.Assert.assertEquals;
@Ignore
public class ElasticsearchPerformanceTests {
private ElasticsearchSvcImpl elasticsearchSvc = new ElasticsearchSvcImpl("localhost", 9301, "elastic", "changeme");
private List<String> patientIds = new ArrayList<>();
@Before
public void before() throws IOException {
/* SearchRequest searchRequest = new SearchRequest(IndexConstants.OBSERVATION_INDEX);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
RandomScoreFunctionBuilder randomScoreFunctionBuilder = new RandomScoreFunctionBuilder();
Date now = new Date();
randomScoreFunctionBuilder.seed(now.getTime());
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(randomScoreFunctionBuilder);
searchSourceBuilder.query(functionScoreQueryBuilder);
searchSourceBuilder.size(0);
// Aggregation by order codes
TermsAggregationBuilder observationCodeValuesBuilder = new TermsAggregationBuilder("group_by_patient", ValueType.STRING).field("subject");
observationCodeValuesBuilder.size(1000);
// Top Hits Aggregation
String[] topHitsInclude = {"subject"};
observationCodeValuesBuilder.subAggregation(AggregationBuilders.topHits("most_recent_effective")
.sort("effectivedtm", SortOrder.DESC)
.fetchSource(topHitsInclude, null).size(1));
searchSourceBuilder.aggregation(observationCodeValuesBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
patientIds = buildResults(response);
*/
}
// @Test
public void testObservationCodesQueryPerformance() throws IOException {
// SearchRequest searchRequest = elasticsearchSvc.buildObservationCodesSearchRequest(10000);
long totalElapsedTimes = 0L;
long totalElapsedSearchAndBuildTimes = 0L;
for(int i=0; i<1000; i++) {
SimpleStopWatch stopWatch = new SimpleStopWatch();
// SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
totalElapsedTimes += stopWatch.getElapsedTime();
// List<CodeJson> codes = elasticsearchSvc.buildCodeResult(response);
totalElapsedSearchAndBuildTimes += stopWatch.getElapsedTime();
// assertEquals(1000L, codes.size());
}
System.out.println("Codes query Average elapsed time = " + totalElapsedTimes/1000 + " ms");
System.out.println("Codes query Average elapsed search and build time = " + totalElapsedSearchAndBuildTimes/1000 + " ms");
}
@Test
public void testObservationsQueryPerformance() throws IOException {
long totalElapsedTimes = 0L;
long totalElapsedSearchAndBuildTimes = 0L;
for(String patientId : patientIds) {
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", patientId);
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam("http://mycodes.org/fhir/category-code", "test-category-code");
searchParameterMap.add("category", categoryParam);
// SearchRequest searchRequest = elasticsearchSvc.buildObservationTermsSearchRequest(1000, searchParameterMap, 100);
SimpleStopWatch stopWatch = new SimpleStopWatch();
// SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
totalElapsedTimes += stopWatch.getElapsedTime();
// List<ObservationJson> observations = elasticsearchSvc.buildObservationTermsResults(response);
totalElapsedSearchAndBuildTimes += stopWatch.getElapsedTime();
// assertEquals(25, observations.size());
}
System.out.println("Observations query Average elapsed time = " + totalElapsedTimes/(patientIds.size()) + " ms");
System.out.println("Observations query Average elapsed search and build time = " + totalElapsedSearchAndBuildTimes/(patientIds.size()) + " ms");
}
// @Test
public void testSingleObservationsQuery() throws IOException {
long totalElapsedTimes = 0L;
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", "5b2091a5-a50e-447b-aff4-c34b69eb43d5");
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam("http://mycodes.org/fhir/category-code", "test-category-code");
searchParameterMap.add("category", categoryParam);
// SearchRequest searchRequest = elasticsearchSvc.buildObservationCompositeSearchRequest(1000, searchParameterMap, 100);
SimpleStopWatch stopWatch = new SimpleStopWatch();
// SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
totalElapsedTimes += stopWatch.getElapsedTime();
// List<ObservationJson> observations = elasticsearchSvc.buildObservationCompositeResults(response);
// assertEquals(25, observations.size());
System.out.println("Average elapsed time = " + totalElapsedTimes/1000 + " ms");
}
// @Test
public void testLastNObservationsQueryTermsPerformance() throws IOException {
long totalElapsedTimes = 0L;
long totalElapsedSearchAndBuildTimes = 0L;
for(String patientId : patientIds) {
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", patientId);
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam("http://mycodes.org/fhir/category-code", "test-category-code");
searchParameterMap.add("category", categoryParam);
// SearchRequest searchRequest = elasticsearchSvc.buildObservationTermsSearchRequest(1000, searchParameterMap, 5);
SimpleStopWatch stopWatch = new SimpleStopWatch();
// SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
totalElapsedTimes += stopWatch.getElapsedTime();
// elasticsearchSvc.buildObservationTermsResults(response);
totalElapsedSearchAndBuildTimes += stopWatch.getElapsedTime();
}
System.out.println("LastN Average elapsed time = " + totalElapsedTimes/(patientIds.size()) + " ms");
System.out.println("LastN Average elapsed search and Build time = " + totalElapsedSearchAndBuildTimes/(patientIds.size()) + " ms");
}
// @Test
public void testLastNObservationsQueryCompPerformance() throws IOException {
long totalElapsedTimes = 0L;
long totalElapsedSearchAndBuildTimes = 0L;
for(String patientId : patientIds) {
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", patientId);
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam("http://mycodes.org/fhir/category-code", "test-category-code");
searchParameterMap.add("category", categoryParam);
// SearchRequest searchRequest = elasticsearchSvc.buildObservationCompositeSearchRequest(1000, searchParameterMap, 5);
SimpleStopWatch stopWatch = new SimpleStopWatch();
// SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
totalElapsedTimes += stopWatch.getElapsedTime();
// elasticsearchSvc.buildObservationCompositeResults(response);
totalElapsedSearchAndBuildTimes += stopWatch.getElapsedTime();
}
System.out.println("LastN Average elapsed time = " + totalElapsedTimes/(patientIds.size()) + " ms");
System.out.println("LastN Average elapsed search and Build time = " + totalElapsedSearchAndBuildTimes/(patientIds.size()) + " ms");
}
/* private List<String> buildResults(SearchResponse theSearchResponse) throws IOException {
Aggregations responseAggregations = theSearchResponse.getAggregations();
ParsedTerms aggregatedObservationCodes = responseAggregations.get("group_by_patient");
aggregatedObservationCodes.getBuckets();
List<? extends Terms.Bucket> observationCodeBuckets = aggregatedObservationCodes.getBuckets();
ObjectMapper objectMapper = new ObjectMapper();
List<String> identifiers = new ArrayList<>(10000);
for (Terms.Bucket observationCodeBucket : observationCodeBuckets) {
Aggregations topHitObservationCodes = observationCodeBucket.getAggregations();
ParsedTopHits parsedTopHits = topHitObservationCodes.get("most_recent_effective");
SearchHit[] topHits = parsedTopHits.getHits().getHits();
for (SearchHit topHit : topHits) {
String sources = topHit.getSourceAsString();
ObservationJson code = objectMapper.readValue(sources,ObservationJson.class);
identifiers.add(code.getSubject().substring(8));
}
}
return identifiers;
}
*/
}

View File

@ -1,153 +0,0 @@
package ca.uhn.fhir.jpa.search.lastn;
import ca.uhn.fhir.jpa.search.lastn.json.CodeJson;
import ca.uhn.fhir.jpa.search.lastn.json.ObservationJson;
import ca.uhn.fhir.jpa.search.lastn.util.SimpleStopWatch;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.TokenParam;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.elasticsearch.index.query.functionscore.RandomScoreFunctionBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.tophits.ParsedTopHits;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.junit.Assert.assertEquals;
@Ignore
public class ElasticsearchV5PerformanceTests {
/*
private ElasticsearchV5SvcImpl elasticsearchSvc = new ElasticsearchV5SvcImpl("localhost", 9301, "elastic", "changeme");
private List<String> patientIds = new ArrayList<>();
@Before
public void before() throws IOException {
SearchRequest searchRequest = new SearchRequest(IndexConstants.OBSERVATION_INDEX);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
RandomScoreFunctionBuilder randomScoreFunctionBuilder = new RandomScoreFunctionBuilder();
Date now = new Date();
randomScoreFunctionBuilder.seed(now.getTime());
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(randomScoreFunctionBuilder);
searchSourceBuilder.query(functionScoreQueryBuilder);
searchSourceBuilder.size(0);
// Aggregation by order codes
TermsAggregationBuilder observationCodeValuesBuilder = new TermsAggregationBuilder("group_by_patient", ValueType.STRING).field("subject");
observationCodeValuesBuilder.size(1000);
// Top Hits Aggregation
String[] topHitsInclude = {"subject"};
observationCodeValuesBuilder.subAggregation(AggregationBuilders.topHits("most_recent_effective")
.sort("effectivedtm", SortOrder.DESC)
.fetchSource(topHitsInclude, null).size(1));
searchSourceBuilder.aggregation(observationCodeValuesBuilder);
searchRequest.source(searchSourceBuilder);
// SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
// patientIds = buildResults(response);
}
@Test
public void testObservationCodesQueryPerformance() throws IOException {
// SearchRequest searchRequest = elasticsearchSvc.buildObservationCodesSearchRequest(10000);
long totalElapsedTimes = 0L;
long totalElapsedSearchAndBuildTimes = 0L;
for(int i=0; i<1000; i++) {
SimpleStopWatch stopWatch = new SimpleStopWatch();
// SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
totalElapsedTimes += stopWatch.getElapsedTime();
// List<CodeJson> codes = elasticsearchSvc.buildCodeResult(response);
totalElapsedSearchAndBuildTimes += stopWatch.getElapsedTime();
// assertEquals(1000L, codes.size());
}
System.out.println("Codes query Average elapsed time = " + totalElapsedTimes/1000 + " ms");
System.out.println("Codes query Average elapsed search and build time = " + totalElapsedSearchAndBuildTimes/1000 + " ms");
}
@Test
public void testObservationsQueryPerformance() throws IOException {
long totalElapsedTimes = 0L;
long totalElapsedSearchAndBuildTimes = 0L;
for(String patientId : patientIds) {
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", patientId);
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam("http://mycodes.org/fhir/category-code", "test-category-code");
searchParameterMap.add("category", categoryParam);
// SearchRequest searchRequest = elasticsearchSvc.buildObservationTermsSearchRequest(1000, searchParameterMap, 100);
SimpleStopWatch stopWatch = new SimpleStopWatch();
// SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
totalElapsedTimes += stopWatch.getElapsedTime();
// List<ObservationJson> observations = elasticsearchSvc.buildObservationTermsResults(response);
totalElapsedSearchAndBuildTimes += stopWatch.getElapsedTime();
// assertEquals(25, observations.size());
}
System.out.println("Observations query Average elapsed time = " + totalElapsedTimes/(patientIds.size()) + " ms");
System.out.println("Observations query Average elapsed search and build time = " + totalElapsedSearchAndBuildTimes/(patientIds.size()) + " ms");
}
@Test
public void testLastNObservationsQueryTermsPerformance() throws IOException {
long totalElapsedTimes = 0L;
long totalElapsedSearchAndBuildTimes = 0L;
for(String patientId : patientIds) {
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", patientId);
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam("http://mycodes.org/fhir/category-code", "test-category-code");
searchParameterMap.add("category", categoryParam);
// SearchRequest searchRequest = elasticsearchSvc.buildObservationTermsSearchRequest(1000, searchParameterMap, 5);
SimpleStopWatch stopWatch = new SimpleStopWatch();
// SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
totalElapsedTimes += stopWatch.getElapsedTime();
// elasticsearchSvc.buildObservationTermsResults(response);
totalElapsedSearchAndBuildTimes += stopWatch.getElapsedTime();
}
System.out.println("LastN Average elapsed time = " + totalElapsedTimes/(patientIds.size()) + " ms");
System.out.println("LastN Average elapsed search and Build time = " + totalElapsedSearchAndBuildTimes/(patientIds.size()) + " ms");
}
private List<String> buildResults(SearchResponse theSearchResponse) throws IOException {
Aggregations responseAggregations = theSearchResponse.getAggregations();
ParsedTerms aggregatedObservationCodes = responseAggregations.get("group_by_patient");
aggregatedObservationCodes.getBuckets();
List<? extends Terms.Bucket> observationCodeBuckets = aggregatedObservationCodes.getBuckets();
ObjectMapper objectMapper = new ObjectMapper();
List<String> identifiers = new ArrayList<>(10000);
for (Terms.Bucket observationCodeBucket : observationCodeBuckets) {
Aggregations topHitObservationCodes = observationCodeBucket.getAggregations();
ParsedTopHits parsedTopHits = topHitObservationCodes.get("most_recent_effective");
SearchHit[] topHits = parsedTopHits.getHits().getHits();
for (SearchHit topHit : topHits) {
String sources = topHit.getSourceAsString();
ObservationJson code = objectMapper.readValue(sources,ObservationJson.class);
identifiers.add(code.getSubject().substring(8));
}
}
return identifiers;
}
*/
}

View File

@ -37,8 +37,9 @@ public class LastNElasticsearchSvcSingleObservationTest {
static ObjectMapper ourMapperNonPrettyPrint;
final String RESOURCEPID = "123";
final String SUBJECTID = "4567";
final String SUBJECTTYPEANDID = "Patient/4567";
// final String SUBJECTID = "4567";
// final String SUBJECTTYPEANDID = "Patient/4567";
final String SUBJECTID = "Patient/4567";
final Date EFFECTIVEDTM = new Date();
final String FIRSTCATEGORYTEXT = "Test Codeable Concept Field for first category";
final String CATEGORYFIRSTCODINGSYSTEM = "http://mycodes.org/fhir/observation-category";
@ -150,7 +151,8 @@ public class LastNElasticsearchSvcSingleObservationTest {
ObservationJson observation = observations.get(0);
assertEquals(RESOURCEPID, observation.getIdentifier());
assertEquals(SUBJECTTYPEANDID, observation.getSubject());
// assertEquals(SUBJECTTYPEANDID, observation.getSubject());
assertEquals(SUBJECTID, observation.getSubject());
assertEquals(RESOURCEPID, observation.getIdentifier());
assertEquals(EFFECTIVEDTM, observation.getEffectiveDtm());
assertEquals(OBSERVATIONSINGLECODEID, observation.getCode_concept_id());
@ -322,7 +324,8 @@ public class LastNElasticsearchSvcSingleObservationTest {
private void createSingleObservation() throws IOException {
ObservationJson indexedObservation = new ObservationJson();
indexedObservation.setIdentifier(RESOURCEPID);
indexedObservation.setSubject(SUBJECTTYPEANDID);
// indexedObservation.setSubject(SUBJECTTYPEANDID);
indexedObservation.setSubject(SUBJECTID);
indexedObservation.setEffectiveDtm(EFFECTIVEDTM);
// Add three CodeableConcepts for category

View File

@ -1,312 +0,0 @@
package ca.uhn.fhir.jpa.search.lastn;
import ca.uhn.fhir.jpa.search.lastn.config.TestElasticsearchV5Config;
import ca.uhn.fhir.jpa.search.lastn.json.CodeJson;
import ca.uhn.fhir.jpa.search.lastn.json.ObservationJson;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.TokenParamModifier;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
import java.util.*;
import static org.junit.Assert.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { TestElasticsearchV5Config.class } )
public class LastNElasticsearchV5SvcMultipleObservationsTest {
@Autowired
// private ElasticsearchV5SvcImpl elasticsearchSvc;
private static ObjectMapper ourMapperNonPrettyPrint;
private Map<String,Map<String,List<Date>>> createdPatientObservationMap = new HashMap<>();
@BeforeClass
public static void beforeClass() {
ourMapperNonPrettyPrint = new ObjectMapper();
ourMapperNonPrettyPrint.setSerializationInclusion(JsonInclude.Include.NON_NULL);
ourMapperNonPrettyPrint.disable(SerializationFeature.INDENT_OUTPUT);
ourMapperNonPrettyPrint.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
}
@Before
public void before() throws IOException {
// createMultiplePatientsAndObservations();
}
@After
public void after() throws IOException {
// elasticsearchSvc.deleteAllDocuments(IndexConstants.OBSERVATION_INDEX);
// elasticsearchSvc.deleteAllDocuments(IndexConstants.CODE_INDEX);
}
/*
@Test
public void testLastNNoCriteriaQuery() throws IOException {
// execute Observation ID search (Terms Aggregation) last 3 observations for each patient
SearchRequest searchRequestIdsOnly = elasticsearchSvc.buildObservationTermsSearchRequest(1000, null, 3);
SearchResponse responseIds = elasticsearchSvc.executeSearchRequest(searchRequestIdsOnly);
List<ObservationJson> observationIdsOnly = elasticsearchSvc.buildObservationTermsResults(responseIds);
validateQueryResponse(observationIdsOnly);
}
private void validateQueryResponse(List<ObservationJson> observationIdsOnly) {
assertEquals(60, observationIdsOnly.size());
// Observation documents should be grouped by subject, then by observation code, and then sorted by effective date/time
// within each observation code. Verify the grouping by creating a nested Map.
Map<String,Map<String, List<Date>>> queriedPatientObservationMap = new HashMap<>();
ObservationJson previousObservationJson = null;
for (ObservationJson observationJson : observationIdsOnly) {
assertNotNull(observationJson.getIdentifier());
assertNotNull(observationJson.getSubject());
assertNotNull(observationJson.getCode_concept_id());
assertNotNull(observationJson.getEffectiveDtm());
if (previousObservationJson == null) {
ArrayList<Date> observationDates = new ArrayList<>();
observationDates.add(observationJson.getEffectiveDtm());
Map<String, List<Date>> codeObservationMap = new HashMap<>();
codeObservationMap.put(observationJson.getCode_concept_id(),observationDates);
queriedPatientObservationMap.put(observationJson.getSubject(), codeObservationMap);
} else if (observationJson.getSubject().equals(previousObservationJson.getSubject())) {
if (observationJson.getCode_concept_id().equals(previousObservationJson.getCode_concept_id())) {
queriedPatientObservationMap.get(observationJson.getSubject()).get(observationJson.getCode_concept_id()).
add(observationJson.getEffectiveDtm());
} else {
Map<String, List<Date>> codeObservationDateMap = queriedPatientObservationMap.get(observationJson.getSubject());
// Ensure that code concept was not already retrieved out of order for this subject/patient.
assertFalse(codeObservationDateMap.containsKey(observationJson.getCode_concept_id()));
ArrayList<Date> observationDates = new ArrayList<>();
observationDates.add(observationJson.getEffectiveDtm());
codeObservationDateMap.put(observationJson.getCode_concept_id(),observationDates);
}
} else {
// Ensure that subject/patient was not already retrieved out of order
assertFalse(queriedPatientObservationMap.containsKey(observationJson.getSubject()));
ArrayList<Date> observationDates = new ArrayList<>();
observationDates.add(observationJson.getEffectiveDtm());
Map<String, List<Date>> codeObservationMap = new HashMap<>();
codeObservationMap.put(observationJson.getCode_concept_id(),observationDates);
queriedPatientObservationMap.put(observationJson.getSubject(), codeObservationMap);
}
previousObservationJson = observationJson;
}
// Finally check that only the most recent effective date/time values were returned and in the correct order.
for(String subjectId : queriedPatientObservationMap.keySet()) {
Map<String, List<Date>> queriedObservationCodeMap = queriedPatientObservationMap.get(subjectId);
Map<String, List<Date>> createdObservationCodeMap = createdPatientObservationMap.get(subjectId);
for(String observationCode : queriedObservationCodeMap.keySet()) {
List<Date> queriedObservationDates = queriedObservationCodeMap.get(observationCode);
List<Date> createdObservationDates = createdObservationCodeMap.get(observationCode);
for (int dateIdx=0; dateIdx<queriedObservationDates.size(); dateIdx++) {
assertEquals(createdObservationDates.get(dateIdx), queriedObservationDates.get(dateIdx));
}
}
}
}
@Test
public void testLastNMultiPatientMultiCodeHashMultiCategoryHash() throws IOException {
// Include subject and patient
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", "3");
searchParameterMap.add("subject", subjectParam);
ReferenceParam patientParam = new ReferenceParam("Patient", "", "8");
searchParameterMap.add("patient", patientParam);
TokenParam categoryParam = new TokenParam("http://mycodes.org/fhir/observation-category", "test-heart-rate");
searchParameterMap.add("category", categoryParam);
TokenParam codeParam = new TokenParam("http://mycodes.org/fhir/observation-code", "test-code-1");
searchParameterMap.add("code", codeParam);
SearchRequest searchRequestIdsOnly = elasticsearchSvc.buildObservationTermsSearchRequest(1000, searchParameterMap, 100);
SearchResponse responseIds = elasticsearchSvc.executeSearchRequest(searchRequestIdsOnly);
List<ObservationJson> observationIdsOnly = elasticsearchSvc.buildObservationTermsResults(responseIds);
assertEquals(10, observationIdsOnly.size());
}
@Test
public void testLastNCodeCodeOnlyCategoryCodeOnly() throws IOException {
// Include subject and patient
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", "3");
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam ("test-heart-rate");
searchParameterMap.add("category", categoryParam);
TokenParam codeParam = new TokenParam("test-code-1");
searchParameterMap.add("code", codeParam);
SearchRequest searchRequestIdsOnly = elasticsearchSvc.buildObservationTermsSearchRequest(1000, searchParameterMap, 100);
SearchResponse responseIds = elasticsearchSvc.executeSearchRequest(searchRequestIdsOnly);
List<ObservationJson> observationIdsOnly = elasticsearchSvc.buildObservationTermsResults(responseIds);
assertEquals(5, observationIdsOnly.size());
}
@Test
public void testLastNCodeSystemOnlyCategorySystemOnly() throws IOException {
// Include subject and patient
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", "3");
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam("http://mycodes.org/fhir/observation-category", null);
searchParameterMap.add("category", categoryParam);
TokenParam codeParam = new TokenParam("http://mycodes.org/fhir/observation-code", null);
searchParameterMap.add("code", codeParam);
SearchRequest searchRequestIdsOnly = elasticsearchSvc.buildObservationTermsSearchRequest(1000, searchParameterMap, 100);
SearchResponse responseIds = elasticsearchSvc.executeSearchRequest(searchRequestIdsOnly);
List<ObservationJson> observationIdsOnly = elasticsearchSvc.buildObservationTermsResults(responseIds);
assertEquals(10, observationIdsOnly.size());
}
@Test
public void testLastNCodeCodeTextCategoryTextOnly() throws IOException {
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", "3");
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam("test-heart-rate display");
categoryParam.setModifier(TokenParamModifier.TEXT);
searchParameterMap.add("category", categoryParam);
TokenParam codeParam = new TokenParam("test-code-1 display");
codeParam.setModifier(TokenParamModifier.TEXT);
searchParameterMap.add("code", codeParam);
SearchRequest searchRequestIdsOnly = elasticsearchSvc.buildObservationTermsSearchRequest(1000, searchParameterMap, 100);
SearchResponse responseIds = elasticsearchSvc.executeSearchRequest(searchRequestIdsOnly);
List<ObservationJson> observationIdsOnly = elasticsearchSvc.buildObservationTermsResults(responseIds);
assertEquals(5, observationIdsOnly.size());
}
private void createMultiplePatientsAndObservations() throws IOException {
// Create CodeableConcepts for two Codes, each with three codings.
String codeableConceptId1 = UUID.randomUUID().toString();
CodeableConcept codeableConceptField1 = new CodeableConcept().setText("Test Codeable Concept Field for First Code");
codeableConceptField1.addCoding(new Coding("http://mycodes.org/fhir/observation-code", "test-code-1", "test-code-1 display"));
codeableConceptField1.addCoding(new Coding("http://myalternatecodes.org/fhir/observation-code", "test-alt-code-1", "test-alt-code-1 display"));
codeableConceptField1.addCoding(new Coding("http://mysecondaltcodes.org/fhir/observation-code", "test-second-alt-code-1", "test-second-alt-code-1 display"));
CodeJson codeJson1 = new CodeJson(codeableConceptField1, codeableConceptId1);
String codeJson1Document = ourMapperNonPrettyPrint.writeValueAsString(codeJson1);
String codeableConceptId2 = UUID.randomUUID().toString();
CodeableConcept codeableConceptField2 = new CodeableConcept().setText("Test Codeable Concept Field for Second Code");
codeableConceptField2.addCoding(new Coding("http://mycodes.org/fhir/observation-code", "test-code-2", "test-code-2 display"));
codeableConceptField2.addCoding(new Coding("http://myalternatecodes.org/fhir/observation-code", "test-alt-code-2", "test-alt-code-2 display"));
codeableConceptField2.addCoding(new Coding("http://mysecondaltcodes.org/fhir/observation-code", "test-second-alt-code-2", "test-second-alt-code-2 display"));
CodeJson codeJson2 = new CodeJson(codeableConceptField2, codeableConceptId2);
String codeJson2Document = ourMapperNonPrettyPrint.writeValueAsString(codeJson2);
// Create CodeableConcepts for two categories, each with three codings.
List<Coding> category1 = new ArrayList<>();
// Create three codings and first category CodeableConcept
category1.add(new Coding("http://mycodes.org/fhir/observation-category", "test-heart-rate", "test-heart-rate display"));
category1.add(new Coding("http://myalternatecodes.org/fhir/observation-category", "test-alt-heart-rate", "test-alt-heart-rate display"));
category1.add(new Coding("http://mysecondaltcodes.org/fhir/observation-category", "test-2nd-alt-heart-rate", "test-2nd-alt-heart-rate display"));
List<CodeableConcept> categoryConcepts1 = new ArrayList<>();
CodeableConcept categoryCodeableConcept1 = new CodeableConcept().setText("Test Codeable Concept Field for first category");
categoryCodeableConcept1.setCoding(category1);
categoryConcepts1.add(categoryCodeableConcept1);
// Create three codings and second category CodeableConcept
List<Coding> category2 = new ArrayList<>();
category2.add(new Coding("http://mycodes.org/fhir/observation-category", "test-vital-signs", "test-vital-signs display"));
category2.add(new Coding("http://myalternatecodes.org/fhir/observation-category", "test-alt-vitals", "test-alt-vitals display"));
category2.add(new Coding("http://mysecondaltcodes.org/fhir/observation-category", "test-2nd-alt-vitals", "test-2nd-alt-vitals display"));
List<CodeableConcept> categoryConcepts2 = new ArrayList<>();
CodeableConcept categoryCodeableConcept2 = new CodeableConcept().setText("Test Codeable Concept Field for second category");
categoryCodeableConcept2.setCoding(category2);
categoryConcepts2.add(categoryCodeableConcept2);
for (int patientCount = 0; patientCount < 10 ; patientCount++) {
String subject = "Patient/"+patientCount;
for ( int entryCount = 0; entryCount < 10 ; entryCount++ ) {
ObservationJson observationJson = new ObservationJson();
String identifier = String.valueOf((entryCount + patientCount*10));
observationJson.setIdentifier(identifier);
observationJson.setSubject(subject);
if (entryCount%2 == 1) {
observationJson.setCategories(categoryConcepts1);
observationJson.setCode(codeableConceptField1);
observationJson.setCode_concept_id(codeableConceptId1);
assertTrue(elasticsearchSvc.performIndex(IndexConstants.CODE_INDEX, codeableConceptId1, codeJson1Document, IndexConstants.CODE_DOCUMENT_TYPE));
} else {
observationJson.setCategories(categoryConcepts2);
observationJson.setCode(codeableConceptField2);
observationJson.setCode_concept_id(codeableConceptId2);
assertTrue(elasticsearchSvc.performIndex(IndexConstants.CODE_INDEX, codeableConceptId2, codeJson2Document, IndexConstants.CODE_DOCUMENT_TYPE));
}
Calendar observationDate = new GregorianCalendar();
observationDate.add(Calendar.HOUR, -10 + entryCount);
Date effectiveDtm = observationDate.getTime();
observationJson.setEffectiveDtm(effectiveDtm);
String observationDocument = ourMapperNonPrettyPrint.writeValueAsString(observationJson);
assertTrue(elasticsearchSvc.performIndex(IndexConstants.OBSERVATION_INDEX, identifier,observationDocument, IndexConstants.OBSERVATION_DOCUMENT_TYPE));
if (createdPatientObservationMap.containsKey(subject)) {
Map<String, List<Date>> observationCodeMap = createdPatientObservationMap.get(subject);
if (observationCodeMap.containsKey(observationJson.getCode_concept_id())) {
List<Date> observationDates = observationCodeMap.get(observationJson.getCode_concept_id());
// Want dates to be sorted in descending order
observationDates.add(0, effectiveDtm);
// Only keep the three most recent dates for later check.
if(observationDates.size() > 3) {
observationDates.remove(3);
}
} else {
ArrayList<Date> observationDates = new ArrayList<>();
observationDates.add(effectiveDtm);
observationCodeMap.put(observationJson.getCode_concept_id(), observationDates);
}
} else {
ArrayList<Date> observationDates = new ArrayList<>();
observationDates.add(effectiveDtm);
Map<String, List<Date>> codeObservationMap = new HashMap<>();
codeObservationMap.put(observationJson.getCode_concept_id(), observationDates);
createdPatientObservationMap.put(subject, codeObservationMap);
}
}
}
try {
Thread.sleep(2000L);
} catch (InterruptedException theE) {
theE.printStackTrace();
}
}
*/
}

View File

@ -1,346 +0,0 @@
package ca.uhn.fhir.jpa.search.lastn;
import ca.uhn.fhir.jpa.search.lastn.config.TestElasticsearchV5Config;
import ca.uhn.fhir.jpa.search.lastn.json.CodeJson;
import ca.uhn.fhir.jpa.search.lastn.json.ObservationJson;
import ca.uhn.fhir.jpa.search.lastn.util.CodeSystemHash;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.TokenParam;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { TestElasticsearchV5Config.class } )
public class LastNElasticsearchV5SvcSingleObservationTest {
@Autowired
// ElasticsearchV5SvcImpl elasticsearchSvc;
static ObjectMapper ourMapperNonPrettyPrint;
final String RESOURCEPID = "123";
final String SUBJECTID = "4567";
final String SUBJECTTYPEANDID = "Patient/4567";
final Date EFFECTIVEDTM = new Date();
final String FIRSTCATEGORYTEXT = "Test Codeable Concept Field for first category";
final String CATEGORYFIRSTCODINGSYSTEM = "http://mycodes.org/fhir/observation-category";
final String CATEGORYSECONDCODINGSYSTEM = "http://myalternatecodes.org/fhir/observation-category";
final String CATEGORYTHIRDCODINGSYSTEM = "http://mysecondaltcodes.org/fhir/observation-category";
final String FIRSTCATEGORYFIRSTCODINGCODE = "test-heart-rate";
final String FIRSTCATEGORYFIRSTCODINGDISPLAY = "test-heart-rate display";
final String FIRSTCATEGORYSECONDCODINGCODE = "test-alt-heart-rate";
final String FIRSTCATEGORYSECONDCODINGDISPLAY = "test-alt-heart-rate display";
final String FIRSTCATEGORYTHIRDCODINGCODE = "test-2nd-alt-heart-rate";
final String FIRSTCATEGORYTHIRDCODINGDISPLAY = "test-2nd-alt-heart-rate display";
final String SECONDCATEGORYTEXT = "Test Codeable Concept Field for for second category";
final String SECONDCATEGORYFIRSTCODINGCODE = "test-vital-signs";
final String SECONDCATEGORYFIRSTCODINGDISPLAY = "test-vital-signs display";
final String SECONDCATEGORYSECONDCODINGCODE = "test-alt-vitals";
final String SECONDCATEGORYSECONDCODINGDISPLAY = "test-alt-vitals display";
final String SECONDCATEGORYTHIRDCODINGCODE = "test-2nd-alt-vitals";
final String SECONDCATEGORYTHIRDCODINGDISPLAY = "test-2nd-alt-vitals display";
final String THIRDCATEGORYTEXT = "Test Codeable Concept Field for third category";
final String THIRDCATEGORYFIRSTCODINGCODE = "test-vital-panel";
final String THIRDCATEGORYFIRSTCODINGDISPLAY = "test-vitals-panel display";
final String THIRDCATEGORYSECONDCODINGCODE = "test-alt-vitals-panel";
final String THIRDCATEGORYSECONDCODINGDISPLAY = "test-alt-vitals display";
final String THIRDCATEGORYTHIRDCODINGCODE = "test-2nd-alt-vitals-panel";
final String THIRDCATEGORYTHIRDCODINGDISPLAY = "test-2nd-alt-vitals-panel display";
final String OBSERVATIONSINGLECODEID = UUID.randomUUID().toString();
final String OBSERVATIONCODETEXT = "Test Codeable Concept Field for Code";
final String CODEFIRSTCODINGSYSTEM = "http://mycodes.org/fhir/observation-code";
final String CODEFIRSTCODINGCODE = "test-code";
final String CODEFIRSTCODINGDISPLAY = "test-code display";
final String CODESECONDCODINGSYSTEM = "http://myalternatecodes.org/fhir/observation-code";
final String CODESECONDCODINGCODE = "test-alt-code";
final String CODESECONDCODINGDISPLAY = "test-alt-code display";
final String CODETHIRDCODINGSYSTEM = "http://mysecondaltcodes.org/fhir/observation-code";
final String CODETHIRDCODINGCODE = "test-second-alt-code";
final String CODETHIRDCODINGDISPLAY = "test-second-alt-code display";
@BeforeClass
public static void beforeClass() {
ourMapperNonPrettyPrint = new ObjectMapper();
ourMapperNonPrettyPrint.setSerializationInclusion(JsonInclude.Include.NON_NULL);
ourMapperNonPrettyPrint.disable(SerializationFeature.INDENT_OUTPUT);
ourMapperNonPrettyPrint.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
}
// @Before
public void before() throws IOException {
// elasticsearchSvc.deleteAllDocuments(IndexConstants.OBSERVATION_INDEX);
// elasticsearchSvc.deleteAllDocuments(IndexConstants.CODE_INDEX);
}
@After
public void after() throws IOException {
// elasticsearchSvc.deleteAllDocuments(IndexConstants.OBSERVATION_INDEX);
// elasticsearchSvc.deleteAllDocuments(IndexConstants.CODE_INDEX);
}
@Test
public void testSingleObservationQuery() throws IOException {
createSingleObservation();
SearchParameterMap searchParameterMap = new SearchParameterMap();
ReferenceParam subjectParam = new ReferenceParam("Patient", "", SUBJECTID);
searchParameterMap.add("subject", subjectParam);
TokenParam categoryParam = new TokenParam(CATEGORYFIRSTCODINGSYSTEM, FIRSTCATEGORYFIRSTCODINGCODE);
searchParameterMap.add("category", categoryParam);
TokenParam codeParam = new TokenParam(CODEFIRSTCODINGSYSTEM, CODEFIRSTCODINGCODE);
searchParameterMap.add("code", codeParam);
// execute Observation ID search - Terms Aggregation
/* SearchRequest searchRequestIdsOnly = elasticsearchSvc.buildObservationTermsSearchRequest(1000, searchParameterMap, 3);
SearchResponse responseIds = elasticsearchSvc.executeSearchRequest(searchRequestIdsOnly);
List<ObservationJson> observationIdsOnly = elasticsearchSvc.buildObservationTermsResults(responseIds);
assertEquals(1, observationIdsOnly.size());
ObservationJson observationIdOnly = observationIdsOnly.get(0);
assertEquals(RESOURCEPID, observationIdOnly.getIdentifier());
// execute full Observation search - Terms Aggregation
SearchRequest searchRequestAllFields = elasticsearchSvc.buildObservationAllFieldsTermsSearchRequest(1000, searchParameterMap, 3);
SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequestAllFields);
List<ObservationJson> observations = elasticsearchSvc.buildObservationTermsResults(response);
validateFullObservationSearch(observations);
*/
}
private void validateFullObservationSearch(List<ObservationJson> observations) throws IOException {
assertEquals(1, observations.size());
ObservationJson observation = observations.get(0);
assertEquals(RESOURCEPID, observation.getIdentifier());
assertEquals(SUBJECTTYPEANDID, observation.getSubject());
assertEquals(RESOURCEPID, observation.getIdentifier());
assertEquals(EFFECTIVEDTM, observation.getEffectiveDtm());
assertEquals(OBSERVATIONSINGLECODEID, observation.getCode_concept_id());
List<String> category_concept_text_values = observation.getCategory_concept_text();
assertEquals(3,category_concept_text_values.size());
assertEquals(FIRSTCATEGORYTEXT, category_concept_text_values.get(0));
assertEquals(SECONDCATEGORYTEXT, category_concept_text_values.get(1));
assertEquals(THIRDCATEGORYTEXT, category_concept_text_values.get(2));
List<List<String>> category_codings_systems = observation.getCategory_coding_system();
assertEquals(3,category_codings_systems.size());
List<String> category_coding_systems = category_codings_systems.get(0);
assertEquals(3, category_coding_systems.size());
assertEquals(CATEGORYFIRSTCODINGSYSTEM, category_coding_systems.get(0));
assertEquals(CATEGORYSECONDCODINGSYSTEM, category_coding_systems.get(1));
assertEquals(CATEGORYTHIRDCODINGSYSTEM, category_coding_systems.get(2));
category_codings_systems.get(1);
assertEquals(3, category_coding_systems.size());
assertEquals(CATEGORYFIRSTCODINGSYSTEM, category_coding_systems.get(0));
assertEquals(CATEGORYSECONDCODINGSYSTEM, category_coding_systems.get(1));
assertEquals(CATEGORYTHIRDCODINGSYSTEM, category_coding_systems.get(2));
category_codings_systems.get(2);
assertEquals(3, category_coding_systems.size());
assertEquals(CATEGORYFIRSTCODINGSYSTEM, category_coding_systems.get(0));
assertEquals(CATEGORYSECONDCODINGSYSTEM, category_coding_systems.get(1));
assertEquals(CATEGORYTHIRDCODINGSYSTEM, category_coding_systems.get(2));
List<List<String>> category_codings_codes = observation.getCategory_coding_code();
assertEquals(3, category_codings_codes.size());
List<String> category_coding_codes = category_codings_codes.get(0);
assertEquals(3, category_coding_codes.size());
assertEquals(FIRSTCATEGORYFIRSTCODINGCODE, category_coding_codes.get(0));
assertEquals(FIRSTCATEGORYSECONDCODINGCODE, category_coding_codes.get(1));
assertEquals(FIRSTCATEGORYTHIRDCODINGCODE, category_coding_codes.get(2));
category_coding_codes = category_codings_codes.get(1);
assertEquals(3, category_coding_codes.size());
assertEquals(SECONDCATEGORYFIRSTCODINGCODE, category_coding_codes.get(0));
assertEquals(SECONDCATEGORYSECONDCODINGCODE, category_coding_codes.get(1));
assertEquals(SECONDCATEGORYTHIRDCODINGCODE, category_coding_codes.get(2));
category_coding_codes = category_codings_codes.get(2);
assertEquals(3, category_coding_codes.size());
assertEquals(THIRDCATEGORYFIRSTCODINGCODE, category_coding_codes.get(0));
assertEquals(THIRDCATEGORYSECONDCODINGCODE, category_coding_codes.get(1));
assertEquals(THIRDCATEGORYTHIRDCODINGCODE, category_coding_codes.get(2));
List<List<String>> category_codings_displays = observation.getCategory_coding_display();
assertEquals(3, category_codings_displays.size());
List<String> category_coding_displays = category_codings_displays.get(0);
assertEquals(FIRSTCATEGORYFIRSTCODINGDISPLAY, category_coding_displays.get(0));
assertEquals(FIRSTCATEGORYSECONDCODINGDISPLAY, category_coding_displays.get(1));
assertEquals(FIRSTCATEGORYTHIRDCODINGDISPLAY, category_coding_displays.get(2));
category_coding_displays = category_codings_displays.get(1);
assertEquals(3, category_coding_displays.size());
assertEquals(SECONDCATEGORYFIRSTCODINGDISPLAY, category_coding_displays.get(0));
assertEquals(SECONDCATEGORYSECONDCODINGDISPLAY, category_coding_displays.get(1));
assertEquals(SECONDCATEGORYTHIRDCODINGDISPLAY, category_coding_displays.get(2));
category_coding_displays = category_codings_displays.get(2);
assertEquals(3, category_coding_displays.size());
assertEquals(THIRDCATEGORYFIRSTCODINGDISPLAY, category_coding_displays.get(0));
assertEquals(THIRDCATEGORYSECONDCODINGDISPLAY, category_coding_displays.get(1));
assertEquals(THIRDCATEGORYTHIRDCODINGDISPLAY, category_coding_displays.get(2));
List<List<String>> category_codings_code_system_hashes = observation.getCategory_coding_code_system_hash();
assertEquals(3, category_codings_code_system_hashes.size());
List<String> category_coding_code_system_hashes = category_codings_code_system_hashes.get(0);
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CATEGORYFIRSTCODINGSYSTEM, FIRSTCATEGORYFIRSTCODINGCODE)), category_coding_code_system_hashes.get(0));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CATEGORYSECONDCODINGSYSTEM, FIRSTCATEGORYSECONDCODINGCODE)), category_coding_code_system_hashes.get(1));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CATEGORYTHIRDCODINGSYSTEM, FIRSTCATEGORYTHIRDCODINGCODE)), category_coding_code_system_hashes.get(2));
category_coding_code_system_hashes = category_codings_code_system_hashes.get(1);
assertEquals(3, category_coding_code_system_hashes.size());
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CATEGORYFIRSTCODINGSYSTEM, SECONDCATEGORYFIRSTCODINGCODE)), category_coding_code_system_hashes.get(0));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CATEGORYSECONDCODINGSYSTEM, SECONDCATEGORYSECONDCODINGCODE)), category_coding_code_system_hashes.get(1));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CATEGORYTHIRDCODINGSYSTEM, SECONDCATEGORYTHIRDCODINGCODE)), category_coding_code_system_hashes.get(2));
category_coding_code_system_hashes = category_codings_code_system_hashes.get(2);
assertEquals(3, category_coding_code_system_hashes.size());
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CATEGORYFIRSTCODINGSYSTEM, THIRDCATEGORYFIRSTCODINGCODE)), category_coding_code_system_hashes.get(0));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CATEGORYSECONDCODINGSYSTEM, THIRDCATEGORYSECONDCODINGCODE)), category_coding_code_system_hashes.get(1));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CATEGORYTHIRDCODINGSYSTEM, THIRDCATEGORYTHIRDCODINGCODE)), category_coding_code_system_hashes.get(2));
String code_concept_text_values = observation.getCode_concept_text();
assertEquals(OBSERVATIONCODETEXT, code_concept_text_values);
/*
List<String> code_coding_systems = observation.getCode_coding_system();
assertEquals(3,code_coding_systems.size());
assertEquals(CODEFIRSTCODINGSYSTEM, code_coding_systems.get(0));
assertEquals(CODESECONDCODINGSYSTEM, code_coding_systems.get(1));
assertEquals(CODETHIRDCODINGSYSTEM, code_coding_systems.get(2));
List<String> code_coding_codes = observation.getCode_coding_code();
assertEquals(3, code_coding_codes.size());
assertEquals(CODEFIRSTCODINGCODE, code_coding_codes.get(0));
assertEquals(CODESECONDCODINGCODE, code_coding_codes.get(1));
assertEquals(CODETHIRDCODINGCODE, code_coding_codes.get(2));
List<String> code_coding_display = observation.getCode_coding_display();
assertEquals(3, code_coding_display.size());
assertEquals(CODEFIRSTCODINGDISPLAY, code_coding_display.get(0));
assertEquals(CODESECONDCODINGDISPLAY, code_coding_display.get(1));
assertEquals(CODETHIRDCODINGDISPLAY, code_coding_display.get(2));
List<String> code_coding_code_system_hash = observation.getCode_coding_code_system_hash();
assertEquals(3, code_coding_code_system_hash.size());
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CODEFIRSTCODINGSYSTEM, CODEFIRSTCODINGCODE)), code_coding_code_system_hash.get(0));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CODESECONDCODINGSYSTEM, CODESECONDCODINGCODE)), code_coding_code_system_hash.get(1));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CODETHIRDCODINGSYSTEM, CODETHIRDCODINGCODE)), code_coding_code_system_hash.get(2));
*/
// Retrieve all Observation codes
/* SearchRequest searchRequest = elasticsearchSvc.buildObservationCodesSearchRequest(1000);
SearchResponse response = elasticsearchSvc.executeSearchRequest(searchRequest);
List<CodeJson> codes = elasticsearchSvc.buildCodeResult(response);
assertEquals(1, codes.size());
CodeJson persistedObservationCode = codes.get(0);
String persistedCodeConceptID = persistedObservationCode.getCodeableConceptId();
assertEquals(OBSERVATIONSINGLECODEID, persistedCodeConceptID);
String persistedCodeConceptText = persistedObservationCode.getCodeableConceptText();
assertEquals(OBSERVATIONCODETEXT, persistedCodeConceptText);
List<String> persistedCodeCodingSystems = persistedObservationCode.getCoding_system();
assertEquals(3,persistedCodeCodingSystems.size());
assertEquals(CODEFIRSTCODINGSYSTEM, persistedCodeCodingSystems.get(0));
assertEquals(CODESECONDCODINGSYSTEM, persistedCodeCodingSystems.get(1));
assertEquals(CODETHIRDCODINGSYSTEM, persistedCodeCodingSystems.get(2));
List<String> persistedCodeCodingCodes = persistedObservationCode.getCoding_code();
assertEquals(3, persistedCodeCodingCodes.size());
assertEquals(CODEFIRSTCODINGCODE, persistedCodeCodingCodes.get(0));
assertEquals(CODESECONDCODINGCODE, persistedCodeCodingCodes.get(1));
assertEquals(CODETHIRDCODINGCODE, persistedCodeCodingCodes.get(2));
List<String> persistedCodeCodingDisplays = persistedObservationCode.getCoding_display();
assertEquals(3, persistedCodeCodingDisplays.size());
assertEquals(CODEFIRSTCODINGDISPLAY, persistedCodeCodingDisplays.get(0));
assertEquals(CODESECONDCODINGDISPLAY, persistedCodeCodingDisplays.get(1));
assertEquals(CODETHIRDCODINGDISPLAY, persistedCodeCodingDisplays.get(2));
List<String> persistedCodeCodingCodeSystemHashes = persistedObservationCode.getCoding_code_system_hash();
assertEquals(3, persistedCodeCodingCodeSystemHashes.size());
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CODEFIRSTCODINGSYSTEM, CODEFIRSTCODINGCODE)), persistedCodeCodingCodeSystemHashes.get(0));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CODESECONDCODINGSYSTEM, CODESECONDCODINGCODE)), persistedCodeCodingCodeSystemHashes.get(1));
assertEquals(String.valueOf(CodeSystemHash.hashCodeSystem(CODETHIRDCODINGSYSTEM, CODETHIRDCODINGCODE)), persistedCodeCodingCodeSystemHashes.get(2));
*/
}
private void createSingleObservation() throws IOException {
ObservationJson indexedObservation = new ObservationJson();
indexedObservation.setIdentifier(RESOURCEPID);
indexedObservation.setSubject(SUBJECTTYPEANDID);
indexedObservation.setEffectiveDtm(EFFECTIVEDTM);
// Add three CodeableConcepts for category
List<CodeableConcept> categoryConcepts = new ArrayList<>();
// Create three codings and first category CodeableConcept
List<Coding> category1 = new ArrayList<>();
CodeableConcept categoryCodeableConcept1 = new CodeableConcept().setText(FIRSTCATEGORYTEXT);
category1.add(new Coding(CATEGORYFIRSTCODINGSYSTEM, FIRSTCATEGORYFIRSTCODINGCODE, FIRSTCATEGORYFIRSTCODINGDISPLAY));
category1.add(new Coding(CATEGORYSECONDCODINGSYSTEM, FIRSTCATEGORYSECONDCODINGCODE, FIRSTCATEGORYSECONDCODINGDISPLAY));
category1.add(new Coding(CATEGORYTHIRDCODINGSYSTEM, FIRSTCATEGORYTHIRDCODINGCODE, FIRSTCATEGORYTHIRDCODINGDISPLAY));
categoryCodeableConcept1.setCoding(category1);
categoryConcepts.add(categoryCodeableConcept1);
// Create three codings and second category CodeableConcept
List<Coding> category2 = new ArrayList<>();
CodeableConcept categoryCodeableConcept2 = new CodeableConcept().setText(SECONDCATEGORYTEXT);
category2.add(new Coding(CATEGORYFIRSTCODINGSYSTEM, SECONDCATEGORYFIRSTCODINGCODE, SECONDCATEGORYFIRSTCODINGDISPLAY));
category2.add(new Coding(CATEGORYSECONDCODINGSYSTEM, SECONDCATEGORYSECONDCODINGCODE, SECONDCATEGORYSECONDCODINGDISPLAY));
category2.add(new Coding(CATEGORYTHIRDCODINGSYSTEM, SECONDCATEGORYTHIRDCODINGCODE, SECONDCATEGORYTHIRDCODINGDISPLAY));
categoryCodeableConcept2.setCoding(category2);
categoryConcepts.add(categoryCodeableConcept2);
// Create three codings and third category CodeableConcept
List<Coding> category3 = new ArrayList<>();
CodeableConcept categoryCodeableConcept3 = new CodeableConcept().setText(THIRDCATEGORYTEXT);
category3.add(new Coding(CATEGORYFIRSTCODINGSYSTEM, THIRDCATEGORYFIRSTCODINGCODE, THIRDCATEGORYFIRSTCODINGDISPLAY));
category3.add(new Coding(CATEGORYSECONDCODINGSYSTEM, THIRDCATEGORYSECONDCODINGCODE, THIRDCATEGORYSECONDCODINGDISPLAY));
category3.add(new Coding(CATEGORYTHIRDCODINGSYSTEM, THIRDCATEGORYTHIRDCODINGCODE, THIRDCATEGORYTHIRDCODINGDISPLAY));
categoryCodeableConcept3.setCoding(category3);
categoryConcepts.add(categoryCodeableConcept3);
indexedObservation.setCategories(categoryConcepts);
// Create CodeableConcept for Code with three codings.
indexedObservation.setCode_concept_id(OBSERVATIONSINGLECODEID);
CodeableConcept codeableConceptField = new CodeableConcept().setText(OBSERVATIONCODETEXT);
codeableConceptField.addCoding(new Coding(CODEFIRSTCODINGSYSTEM, CODEFIRSTCODINGCODE, CODEFIRSTCODINGDISPLAY));
codeableConceptField.addCoding(new Coding(CODESECONDCODINGSYSTEM, CODESECONDCODINGCODE, CODESECONDCODINGDISPLAY));
codeableConceptField.addCoding(new Coding(CODETHIRDCODINGSYSTEM, CODETHIRDCODINGCODE, CODETHIRDCODINGDISPLAY));
indexedObservation.setCode(codeableConceptField);
String observationDocument = ourMapperNonPrettyPrint.writeValueAsString(indexedObservation);
// assertTrue(elasticsearchSvc.performIndex(IndexConstants.OBSERVATION_INDEX, RESOURCEPID, observationDocument, IndexConstants.OBSERVATION_DOCUMENT_TYPE));
CodeJson observationCode = new CodeJson(codeableConceptField, OBSERVATIONSINGLECODEID);
String codeDocument = ourMapperNonPrettyPrint.writeValueAsString(observationCode);
// assertTrue(elasticsearchSvc.performIndex(IndexConstants.CODE_INDEX, OBSERVATIONSINGLECODEID, codeDocument, IndexConstants.CODE_DOCUMENT_TYPE));
try {
Thread.sleep(1000L);
} catch (InterruptedException theE) {
theE.printStackTrace();
}
}
}