A few test fixes

This commit is contained in:
jamesagnew 2018-09-10 08:50:12 -04:00
parent 7b7f3c333b
commit 0e75c8ed39
11 changed files with 188 additions and 284 deletions

View File

@ -56,7 +56,7 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable {
@Column(name = "SP_NAME", length = MAX_SP_NAME, nullable = false)
private String myParamName;
@ManyToOne(optional = false)
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID")
@ContainedIn
private ResourceTable myResource;

View File

@ -1,21 +1,5 @@
package ca.uhn.fhir.jpa.dao.dstu2;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import java.math.BigDecimal;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.*;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.jpa.dao.data.ISearchParamPresentDao;
@ -24,27 +8,48 @@ import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
import ca.uhn.fhir.model.dstu2.composite.*;
import ca.uhn.fhir.model.dstu2.resource.*;
import ca.uhn.fhir.model.dstu2.valueset.*;
import ca.uhn.fhir.model.dstu2.valueset.ContactPointSystemEnum;
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionChannelTypeEnum;
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.model.primitive.*;
import ca.uhn.fhir.rest.api.*;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.*;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.util.TestUtil;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
@SuppressWarnings("unchecked")
public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2SearchNoFtTest.class);
@Autowired
private ISearchParamPresentDao mySearchParamPresentDao;
@Before
public void beforeDisableResultReuse() {
myDaoConfig.setReuseCachedSearchResultsForMillis(null);
}
@Autowired
private ISearchParamPresentDao mySearchParamPresentDao;
@Test
public void testCodeSearch() {
Subscription subs = new Subscription();
@ -110,10 +115,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
List<IIdType> actual = toUnqualifiedVersionlessIds(myDiagnosticOrderDao.search(new SearchParameterMap(DiagnosticOrder.SP_ITEM_DATE, new DateParam("2011-12-12T11:12:12Z")).setLoadSynchronous(true)));
assertThat(actual, contains(id));
Class<ResourceIndexedSearchParamDate> type = ResourceIndexedSearchParamDate.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceIndexedSearchParamDate> type = ResourceIndexedSearchParamDate.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
}
@Test
@ -131,10 +138,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
List<IIdType> actual = toUnqualifiedVersionlessIds(myImmunizationDao.search(new SearchParameterMap(Immunization.SP_DOSE_SEQUENCE, new NumberParam("1")).setLoadSynchronous(true)));
assertThat(actual, contains(id));
Class<ResourceIndexedSearchParamNumber> type = ResourceIndexedSearchParamNumber.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceIndexedSearchParamNumber> type = ResourceIndexedSearchParamNumber.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
}
@Test
@ -147,10 +156,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
IIdType id = mySubstanceDao.create(res, mySrd).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamQuantity> type = ResourceIndexedSearchParamQuantity.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceIndexedSearchParamQuantity> type = ResourceIndexedSearchParamQuantity.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
List<IIdType> actual = toUnqualifiedVersionlessIds(mySubstanceDao.search(new SearchParameterMap(Substance.SP_QUANTITY, new QuantityParam((ParamPrefixEnum) null, 123, "http://foo", "UNIT")).setLoadSynchronous(true)));
assertThat(actual, contains(id));
@ -175,11 +186,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
IIdType id = myDiagnosticOrderDao.create(res, mySrd).getId().toUnqualifiedVersionless();
Class<ResourceLink> type = ResourceLink.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceLink> type = ResourceLink.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
List<IIdType> actual = toUnqualifiedVersionlessIds(myDiagnosticOrderDao.search(new SearchParameterMap(DiagnosticOrder.SP_ACTOR, new ReferenceParam("Practitioner/somepract")).setLoadSynchronous(true)));
assertThat(actual, contains(id));
}
@ -196,10 +208,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
IIdType id = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamString> type = ResourceIndexedSearchParamString.class;
List<ResourceIndexedSearchParamString> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceIndexedSearchParamString> type = ResourceIndexedSearchParamString.class;
List<ResourceIndexedSearchParamString> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
List<IIdType> actual = toUnqualifiedVersionlessIds(myPatientDao.search(new SearchParameterMap(Patient.SP_ADDRESS, new StringParam("123 Fake Street")).setLoadSynchronous(true)));
assertThat(actual, contains(id));
@ -215,10 +229,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
IIdType id = myPatientDao.create(res, mySrd).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamToken> type = ResourceIndexedSearchParamToken.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceIndexedSearchParamToken> type = ResourceIndexedSearchParamToken.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
List<IIdType> actual = toUnqualifiedVersionlessIds(myPatientDao.search(new SearchParameterMap(Patient.SP_IDENTIFIER, new TokenParam("http://foo1", "123")).setLoadSynchronous(true)));
assertThat(actual, contains(id));
@ -234,11 +250,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
IIdType id = myConceptMapDao.create(res, mySrd).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamUri> type = ResourceIndexedSearchParamUri.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceIndexedSearchParamUri> type = ResourceIndexedSearchParamUri.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
List<IIdType> actual = toUnqualifiedVersionlessIds(myConceptMapDao.search(new SearchParameterMap(ConceptMap.SP_DEPENDSON, new UriParam("http://foo")).setLoadSynchronous(true)));
assertThat(actual, contains(id));
}
@ -558,7 +575,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
params = new SearchParameterMap();
params.setLoadSynchronous(true);
params.add("_id", new StringDt("TEST"));
assertEquals(0, toList(myPatientDao.search(params)).size());
@ -1104,7 +1121,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
dr01.setSubject(new ResourceReferenceDt(patientId01));
IIdType drId01 = myDiagnosticReportDao.create(dr01, mySrd).getId();
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 });
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[]{patientId01, patientId02, obsId01, obsId02, drId01});
List<Observation> result = toList(myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_SUBJECT, new ReferenceParam(Patient.SP_IDENTIFIER, "urn:system|testSearchResourceLinkWithChain01"))));
assertEquals(1, result.size());
@ -1197,7 +1214,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
obs02.setSubject(new ResourceReferenceDt(locId01));
IIdType obsId02 = myObservationDao.create(obs02, mySrd).getId();
ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", new Object[] { patientId01, locId01, obsId01, obsId02 });
ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", new Object[]{patientId01, locId01, obsId01, obsId02});
List<Observation> result;
@ -1245,7 +1262,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
dr01.setSubject(new ResourceReferenceDt(patientId01));
IIdType drId01 = myDiagnosticReportDao.create(dr01, mySrd).getId();
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 });
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[]{patientId01, patientId02, obsId01, obsId02, drId01});
List<Observation> result = toList(myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_SUBJECT, new ReferenceParam("testSearchResourceLinkWithTextLogicalId01"))));
assertEquals(1, result.size());
@ -1411,7 +1428,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam001");
patient.addName().addFamily("Tester").addGiven("testSearchTokenParam1");
patient.addCommunication().getLanguage().setText("testSearchTokenParamComText").addCoding().setCode("testSearchTokenParamCode").setSystem("testSearchTokenParamSystem")
.setDisplay("testSearchTokenParamDisplay");
.setDisplay("testSearchTokenParamDisplay");
myPatientDao.create(patient, mySrd);
patient = new Patient();

View File

@ -398,10 +398,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
myEncounterDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Encounter.SP_LOCATION_PERIOD, new DateParam("2011-12-12T11:12:12Z"))));
assertThat(actual, contains(id));
Class<ResourceIndexedSearchParamDate> type = ResourceIndexedSearchParamDate.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(()->{
Class<ResourceIndexedSearchParamDate> type = ResourceIndexedSearchParamDate.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
}
@Test
@ -419,10 +422,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
List<IIdType> actual = toUnqualifiedVersionlessIds(myImmunizationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Immunization.SP_DOSE_SEQUENCE, new NumberParam("1"))));
assertThat(actual, contains(id));
Class<ResourceIndexedSearchParamNumber> type = ResourceIndexedSearchParamNumber.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(()-> {
Class<ResourceIndexedSearchParamNumber> type = ResourceIndexedSearchParamNumber.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
}
@Test

View File

@ -517,13 +517,8 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
include.setSystem(URL_MY_CODE_SYSTEM);
include.addConcept().setCode("ZZZZ");
try {
myValueSetDao.expand(vs, null);
fail();
} catch (InvalidRequestException e) {
assertEquals("Unable to find code 'ZZZZ' in code system http://example.com/my_code_system", e.getMessage());
}
ValueSet expansion = myValueSetDao.expand(vs, null);
assertEquals(0, expansion.getExpansion().getContains().size());
}
@Test
@ -543,36 +538,6 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
}
}
@Test
public void testExpandWithSystemAndCodesAndFilterKeywordInLocalValueSet() {
createLocalCsAndVs();
ValueSet vs = new ValueSet();
ConceptSetComponent include = vs.getCompose().addInclude();
include.setSystem(URL_MY_CODE_SYSTEM);
include.addConcept().setCode("A");
include.addFilter().setProperty("display").setOp(FilterOperator.EQUAL).setValue("AAA");
ValueSet result = myValueSetDao.expand(vs, null);
// Technically it's not valid to expand a ValueSet with both includes and filters so the
// result fails validation because of the input.. we're being permissive by allowing both
// though, so we won't validate the input
result.setCompose(new ValueSetComposeComponent());
logAndValidateValueSet(result);
ArrayList<String> codes = toCodesContains(result.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("A", "AAA"));
int idx = codes.indexOf("AAA");
assertEquals("AAA", result.getExpansion().getContains().get(idx).getCode());
assertEquals("Code AAA", result.getExpansion().getContains().get(idx).getDisplay());
assertEquals(URL_MY_CODE_SYSTEM, result.getExpansion().getContains().get(idx).getSystem());
//
}
@Test
public void testExpandWithSystemAndCodesInExternalValueSet() {
createExternalCsAndLocalVs();

View File

@ -1,12 +1,9 @@
package ca.uhn.fhir.jpa.dao.dstu3;
<<<<<<< master
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
=======
>>>>>>> master
import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.ValidationModeEnum;
@ -16,16 +13,9 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.util.StopWatch;
import ca.uhn.fhir.util.TestUtil;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.Organization;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
@ -34,14 +24,8 @@ import org.junit.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
<<<<<<< master
=======
import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
>>>>>>> master
public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3ValidateTest.class);

View File

@ -200,10 +200,10 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
/**
* See #1053
*
* <p>
* Note that I don't know that _lastUpdate actually should apply to reverse includes. The
* spec doesn't say one way or ther other, but it seems like sensible behaviour to me.
*
* <p>
* Definitely the $everything operation depends on this behaviour, so if we change it
* we need to account for the everything operation...
*/
@ -573,10 +573,12 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
myEncounterDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Encounter.SP_LOCATION_PERIOD, new DateParam("2011-12-12T11:12:12Z"))));
assertThat(actual, contains(id));
Class<ResourceIndexedSearchParamDate> type = ResourceIndexedSearchParamDate.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceIndexedSearchParamDate> type = ResourceIndexedSearchParamDate.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
}
@Test
@ -629,7 +631,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
IIdType id = mySubstanceDao.create(res, mySrd).getId().toUnqualifiedVersionless();
runInTransaction(()->{
runInTransaction(() -> {
Class<ResourceIndexedSearchParamQuantity> type = ResourceIndexedSearchParamQuantity.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
ourLog.info(toStringMultiline(results));
@ -689,10 +691,12 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
IIdType id = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamString> type = ResourceIndexedSearchParamString.class;
List<ResourceIndexedSearchParamString> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceIndexedSearchParamString> type = ResourceIndexedSearchParamString.class;
List<ResourceIndexedSearchParamString> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
List<IIdType> actual = toUnqualifiedVersionlessIds(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_ADDRESS, new StringParam("123 Fake Street"))));
assertThat(actual, contains(id));
@ -708,13 +712,15 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
IIdType id = myPatientDao.create(res, mySrd).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamToken> type = ResourceIndexedSearchParamToken.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
runInTransaction(() -> {
Class<ResourceIndexedSearchParamToken> type = ResourceIndexedSearchParamToken.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
// This is 3 for now because the FluentPath for Patient:deceased adds a value.. this should
// be corrected at some point, and we'll then drop back down to 2
assertEquals(3, results.size());
});
// This is 3 for now because the FluentPath for Patient:deceased adds a value.. this should
// be corrected at some point, and we'll then drop back down to 2
assertEquals(3, results.size());
List<IIdType> actual = toUnqualifiedVersionlessIds(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_IDENTIFIER, new TokenParam("http://foo1", "123"))));
assertThat(actual, contains(id));
@ -732,10 +738,12 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
IIdType id = myValueSetDao.create(res, mySrd).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamUri> type = ResourceIndexedSearchParamUri.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
runInTransaction(() -> {
Class<ResourceIndexedSearchParamUri> type = ResourceIndexedSearchParamUri.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList();
ourLog.info(toStringMultiline(results));
assertEquals(2, results.size());
});
List<IIdType> actual = toUnqualifiedVersionlessIds(myValueSetDao.search(new SearchParameterMap().setLoadSynchronous(true).add(ValueSet.SP_REFERENCE, new UriParam("http://foo"))));
assertThat(actual, contains(id));

View File

@ -289,7 +289,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test {
.setValue(".*\\^Donor$");
outcome = myTermSvc.expandValueSet(vs);
codes = toCodesContains(outcome.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("43343-3"));
assertThat(codes, containsInAnyOrder("43343-3", "43343-4"));
}
@Test
@ -405,7 +405,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test {
.setValue("^Ser$");
outcome = myTermSvc.expandValueSet(vs);
codes = toCodesContains(outcome.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("43343-3"));
assertThat(codes, containsInAnyOrder("43343-3", "43343-4"));
}

View File

@ -10,11 +10,7 @@ import ca.uhn.fhir.validation.IValidatorModule;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.*;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
@ -23,12 +19,7 @@ import org.fhir.ucum.UcumService;
import org.hl7.fhir.convertors.VersionConvertor_30_40;
import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext;
import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Questionnaire;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.TerminologyServiceException;
import org.hl7.fhir.r4.context.IWorkerContext;
@ -49,19 +40,15 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@SuppressWarnings({"PackageAccessibility", "Duplicates"})
public class FhirInstanceValidator extends BaseValidatorBridge implements IValidatorModule {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidator.class);
@ -108,18 +95,14 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
return root.getLocalName();
}
private ArrayList<String> determineIfProfilesSpecified(Document theDocument)
{
private ArrayList<String> determineIfProfilesSpecified(Document theDocument) {
ArrayList<String> profileNames = new ArrayList<String>();
NodeList list = theDocument.getChildNodes().item(0).getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
if (list.item(i).getNodeName().compareToIgnoreCase("meta") == 0)
{
if (list.item(i).getNodeName().compareToIgnoreCase("meta") == 0) {
NodeList metaList = list.item(i).getChildNodes();
for (int j = 0; j < metaList.getLength(); j++)
{
if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0)
{
for (int j = 0; j < metaList.getLength(); j++) {
if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0) {
profileNames.add(metaList.item(j).getAttributes().item(0).getNodeValue());
}
}
@ -134,20 +117,8 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
try {
// Test if a URL was passed in specifying the structure definition and test if "StructureDefinition" is part of the URL
URL testIfUrl = new URL(resourceName);
if (resourceName.toLowerCase().contains("structuredefinition"))
{
sdName = resourceName;
}
else
{
ourLog.error(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s",
resourceName));
throw new InternalErrorException(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s",
resourceName));
}
}
catch (MalformedURLException e)
{
sdName = resourceName;
} catch (MalformedURLException e) {
sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName;
}
StructureDefinition profile = myStructureDefintion != null ? myStructureDefintion : myValidationSupport.fetchStructureDefinition(theCtx, sdName);
@ -283,8 +254,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
// Determine if meta/profiles are present...
ArrayList<String> resourceNames = determineIfProfilesSpecified(document);
if (resourceNames.isEmpty())
{
if (resourceNames.isEmpty()) {
resourceNames.add(determineResourceName(document));
}
@ -297,9 +267,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
ourLog.error("Failure during validation", e);
throw new InternalErrorException("Unexpected failure while validating resource", e);
}
}
else
{
} else {
profile = findStructureDefinitionForResourceName(theCtx, determineResourceName(document));
if (profile != null) {
try {
@ -319,8 +287,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
JsonArray profiles = null;
try {
profiles = json.getAsJsonObject("meta").getAsJsonArray("profile");
for (JsonElement element : profiles)
{
for (JsonElement element : profiles) {
resourceNames.add(element.getAsString());
}
} catch (Exception e) {
@ -335,9 +302,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
} catch (Exception e) {
throw new InternalErrorException("Unexpected failure while validating resource", e);
}
}
else
{
} else {
profile = findStructureDefinitionForResourceName(theCtx, json.get("resourceType").getAsString());
if (profile != null) {
try {
@ -385,40 +350,40 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
}
myFetchResourceCache = Caffeine.newBuilder()
.expireAfterWrite(timeoutMillis, TimeUnit.MILLISECONDS)
.maximumSize(10000)
.build(new CacheLoader<ResourceKey, org.hl7.fhir.r4.model.Resource>() {
@Override
public org.hl7.fhir.r4.model.Resource load(ResourceKey key) throws Exception {
Resource fetched;
switch (key.getResourceName()) {
case "StructureDefinition":
fetched = myWrap.fetchResource(StructureDefinition.class, key.getUri());
break;
case "ValueSet":
fetched = myWrap.fetchResource(ValueSet.class, key.getUri());
break;
case "CodeSystem":
fetched = myWrap.fetchResource(CodeSystem.class, key.getUri());
break;
case "Questionnaire":
fetched = myWrap.fetchResource(Questionnaire.class, key.getUri());
break;
default:
throw new UnsupportedOperationException("Don't know how to fetch " + key.getResourceName());
}
.expireAfterWrite(timeoutMillis, TimeUnit.MILLISECONDS)
.maximumSize(10000)
.build(new CacheLoader<ResourceKey, org.hl7.fhir.r4.model.Resource>() {
@Override
public org.hl7.fhir.r4.model.Resource load(ResourceKey key) throws Exception {
Resource fetched;
switch (key.getResourceName()) {
case "StructureDefinition":
fetched = myWrap.fetchResource(StructureDefinition.class, key.getUri());
break;
case "ValueSet":
fetched = myWrap.fetchResource(ValueSet.class, key.getUri());
break;
case "CodeSystem":
fetched = myWrap.fetchResource(CodeSystem.class, key.getUri());
break;
case "Questionnaire":
fetched = myWrap.fetchResource(Questionnaire.class, key.getUri());
break;
default:
throw new UnsupportedOperationException("Don't know how to fetch " + key.getResourceName());
}
if (fetched == null) {
return null;
}
if (fetched == null) {
return null;
}
try {
return VersionConvertor_30_40.convertResource(fetched);
} catch (FHIRException e) {
throw new InternalErrorException(e);
try {
return VersionConvertor_30_40.convertResource(fetched);
} catch (FHIRException e) {
throw new InternalErrorException(e);
}
}
}
});
});
}
@Override

View File

@ -172,17 +172,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
try {
// Test if a URL was passed in specifying the structure definition and test if "StructureDefinition" is part of the URL
URL testIfUrl = new URL(resourceName);
if (resourceName.toLowerCase().contains("structuredefinition"))
{
sdName = resourceName;
}
else
{
ourLog.error(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s",
resourceName));
throw new InternalErrorException(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s",
resourceName));
}
}
catch (MalformedURLException e)
{

View File

@ -6,11 +6,7 @@ import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.validation.IValidationContext;
import ca.uhn.fhir.validation.IValidatorModule;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.*;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.exceptions.PathEngineException;
import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport;
@ -30,6 +26,8 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
@ -37,9 +35,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
public class FhirInstanceValidator extends BaseValidatorBridge implements IValidatorModule {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidator.class);
@ -54,7 +49,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
/**
* Constructor
*
* <p>
* Uses {@link DefaultProfileValidationSupport} for {@link IValidationSupport validation support}
*/
public FhirInstanceValidator() {
@ -63,9 +58,8 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
/**
* Constructor which uses the given validation support
*
* @param theValidationSupport
* The validation support
*
* @param theValidationSupport The validation support
*/
public FhirInstanceValidator(IValidationSupport theValidationSupport) {
myDocBuilderFactory = DocumentBuilderFactory.newInstance();
@ -87,18 +81,14 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
return root.getLocalName();
}
private ArrayList<String> determineIfProfilesSpecified(Document theDocument)
{
private ArrayList<String> determineIfProfilesSpecified(Document theDocument) {
ArrayList<String> profileNames = new ArrayList<String>();
NodeList list = theDocument.getChildNodes().item(0).getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
if (list.item(i).getNodeName().compareToIgnoreCase("meta") == 0)
{
if (list.item(i).getNodeName().compareToIgnoreCase("meta") == 0) {
NodeList metaList = list.item(i).getChildNodes();
for (int j = 0; j < metaList.getLength(); j++)
{
if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0)
{
for (int j = 0; j < metaList.getLength(); j++) {
if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0) {
profileNames.add(metaList.item(j).getAttributes().item(0).getNodeValue());
}
}
@ -113,20 +103,8 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
try {
// Test if a URL was passed in specifying the structure definition and test if "StructureDefinition" is part of the URL
URL testIfUrl = new URL(resourceName);
if (resourceName.toLowerCase().contains("structuredefinition"))
{
sdName = resourceName;
}
else
{
ourLog.error(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s",
resourceName));
throw new InternalErrorException(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s",
resourceName));
}
}
catch (MalformedURLException e)
{
sdName = resourceName;
} catch (MalformedURLException e) {
sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName;
}
StructureDefinition profile = myStructureDefintion != null ? myStructureDefintion : myValidationSupport.fetchStructureDefinition(theCtx, sdName);
@ -141,7 +119,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
* reported at the ERROR level. If this setting is set to {@link BestPracticeWarningLevel#Ignore}, best practice
* guielines will be ignored.
* </p>
*
*
* @see {@link #setBestPracticeWarningLevel(BestPracticeWarningLevel)}
*/
public BestPracticeWarningLevel getBestPracticeWarningLevel() {
@ -158,8 +136,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
* guielines will be ignored.
* </p>
*
* @param theBestPracticeWarningLevel
* The level, must not be <code>null</code>
* @param theBestPracticeWarningLevel The level, must not be <code>null</code>
*/
public void setBestPracticeWarningLevel(BestPracticeWarningLevel theBestPracticeWarningLevel) {
Validate.notNull(theBestPracticeWarningLevel);
@ -252,8 +229,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
// Determine if meta/profiles are present...
ArrayList<String> resourceNames = determineIfProfilesSpecified(document);
if (resourceNames.isEmpty())
{
if (resourceNames.isEmpty()) {
resourceNames.add(determineResourceName(document));
}
@ -266,9 +242,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
ourLog.error("Failure during validation", e);
throw new InternalErrorException("Unexpected failure while validating resource", e);
}
}
else
{
} else {
profile = findStructureDefinitionForResourceName(theCtx, determineResourceName(document));
if (profile != null) {
try {
@ -288,8 +262,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
JsonArray profiles = null;
try {
profiles = json.getAsJsonObject("meta").getAsJsonArray("profile");
for (JsonElement element : profiles)
{
for (JsonElement element : profiles) {
resourceNames.add(element.getAsString());
}
} catch (Exception e) {
@ -304,9 +277,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
} catch (Exception e) {
throw new InternalErrorException("Unexpected failure while validating resource", e);
}
}
else
{
} else {
profile = findStructureDefinitionForResourceName(theCtx, json.get("resourceType").getAsString());
if (profile != null) {
try {

View File

@ -34,8 +34,6 @@ import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport;
import org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext;
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.r4.hapi.ctx.PrePopulatedValidationSupport;
import org.hl7.fhir.r4.hapi.ctx.ValidationSupportChain;
import org.hl7.fhir.r4.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.r4.model.Base;
import org.hl7.fhir.r4.model.Base64BinaryType;
@ -102,6 +100,7 @@ public class FhirInstanceValidatorR4Test {
private static FhirContext ourCtx = FhirContext.forR4();
@Rule
public TestRule watcher = new TestWatcher() {
@Override
protected void starting(Description description) {
ourLog.info("Starting test: " + description.getMethodName());
}