Skip to content

Commit

Permalink
Merge 663125f into e53d747
Browse files Browse the repository at this point in the history
  • Loading branch information
javajeff committed May 9, 2017
2 parents e53d747 + 663125f commit d44cca3
Show file tree
Hide file tree
Showing 50 changed files with 5,630 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource;
Expand All @@ -48,7 +49,9 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
private List<RuntimeSearchParam> mySearchParams;
private final FhirVersionEnum myStructureVersion;
private volatile RuntimeResourceDefinition myBaseDefinition;




public RuntimeResourceDefinition(FhirContext theContext, String theResourceName, Class<? extends IBaseResource> theClass, ResourceDef theResourceAnnotation, boolean theStandardType, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super(theResourceName, theClass, theStandardType, theContext, theClassToElementDefinitions);
myContext = theContext;
Expand All @@ -68,6 +71,7 @@ public RuntimeResourceDefinition(FhirContext theContext, String theResourceName,

}


public void addSearchParam(RuntimeSearchParam theParam) {
myNameToSearchParam.put(theParam.getName(), theParam);
}
Expand Down
23 changes: 23 additions & 0 deletions hapi-fhir-jpaserver-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
<name>HAPI FHIR JPA Server</name>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate4</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>9.5.1-5</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
Expand Down Expand Up @@ -363,6 +385,7 @@

<properties>
<skip-hib4>false</skip-hib4>
<jackson.version>2.7.1</jackson.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ public IBundleProvider search(final SearchParameterMap theParams, RequestDetails

if (theRequestDetails.isSubRequest()) {
theParams.setLoadSynchronous(true);
int max = myDaoConfig.getMaximumSearchResultCountInTransaction();
theParams.setLoadSynchronousUpTo(myDaoConfig.getMaximumSearchResultCountInTransaction());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public int getIncludeLimit() {
@Deprecated
public List<IServerInterceptor> getInterceptors() {
if (myInterceptors == null) {
return Collections.emptyList();
myInterceptors = new ArrayList<IServerInterceptor>();
}
return myInterceptors;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@

public class FhirResourceDaoDstu1<T extends IResource> extends BaseHapiFhirResourceDao<T> {

@Override
public RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(String criteria) {
return null;
}

@Override
protected List<Object> getIncludeValues(FhirTerser t, Include next, IBaseResource nextResource, RuntimeResourceDefinition def) {
List<Object> values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public MethodOutcome validate(T theResource, IIdType theId, String theRawResourc

}

@Override
public RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(String criteria) {
return null;
}

private class IdChecker implements IValidatorModule {

private ValidationModeEnum myMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import javax.persistence.Query;

import ca.uhn.fhir.model.dstu2.valueset.SubscriptionChannelTypeEnum;
import org.apache.commons.lang3.time.DateUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
Expand Down Expand Up @@ -116,8 +117,12 @@ public synchronized List<IBaseResource> getUndeliveredResourcesAndPurge(Long the
}

@Override
public int pollForNewUndeliveredResources() {
return pollForNewUndeliveredResources((String) null);
}

@Transactional(propagation = Propagation.NOT_SUPPORTED)
public synchronized int pollForNewUndeliveredResources() {
public synchronized int pollForNewUndeliveredResources(final String resourceType) {
if (getConfig().isSubscriptionEnabled() == false) {
return 0;
}
Expand All @@ -141,16 +146,28 @@ public Collection<Long> doInTransaction(TransactionStatus theStatus) {
@Override
public Integer doInTransaction(TransactionStatus theStatus) {
SubscriptionTable nextSubscriptionTable = mySubscriptionTableDao.findOne(nextSubscriptionTablePid);
return pollForNewUndeliveredResources(nextSubscriptionTable);
return pollForNewUndeliveredResources(nextSubscriptionTable, resourceType);
}
});
}

return retVal;
}

private int pollForNewUndeliveredResources(SubscriptionTable theSubscriptionTable) {
private int pollForNewUndeliveredResources(SubscriptionTable theSubscriptionTable, String resourceType) {
Subscription subscription = toResource(Subscription.class, theSubscriptionTable.getSubscriptionResource(), false);
ourLog.info("subscription for " + resourceType + " with criteria " + subscription.getCriteria());

if (!subscription.getChannel().getType().equals(SubscriptionChannelTypeEnum.WEBSOCKET.getCode())){
ourLog.info("Skipping non web socket subscription");
return 0;
}

if (resourceType != null && subscription.getCriteria() != null && !subscription.getCriteria().startsWith(resourceType)) {
ourLog.info("Skipping subscription search for " + resourceType + " because it does not match the criteria " + subscription.getCriteria());
return 0;
}

RuntimeResourceDefinition resourceDef = validateCriteriaAndReturnResourceDefinition(subscription);
SearchParameterMap criteriaUrl = translateMatchUrl(this, getContext(), subscription.getCriteria(), resourceDef);

Expand Down Expand Up @@ -297,7 +314,7 @@ protected ResourceTable updateEntity(IBaseResource theResource, ResourceTable th
return retVal;
}

private RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(Subscription theResource) {
public RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(Subscription theResource) {
String query = theResource.getCriteria();
if (isBlank(query)) {
throw new UnprocessableEntityException("Subscription.criteria must be populated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Set;

import ca.uhn.fhir.context.RuntimeResourceDefinition;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.Resource;
import org.hl7.fhir.instance.model.api.IBaseMetaType;
Expand Down Expand Up @@ -243,6 +244,10 @@ public interface IFhirResourceDao<T extends IBaseResource> extends IDao {
*/
MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails);

RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(String criteria);

<R extends IBaseResource> IFhirResourceDao<R> getDao(Class<R> theType) ;

// /**
// * Invoke the everything operation
// */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ public interface IFhirResourceDaoSubscription<T extends IBaseResource> extends I

void pollForNewUndeliveredResourcesScheduler();

int pollForNewUndeliveredResources(String resourceType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,8 @@ private String determineSystemIfMissing(String theParamName, String code, String
public void loadResourcesByPid(Collection<Long> theIncludePids, List<IBaseResource> theResourceListToPopulate, Set<Long> theRevIncludedPids, boolean theForHistoryOperation,
EntityManager entityManager, FhirContext context, IDao theDao) {
if (theIncludePids.isEmpty()) {
return;
ourLog.info("The include pids are empty");
//return;
}

// Dupes will cause a crash later anyhow, but this is expensive so only do it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.List;

import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.OperationOutcome.IssueSeverity;
Expand Down Expand Up @@ -71,6 +72,9 @@ public class FhirResourceDaoDstu3<T extends IAnyResource> extends BaseHapiFhirRe
@Qualifier("myInstanceValidatorDstu3")
private IValidatorModule myInstanceValidator;

@Autowired
private FhirContext fhirContext;

@Override
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
OperationOutcome oo = new OperationOutcome();
Expand Down Expand Up @@ -163,6 +167,26 @@ public MethodOutcome validate(T theResource, IIdType theId, String theRawResourc

}

/**
* Get the resource definition from the criteria which specifies the resource type
* @param criteria
* @return
*/
@Override
public RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(String criteria) {
String resourceName;
if(criteria == null || criteria.trim().isEmpty()){
throw new IllegalArgumentException("Criteria cannot be empty");
}
if(criteria.contains("?")){
resourceName = criteria.substring(0, criteria.indexOf("?"));
}else{
resourceName = criteria;
}

return fhirContext.getResourceDefinition(resourceName);
}

private class IdChecker implements IValidatorModule {

private ValidationModeEnum myMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ public synchronized List<IBaseResource> getUndeliveredResourcesAndPurge(Long the
return retVal;
}

public int pollForNewUndeliveredResources() {
return pollForNewUndeliveredResources((String) null);
}

@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public synchronized int pollForNewUndeliveredResources() {
public synchronized int pollForNewUndeliveredResources(final String resourceType) {
if (getConfig().isSubscriptionEnabled() == false) {
return 0;
}
Expand All @@ -145,16 +149,27 @@ public Collection<Long> doInTransaction(TransactionStatus theStatus) {
@Override
public Integer doInTransaction(TransactionStatus theStatus) {
SubscriptionTable nextSubscriptionTable = mySubscriptionTableDao.findOne(nextSubscriptionTablePid);
return pollForNewUndeliveredResources(nextSubscriptionTable);
return pollForNewUndeliveredResources(nextSubscriptionTable, resourceType);
}
});
}

return retVal;
}

private int pollForNewUndeliveredResources(SubscriptionTable theSubscriptionTable) {
private int pollForNewUndeliveredResources(SubscriptionTable theSubscriptionTable, String resourceType) {
Subscription subscription = toResource(Subscription.class, theSubscriptionTable.getSubscriptionResource(), false);
if (subscription.getChannel().getType() != Subscription.SubscriptionChannelType.WEBSOCKET){
ourLog.info("Skipping non web socket subscription");
return 0;
}

ourLog.info("subscription for " + resourceType + " with criteria " + subscription.getCriteria());
if (resourceType != null && subscription.getCriteria() != null && !subscription.getCriteria().startsWith(resourceType)) {
ourLog.info("Skipping subscription search for " + resourceType + " because it does not match the criteria " + subscription.getCriteria());
return 0;
}

RuntimeResourceDefinition resourceDef = validateCriteriaAndReturnResourceDefinition(subscription);
SearchParameterMap criteriaUrl = translateMatchUrl(this, getContext(), subscription.getCriteria(), resourceDef);

Expand Down Expand Up @@ -302,7 +317,7 @@ protected ResourceTable updateEntity(IBaseResource theResource, ResourceTable th
return retVal;
}

private RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(Subscription theResource) {
public RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(Subscription theResource) {
String query = theResource.getCriteria();
if (isBlank(query)) {
throw new UnprocessableEntityException("Subscription.criteria must be populated");
Expand Down

0 comments on commit d44cca3

Please sign in to comment.