Add some tests
This commit is contained in:
parent
4e1bbe681a
commit
2518d4e0be
|
@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.dao;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
|
import ca.uhn.fhir.jpa.api.IDaoRegistry;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
|
@ -35,7 +36,7 @@ import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DaoRegistry implements ApplicationContextAware {
|
public class DaoRegistry implements ApplicationContextAware, IDaoRegistry {
|
||||||
private ApplicationContext myAppCtx;
|
private ApplicationContext myAppCtx;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -135,6 +136,11 @@ public class DaoRegistry implements ApplicationContextAware {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isResourceTypeSupported(String theResourceType) {
|
||||||
|
return mySupportedResourceTypes.contains(theResourceType);
|
||||||
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
if (myResourceNameToResourceDao != null && !myResourceNameToResourceDao.isEmpty()) {
|
if (myResourceNameToResourceDao != null && !myResourceNameToResourceDao.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@ -387,6 +388,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test {
|
||||||
upload("/r4/uscore/StructureDefinition-us-core-ethnicity.json");
|
upload("/r4/uscore/StructureDefinition-us-core-ethnicity.json");
|
||||||
upload("/r4/uscore/StructureDefinition-us-core-patient.json");
|
upload("/r4/uscore/StructureDefinition-us-core-patient.json");
|
||||||
upload("/r4/uscore/StructureDefinition-us-core-race.json");
|
upload("/r4/uscore/StructureDefinition-us-core-race.json");
|
||||||
|
upload("/r4/uscore/StructureDefinition-us-core-observation-lab.json");
|
||||||
upload("/r4/uscore/ValueSet-birthsex.json");
|
upload("/r4/uscore/ValueSet-birthsex.json");
|
||||||
upload("/r4/uscore/ValueSet-detailed-ethnicity.json");
|
upload("/r4/uscore/ValueSet-detailed-ethnicity.json");
|
||||||
upload("/r4/uscore/ValueSet-detailed-race.json");
|
upload("/r4/uscore/ValueSet-detailed-race.json");
|
||||||
|
@ -416,6 +418,15 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test {
|
||||||
ourLog.info("Outcome:\n{}", encoded);
|
ourLog.info("Outcome:\n{}", encoded);
|
||||||
assertThat(encoded, containsString("No issues detected"));
|
assertThat(encoded, containsString("No issues detected"));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
String resource = loadResource("/r4/uscore/observation-resource-good.json");
|
||||||
|
IBaseResource parsedResource = myFhirCtx.newJsonParser().parseResource(resource);
|
||||||
|
MethodOutcome outcome = myObservationDao.validate((Observation) parsedResource, null, resource, null, null, null, mySrd);
|
||||||
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
|
String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo);
|
||||||
|
ourLog.info("Outcome:\n{}", encoded);
|
||||||
|
assertThat(encoded, not(containsString("error")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBaseResource findResourceByIdInBundle(Bundle vss, String name) {
|
private IBaseResource findResourceByIdInBundle(Bundle vss, String name) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,76 @@
|
||||||
|
{
|
||||||
|
"resourceType" : "Observation",
|
||||||
|
"id" : "erythrocytes",
|
||||||
|
"meta" : {
|
||||||
|
"versionId" : "1189",
|
||||||
|
"lastUpdated" : "2016-03-09T15:29:58.419+00:00",
|
||||||
|
"profile" : [
|
||||||
|
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"text" : {
|
||||||
|
"status" : "generated",
|
||||||
|
"div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative with Details</b></p><p><b>id</b>: erythrocytes</p><p><b>meta</b>: </p><p><b>status</b>: final</p><p><b>category</b>: Laboratory <span style=\"background: LightGoldenRodYellow\">(Details : {http://terminology.hl7.org/CodeSystem/observation-category code 'laboratory' = 'Laboratory', given as 'Laboratory'})</span></p><p><b>code</b>: RBC # Bld Auto <span style=\"background: LightGoldenRodYellow\">(Details : {LOINC code '789-8' = 'Erythrocytes [#/volume] in Blood by Automated count', given as 'RBC # Bld Auto'})</span></p><p><b>subject</b>: <a href=\"Patient-example.html\">Amy Shaw. Generated Summary: id: example; Medical Record Number = 1032702 (USUAL); active; Amy V. Shaw ; ph: 555-555-5555(HOME), amy.shaw@example.com; gender: female; birthDate: Feb 20, 2007</a></p><p><b>effective</b>: Jul 5, 2005 12:00:00 AM</p><p><b>value</b>: 4.58 10*6/uL</p><h3>ReferenceRanges</h3><table class=\"grid\"><tr><td>-</td><td><b>Low</b></td><td><b>High</b></td><td><b>AppliesTo</b></td></tr><tr><td>*</td><td>4.1 10*6/uL<span style=\"background: LightGoldenRodYellow\"> (Details: UCUM code 10*6/uL = '10*6/uL')</span></td><td>6.1 10*6/uL<span style=\"background: LightGoldenRodYellow\"> (Details: UCUM code 10*6/uL = '10*6/uL')</span></td><td>Normal Range <span style=\"background: LightGoldenRodYellow\">(Details : {http://terminology.hl7.org/CodeSystem/referencerange-meaning code 'normal' = 'Normal Range', given as 'Normal Range'})</span></td></tr></table></div>"
|
||||||
|
},
|
||||||
|
"status" : "final",
|
||||||
|
"category" : [
|
||||||
|
{
|
||||||
|
"coding" : [
|
||||||
|
{
|
||||||
|
"system" : "http://terminology.hl7.org/CodeSystem/observation-category",
|
||||||
|
"code" : "laboratory",
|
||||||
|
"display" : "Laboratory"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"text" : "Laboratory"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"code" : {
|
||||||
|
"coding" : [
|
||||||
|
{
|
||||||
|
"system" : "http://loinc.org",
|
||||||
|
"code" : "789-8",
|
||||||
|
"display" : "RBC # Bld Auto"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"text" : "RBC # Bld Auto"
|
||||||
|
},
|
||||||
|
"subject" : {
|
||||||
|
"reference" : "Patient/example",
|
||||||
|
"display" : "Amy Shaw"
|
||||||
|
},
|
||||||
|
"effectiveDateTime" : "2005-07-05",
|
||||||
|
"valueQuantity" : {
|
||||||
|
"value" : 4.58,
|
||||||
|
"unit" : "10*6/uL",
|
||||||
|
"system" : "http://unitsofmeasure.org"
|
||||||
|
},
|
||||||
|
"referenceRange" : [
|
||||||
|
{
|
||||||
|
"low" : {
|
||||||
|
"value" : 4.1,
|
||||||
|
"unit" : "10*6/uL",
|
||||||
|
"system" : "http://unitsofmeasure.org",
|
||||||
|
"code" : "10*6/uL"
|
||||||
|
},
|
||||||
|
"high" : {
|
||||||
|
"value" : 6.1,
|
||||||
|
"unit" : "10*6/uL",
|
||||||
|
"system" : "http://unitsofmeasure.org",
|
||||||
|
"code" : "10*6/uL"
|
||||||
|
},
|
||||||
|
"appliesTo" : [
|
||||||
|
{
|
||||||
|
"coding" : [
|
||||||
|
{
|
||||||
|
"system" : "http://terminology.hl7.org/CodeSystem/referencerange-meaning",
|
||||||
|
"code" : "normal",
|
||||||
|
"display" : "Normal Range"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"text" : "Normal Range"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package ca.uhn.fhir.jpa.api;
|
||||||
|
|
||||||
|
public interface IDaoRegistry {
|
||||||
|
|
||||||
|
boolean isResourceTypeSupported(String theResourceType);
|
||||||
|
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.subscription.module.cache;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.api.IDaoRegistry;
|
||||||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||||
import ca.uhn.fhir.jpa.searchparam.retry.Retrier;
|
import ca.uhn.fhir.jpa.searchparam.retry.Retrier;
|
||||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
|
@ -49,9 +50,11 @@ public class SubscriptionLoader {
|
||||||
private static final int MAX_RETRIES = 60; // 60 * 5 seconds = 5 minutes
|
private static final int MAX_RETRIES = 60; // 60 * 5 seconds = 5 minutes
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISubscriptionProvider mySubscriptionProvidor;
|
private ISubscriptionProvider mySubscriptionProvider;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SubscriptionRegistry mySubscriptionRegistry;
|
private SubscriptionRegistry mySubscriptionRegistry;
|
||||||
|
@Autowired
|
||||||
|
private IDaoRegistry myDaoRegistry;
|
||||||
|
|
||||||
private final Object mySyncSubscriptionsLock = new Object();
|
private final Object mySyncSubscriptionsLock = new Object();
|
||||||
private Semaphore mySyncSubscriptionsSemaphore = new Semaphore(1);
|
private Semaphore mySyncSubscriptionsSemaphore = new Semaphore(1);
|
||||||
|
@ -62,6 +65,9 @@ public class SubscriptionLoader {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Scheduled(fixedDelay = DateUtils.MILLIS_PER_MINUTE)
|
@Scheduled(fixedDelay = DateUtils.MILLIS_PER_MINUTE)
|
||||||
public void syncSubscriptions() {
|
public void syncSubscriptions() {
|
||||||
|
if (!myDaoRegistry.isResourceTypeSupported("Subscription")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!mySyncSubscriptionsSemaphore.tryAcquire()) {
|
if (!mySyncSubscriptionsSemaphore.tryAcquire()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +104,7 @@ public class SubscriptionLoader {
|
||||||
.addOr(new TokenParam(null, Subscription.SubscriptionStatus.ACTIVE.toCode())));
|
.addOr(new TokenParam(null, Subscription.SubscriptionStatus.ACTIVE.toCode())));
|
||||||
map.setLoadSynchronousUpTo(SubscriptionConstants.MAX_SUBSCRIPTION_RESULTS);
|
map.setLoadSynchronousUpTo(SubscriptionConstants.MAX_SUBSCRIPTION_RESULTS);
|
||||||
|
|
||||||
IBundleProvider subscriptionBundleList = mySubscriptionProvidor.search(map);
|
IBundleProvider subscriptionBundleList = mySubscriptionProvider.search(map);
|
||||||
|
|
||||||
if (subscriptionBundleList.size() >= SubscriptionConstants.MAX_SUBSCRIPTION_RESULTS) {
|
if (subscriptionBundleList.size() >= SubscriptionConstants.MAX_SUBSCRIPTION_RESULTS) {
|
||||||
ourLog.error("Currently over " + SubscriptionConstants.MAX_SUBSCRIPTION_RESULTS + " subscriptions. Some subscriptions have not been loaded.");
|
ourLog.error("Currently over " + SubscriptionConstants.MAX_SUBSCRIPTION_RESULTS + " subscriptions. Some subscriptions have not been loaded.");
|
||||||
|
@ -111,7 +117,7 @@ public class SubscriptionLoader {
|
||||||
for (IBaseResource resource : resourceList) {
|
for (IBaseResource resource : resourceList) {
|
||||||
String nextId = resource.getIdElement().getIdPart();
|
String nextId = resource.getIdElement().getIdPart();
|
||||||
allIds.add(nextId);
|
allIds.add(nextId);
|
||||||
boolean changed = mySubscriptionProvidor.loadSubscription(resource);
|
boolean changed = mySubscriptionProvider.loadSubscription(resource);
|
||||||
if (changed) {
|
if (changed) {
|
||||||
changesCount++;
|
changesCount++;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +132,7 @@ public class SubscriptionLoader {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void setSubscriptionProviderForUnitTest(ISubscriptionProvider theSubscriptionProvider) {
|
public void setSubscriptionProviderForUnitTest(ISubscriptionProvider theSubscriptionProvider) {
|
||||||
mySubscriptionProvidor = theSubscriptionProvider;
|
mySubscriptionProvider = theSubscriptionProvider;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue