Tester improvements
This commit is contained in:
parent
d3b4a3ad60
commit
1b7b141396
|
@ -49,6 +49,9 @@ diagnosticreport.title=classpath:ca/uhn/fhir/narrative/title/DiagnosticReport.ht
|
|||
encounter.class=ca.uhn.fhir.model.dstu.resource.Encounter
|
||||
encounter.title=classpath:ca/uhn/fhir/narrative/title/Encounter.html
|
||||
|
||||
organization.class=ca.uhn.fhir.model.dstu.resource.Organization
|
||||
organization.title=classpath:ca/uhn/fhir/narrative/title/Organization.html
|
||||
|
||||
patient.class=ca.uhn.fhir.model.dstu.resource.Patient
|
||||
patient.narrative=classpath:ca/uhn/fhir/narrative/Patient.html
|
||||
patient.title=classpath:ca/uhn/fhir/narrative/title/Patient.html
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<div>
|
||||
<th:block th:if="${not resource.name.empty}" th:text="${resource.name.value}"/>
|
||||
<th:block th:if="${resource.name.empty}">Unknown Organization</th:block>
|
||||
</div>
|
|
@ -20,6 +20,7 @@ import ca.uhn.fhir.model.dstu.resource.Conformance;
|
|||
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
|
||||
import ca.uhn.fhir.model.dstu.resource.Encounter;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.valueset.DiagnosticReportStatusEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.EncounterClassEnum;
|
||||
|
@ -89,6 +90,21 @@ public class DefaultThymeleafNarrativeGeneratorTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateOrganization() throws DataFormatException {
|
||||
Organization enc = new Organization();
|
||||
|
||||
enc.addIdentifier("urn:visits", "1234567");
|
||||
enc.setName("Some Test Org");
|
||||
enc.addAddress().addLine("123 Fake St").setCity("Toronto").setState("ON").setCountry("Canada").setZip("12345");
|
||||
|
||||
String title = gen.generateTitle(enc);
|
||||
assertEquals("Some Test Org", title);
|
||||
ourLog.info(title);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerateServerConformance() throws DataFormatException {
|
||||
Conformance value = myCtx.newXmlParser().parseResource(Conformance.class, new InputStreamReader(getClass().getResourceAsStream("/server-conformance-statement.xml")));
|
||||
|
|
|
@ -27,6 +27,7 @@ import javax.persistence.criteria.Predicate;
|
|||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
@ -78,37 +79,28 @@ import com.google.common.base.Function;
|
|||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public abstract class BaseFhirDao {
|
||||
public abstract class BaseFhirDao implements IDao {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseFhirDao.class);
|
||||
|
||||
@Autowired(required = true)
|
||||
private DaoConfig myConfig;
|
||||
|
||||
@Autowired(required = true)
|
||||
private FhirContext myContext;
|
||||
|
||||
@PersistenceContext(name = "FHIR_UT", type = PersistenceContextType.TRANSACTION, unitName = "FHIR_UT")
|
||||
private EntityManager myEntityManager;
|
||||
private List<IDaoListener> myListeners = new ArrayList<IDaoListener>();
|
||||
|
||||
@Autowired
|
||||
private List<IFhirResourceDao<?>> myResourceDaos;
|
||||
|
||||
private Map<Class<? extends IResource>, IFhirResourceDao<?>> myResourceTypeToDao;
|
||||
|
||||
protected void loadResourcesById(Set<IdDt> theIncludePids, List<IResource> theResourceListToPopulate) {
|
||||
Set<Long> pids = new HashSet<Long>();
|
||||
for (IdDt next : theIncludePids) {
|
||||
pids.add(next.getIdPartAsLong());
|
||||
}
|
||||
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceTable> cq = builder.createQuery(ResourceTable.class);
|
||||
Root<ResourceTable> from = cq.from(ResourceTable.class);
|
||||
// cq.where(builder.equal(from.get("myResourceType"),
|
||||
// getContext().getResourceDefinition(myResourceType).getName()));
|
||||
// if (theIncludePids != null) {
|
||||
cq.where(from.get("myId").in(pids));
|
||||
// }
|
||||
TypedQuery<ResourceTable> q = myEntityManager.createQuery(cq);
|
||||
|
||||
for (ResourceTable next : q.getResultList()) {
|
||||
IResource resource = toResource(next);
|
||||
theResourceListToPopulate.add(resource);
|
||||
protected void notifyWriteCompleted() {
|
||||
for (IDaoListener next : myListeners) {
|
||||
next.writeCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,16 +108,67 @@ public abstract class BaseFhirDao {
|
|||
return myContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDaoListener(IDaoListener theListener) {
|
||||
Validate.notNull(theListener, "theListener");
|
||||
myListeners.add(theListener);
|
||||
}
|
||||
|
||||
public void setContext(FhirContext theContext) {
|
||||
myContext = theContext;
|
||||
}
|
||||
|
||||
protected DaoConfig getConfig() {
|
||||
return myConfig;
|
||||
private void findMatchingTagIds(String theResourceName, IdDt theResourceId, Set<Long> tagIds, Class<? extends BaseTag> entityClass) {
|
||||
{
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Tuple> cq = builder.createTupleQuery();
|
||||
Root<? extends BaseTag> from = cq.from(entityClass);
|
||||
cq.multiselect(from.get("myTagId").as(Long.class)).distinct(true);
|
||||
|
||||
if (theResourceName != null) {
|
||||
Predicate typePredicate = builder.equal(from.get("myResourceType"), theResourceName);
|
||||
if (theResourceId != null) {
|
||||
cq.where(typePredicate, builder.equal(from.get("myResourceId"), theResourceId.getIdPartAsLong()));
|
||||
} else {
|
||||
cq.where(typePredicate);
|
||||
}
|
||||
}
|
||||
|
||||
TypedQuery<Tuple> query = myEntityManager.createQuery(cq);
|
||||
for (Tuple next : query.getResultList()) {
|
||||
tagIds.add(next.get(0, Long.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired(required = true)
|
||||
private DaoConfig myConfig;
|
||||
private void searchHistoryCurrentVersion(List<HistoryTuple> theTuples, List<BaseHasResource> theRetVal) {
|
||||
Collection<HistoryTuple> tuples = Collections2.filter(theTuples, new com.google.common.base.Predicate<HistoryTuple>() {
|
||||
@Override
|
||||
public boolean apply(HistoryTuple theInput) {
|
||||
return theInput.isHistory() == false;
|
||||
}
|
||||
});
|
||||
Collection<Long> ids = Collections2.transform(tuples, new Function<HistoryTuple, Long>() {
|
||||
@Override
|
||||
public Long apply(HistoryTuple theInput) {
|
||||
return theInput.getId();
|
||||
}
|
||||
});
|
||||
if (ids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceTable> cq = builder.createQuery(ResourceTable.class);
|
||||
Root<ResourceTable> from = cq.from(ResourceTable.class);
|
||||
cq.where(from.get("myId").in(ids));
|
||||
|
||||
cq.orderBy(builder.desc(from.get("myUpdated")));
|
||||
TypedQuery<ResourceTable> q = myEntityManager.createQuery(cq);
|
||||
for (ResourceTable next : q.getResultList()) {
|
||||
theRetVal.add(next);
|
||||
}
|
||||
}
|
||||
|
||||
private void searchHistoryCurrentVersion(String theResourceName, Long theId, Date theSince, Date theEnd, Integer theLimit, List<HistoryTuple> tuples) {
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
|
@ -165,31 +208,33 @@ public abstract class BaseFhirDao {
|
|||
}
|
||||
}
|
||||
|
||||
private void searchHistoryCurrentVersion(List<HistoryTuple> theTuples, List<BaseHasResource> theRetVal) {
|
||||
private void searchHistoryHistory(List<HistoryTuple> theTuples, List<BaseHasResource> theRetVal) {
|
||||
Collection<HistoryTuple> tuples = Collections2.filter(theTuples, new com.google.common.base.Predicate<HistoryTuple>() {
|
||||
@Override
|
||||
public boolean apply(HistoryTuple theInput) {
|
||||
return theInput.isHistory() == false;
|
||||
return theInput.isHistory() == true;
|
||||
}
|
||||
});
|
||||
Collection<Long> ids = Collections2.transform(tuples, new Function<HistoryTuple, Long>() {
|
||||
@Override
|
||||
public Long apply(HistoryTuple theInput) {
|
||||
return theInput.getId();
|
||||
return (Long) theInput.getId();
|
||||
}
|
||||
});
|
||||
if (ids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ourLog.info("Retrieving {} history elements from ResourceHistoryTable", ids.size());
|
||||
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceTable> cq = builder.createQuery(ResourceTable.class);
|
||||
Root<ResourceTable> from = cq.from(ResourceTable.class);
|
||||
CriteriaQuery<ResourceHistoryTable> cq = builder.createQuery(ResourceHistoryTable.class);
|
||||
Root<ResourceHistoryTable> from = cq.from(ResourceHistoryTable.class);
|
||||
cq.where(from.get("myId").in(ids));
|
||||
|
||||
cq.orderBy(builder.desc(from.get("myUpdated")));
|
||||
TypedQuery<ResourceTable> q = myEntityManager.createQuery(cq);
|
||||
for (ResourceTable next : q.getResultList()) {
|
||||
TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery(cq);
|
||||
for (ResourceHistoryTable next : q.getResultList()) {
|
||||
theRetVal.add(next);
|
||||
}
|
||||
}
|
||||
|
@ -232,39 +277,6 @@ public abstract class BaseFhirDao {
|
|||
}
|
||||
}
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseFhirDao.class);
|
||||
|
||||
private void searchHistoryHistory(List<HistoryTuple> theTuples, List<BaseHasResource> theRetVal) {
|
||||
Collection<HistoryTuple> tuples = Collections2.filter(theTuples, new com.google.common.base.Predicate<HistoryTuple>() {
|
||||
@Override
|
||||
public boolean apply(HistoryTuple theInput) {
|
||||
return theInput.isHistory() == true;
|
||||
}
|
||||
});
|
||||
Collection<Long> ids = Collections2.transform(tuples, new Function<HistoryTuple, Long>() {
|
||||
@Override
|
||||
public Long apply(HistoryTuple theInput) {
|
||||
return (Long) theInput.getId();
|
||||
}
|
||||
});
|
||||
if (ids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ourLog.info("Retrieving {} history elements from ResourceHistoryTable", ids.size());
|
||||
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceHistoryTable> cq = builder.createQuery(ResourceHistoryTable.class);
|
||||
Root<ResourceHistoryTable> from = cq.from(ResourceHistoryTable.class);
|
||||
cq.where(from.get("myId").in(ids));
|
||||
|
||||
cq.orderBy(builder.desc(from.get("myUpdated")));
|
||||
TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery(cq);
|
||||
for (ResourceHistoryTable next : q.getResultList()) {
|
||||
theRetVal.add(next);
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ResourceLink> extractResourceLinks(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<ResourceLink> retVal = new ArrayList<ResourceLink>();
|
||||
|
||||
|
@ -424,8 +436,7 @@ public abstract class BaseFhirDao {
|
|||
|
||||
if (nextObject instanceof QuantityDt) {
|
||||
QuantityDt nextValue = (QuantityDt) nextObject;
|
||||
ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, nextValue.getValue().getValue(), nextValue.getSystem().getValueAsString(),
|
||||
nextValue.getUnits().getValue());
|
||||
ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, nextValue.getValue().getValue(), nextValue.getSystem().getValueAsString(), nextValue.getUnits().getValue());
|
||||
nextEntity.setResource(theEntity);
|
||||
retVal.add(nextEntity);
|
||||
} else {
|
||||
|
@ -513,8 +524,7 @@ public abstract class BaseFhirDao {
|
|||
} else if (nextObject instanceof ContactDt) {
|
||||
ContactDt nextContact = (ContactDt) nextObject;
|
||||
if (nextContact.getValue().isEmpty() == false) {
|
||||
ResourceIndexedSearchParamString nextEntity = new ResourceIndexedSearchParamString(resourceName, normalizeString(nextContact.getValue().getValueAsString()), nextContact
|
||||
.getValue().getValueAsString());
|
||||
ResourceIndexedSearchParamString nextEntity = new ResourceIndexedSearchParamString(resourceName, normalizeString(nextContact.getValue().getValueAsString()), nextContact.getValue().getValueAsString());
|
||||
nextEntity.setResource(theEntity);
|
||||
retVal.add(nextEntity);
|
||||
}
|
||||
|
@ -606,7 +616,7 @@ public abstract class BaseFhirDao {
|
|||
|
||||
assert systems.size() == codes.size() : "Systems contains " + systems + ", codes contains: " + codes;
|
||||
|
||||
Set<Pair<String, String>> haveValues = new HashSet<Pair<String,String>>();
|
||||
Set<Pair<String, String>> haveValues = new HashSet<Pair<String, String>>();
|
||||
for (int i = 0; i < systems.size(); i++) {
|
||||
String system = systems.get(i);
|
||||
String code = codes.get(i);
|
||||
|
@ -621,7 +631,7 @@ public abstract class BaseFhirDao {
|
|||
code = code.substring(0, ResourceIndexedSearchParamToken.MAX_LENGTH);
|
||||
}
|
||||
|
||||
Pair<String, String> nextPair = Pair.of(system,code);
|
||||
Pair<String, String> nextPair = Pair.of(system, code);
|
||||
if (haveValues.contains(nextPair)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -641,6 +651,10 @@ public abstract class BaseFhirDao {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
protected DaoConfig getConfig() {
|
||||
return myConfig;
|
||||
}
|
||||
|
||||
protected IFhirResourceDao<? extends IResource> getDao(Class<? extends IResource> theType) {
|
||||
if (myResourceTypeToDao == null) {
|
||||
myResourceTypeToDao = new HashMap<Class<? extends IResource>, IFhirResourceDao<?>>();
|
||||
|
@ -658,6 +672,60 @@ public abstract class BaseFhirDao {
|
|||
return myResourceTypeToDao.get(theType);
|
||||
}
|
||||
|
||||
protected TagDefinition getTag(String theScheme, String theTerm, String theLabel) {
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<TagDefinition> cq = builder.createQuery(TagDefinition.class);
|
||||
Root<TagDefinition> from = cq.from(TagDefinition.class);
|
||||
cq.where(builder.and(builder.equal(from.get("myScheme"), theScheme), builder.equal(from.get("myTerm"), theTerm)));
|
||||
TypedQuery<TagDefinition> q = myEntityManager.createQuery(cq);
|
||||
try {
|
||||
return q.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
TagDefinition retVal = new TagDefinition(theTerm, theLabel, theScheme);
|
||||
myEntityManager.persist(retVal);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
protected TagList getTags(Class<? extends IResource> theResourceType, IdDt theResourceId) {
|
||||
String resourceName = null;
|
||||
if (theResourceType != null) {
|
||||
resourceName = toResourceName(theResourceType);
|
||||
if (theResourceId != null && theResourceId.hasVersionIdPart()) {
|
||||
IFhirResourceDao<? extends IResource> dao = getDao(theResourceType);
|
||||
BaseHasResource entity = dao.readEntity(theResourceId);
|
||||
TagList retVal = new TagList();
|
||||
for (BaseTag next : entity.getTags()) {
|
||||
retVal.add(next.getTag().toTag());
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
Set<Long> tagIds = new HashSet<Long>();
|
||||
findMatchingTagIds(resourceName, theResourceId, tagIds, ResourceTag.class);
|
||||
findMatchingTagIds(resourceName, theResourceId, tagIds, ResourceHistoryTag.class);
|
||||
if (tagIds.isEmpty()) {
|
||||
return new TagList();
|
||||
}
|
||||
{
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<TagDefinition> cq = builder.createQuery(TagDefinition.class);
|
||||
Root<TagDefinition> from = cq.from(TagDefinition.class);
|
||||
cq.where(from.get("myId").in(tagIds));
|
||||
cq.orderBy(builder.asc(from.get("myScheme")), builder.asc(from.get("myTerm")));
|
||||
TypedQuery<TagDefinition> q = myEntityManager.createQuery(cq);
|
||||
q.setMaxResults(getConfig().getHardTagListLimit());
|
||||
|
||||
TagList retVal = new TagList();
|
||||
for (TagDefinition next : q.getResultList()) {
|
||||
retVal.add(next.toTag());
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
protected IBundleProvider history(String theResourceName, Long theId, Date theSince) {
|
||||
final List<HistoryTuple> tuples = new ArrayList<HistoryTuple>();
|
||||
|
||||
|
@ -683,8 +751,8 @@ public abstract class BaseFhirDao {
|
|||
return new IBundleProvider() {
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return tuples.size();
|
||||
public InstantDt getPublished() {
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -719,16 +787,32 @@ public abstract class BaseFhirDao {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InstantDt getPublished() {
|
||||
return end;
|
||||
public int size() {
|
||||
return tuples.size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
InstantDt createHistoryToTimestamp() {
|
||||
// final InstantDt end = new InstantDt(DateUtils.addSeconds(DateUtils.truncate(new Date(), Calendar.SECOND),
|
||||
// -1));
|
||||
return InstantDt.withCurrentTime();
|
||||
protected void loadResourcesById(Set<IdDt> theIncludePids, List<IResource> theResourceListToPopulate) {
|
||||
Set<Long> pids = new HashSet<Long>();
|
||||
for (IdDt next : theIncludePids) {
|
||||
pids.add(next.getIdPartAsLong());
|
||||
}
|
||||
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceTable> cq = builder.createQuery(ResourceTable.class);
|
||||
Root<ResourceTable> from = cq.from(ResourceTable.class);
|
||||
// cq.where(builder.equal(from.get("myResourceType"),
|
||||
// getContext().getResourceDefinition(myResourceType).getName()));
|
||||
// if (theIncludePids != null) {
|
||||
cq.where(from.get("myId").in(pids));
|
||||
// }
|
||||
TypedQuery<ResourceTable> q = myEntityManager.createQuery(cq);
|
||||
|
||||
for (ResourceTable next : q.getResultList()) {
|
||||
IResource resource = toResource(next);
|
||||
theResourceListToPopulate.add(resource);
|
||||
}
|
||||
}
|
||||
|
||||
protected String normalizeString(String theString) {
|
||||
|
@ -744,21 +828,6 @@ public abstract class BaseFhirDao {
|
|||
return new String(out).toUpperCase();
|
||||
}
|
||||
|
||||
protected TagDefinition getTag(String theScheme, String theTerm, String theLabel) {
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<TagDefinition> cq = builder.createQuery(TagDefinition.class);
|
||||
Root<TagDefinition> from = cq.from(TagDefinition.class);
|
||||
cq.where(builder.and(builder.equal(from.get("myScheme"), theScheme), builder.equal(from.get("myTerm"), theTerm)));
|
||||
TypedQuery<TagDefinition> q = myEntityManager.createQuery(cq);
|
||||
try {
|
||||
return q.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
TagDefinition retVal = new TagDefinition(theTerm, theLabel, theScheme);
|
||||
myEntityManager.persist(retVal);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
protected void populateResourceIntoEntity(IResource theResource, ResourceTable theEntity) {
|
||||
|
||||
if (theEntity.getPublished().isEmpty()) {
|
||||
|
@ -863,14 +932,14 @@ public abstract class BaseFhirDao {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
protected String toResourceName(IResource theResource) {
|
||||
return myContext.getResourceDefinition(theResource).getName();
|
||||
}
|
||||
|
||||
protected String toResourceName(Class<? extends IResource> theResourceType) {
|
||||
return myContext.getResourceDefinition(theResourceType).getName();
|
||||
}
|
||||
|
||||
protected String toResourceName(IResource theResource) {
|
||||
return myContext.getResourceDefinition(theResource).getName();
|
||||
}
|
||||
|
||||
protected ResourceTable updateEntity(final IResource theResource, ResourceTable entity, boolean theUpdateHistory, boolean theDelete) {
|
||||
if (entity.getPublished() == null) {
|
||||
entity.setPublished(new Date());
|
||||
|
@ -987,66 +1056,10 @@ public abstract class BaseFhirDao {
|
|||
return entity;
|
||||
}
|
||||
|
||||
protected TagList getTags(Class<? extends IResource> theResourceType, IdDt theResourceId) {
|
||||
String resourceName = null;
|
||||
if (theResourceType != null) {
|
||||
resourceName = toResourceName(theResourceType);
|
||||
if (theResourceId != null && theResourceId.hasVersionIdPart()) {
|
||||
IFhirResourceDao<? extends IResource> dao = getDao(theResourceType);
|
||||
BaseHasResource entity = dao.readEntity(theResourceId);
|
||||
TagList retVal = new TagList();
|
||||
for (BaseTag next : entity.getTags()) {
|
||||
retVal.add(next.getTag().toTag());
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
Set<Long> tagIds = new HashSet<Long>();
|
||||
findMatchingTagIds(resourceName, theResourceId, tagIds, ResourceTag.class);
|
||||
findMatchingTagIds(resourceName, theResourceId, tagIds, ResourceHistoryTag.class);
|
||||
if (tagIds.isEmpty()) {
|
||||
return new TagList();
|
||||
}
|
||||
{
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<TagDefinition> cq = builder.createQuery(TagDefinition.class);
|
||||
Root<TagDefinition> from = cq.from(TagDefinition.class);
|
||||
cq.where(from.get("myId").in(tagIds));
|
||||
cq.orderBy(builder.asc(from.get("myScheme")), builder.asc(from.get("myTerm")));
|
||||
TypedQuery<TagDefinition> q = myEntityManager.createQuery(cq);
|
||||
q.setMaxResults(getConfig().getHardTagListLimit());
|
||||
|
||||
TagList retVal = new TagList();
|
||||
for (TagDefinition next : q.getResultList()) {
|
||||
retVal.add(next.toTag());
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
private void findMatchingTagIds(String theResourceName, IdDt theResourceId, Set<Long> tagIds, Class<? extends BaseTag> entityClass) {
|
||||
{
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Tuple> cq = builder.createTupleQuery();
|
||||
Root<? extends BaseTag> from = cq.from(entityClass);
|
||||
cq.multiselect(from.get("myTagId").as(Long.class)).distinct(true);
|
||||
|
||||
if (theResourceName != null) {
|
||||
Predicate typePredicate = builder.equal(from.get("myResourceType"), theResourceName);
|
||||
if (theResourceId != null) {
|
||||
cq.where(typePredicate, builder.equal(from.get("myResourceId"), theResourceId.getIdPartAsLong()));
|
||||
} else {
|
||||
cq.where(typePredicate);
|
||||
}
|
||||
}
|
||||
|
||||
TypedQuery<Tuple> query = myEntityManager.createQuery(cq);
|
||||
for (Tuple next : query.getResultList()) {
|
||||
tagIds.add(next.get(0, Long.class));
|
||||
}
|
||||
}
|
||||
InstantDt createHistoryToTimestamp() {
|
||||
// final InstantDt end = new InstantDt(DateUtils.addSeconds(DateUtils.truncate(new Date(), Calendar.SECOND),
|
||||
// -1));
|
||||
return InstantDt.withCurrentTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -517,6 +517,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
|
||||
myEntityManager.persist(newEntity);
|
||||
myEntityManager.merge(entity);
|
||||
notifyWriteCompleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -527,6 +528,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
updateEntity(theResource, entity, false, false);
|
||||
|
||||
MethodOutcome outcome = toMethodOutcome(entity);
|
||||
notifyWriteCompleted();
|
||||
return outcome;
|
||||
}
|
||||
|
||||
|
@ -1021,6 +1023,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
|
||||
ResourceTable savedEntity = updateEntity(theResource, entity, true, false);
|
||||
|
||||
notifyWriteCompleted();
|
||||
return toMethodOutcome(savedEntity);
|
||||
}
|
||||
|
||||
|
@ -1033,6 +1036,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
|
||||
ResourceTable savedEntity = updateEntity(null, entity, true, true);
|
||||
|
||||
notifyWriteCompleted();
|
||||
return toMethodOutcome(savedEntity);
|
||||
}
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ public class FhirSystemDao extends BaseFhirDao implements IFhirSystemDao {
|
|||
long delay = System.currentTimeMillis() - start;
|
||||
ourLog.info("Transaction completed in {}ms with {} creations and {} updates", new Object[] {delay, creations, updates});
|
||||
|
||||
notifyWriteCompleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package ca.uhn.fhir.jpa.dao;
|
||||
|
||||
public interface IDao {
|
||||
|
||||
void registerDaoListener(IDaoListener theListener);
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package ca.uhn.fhir.jpa.dao;
|
||||
|
||||
public interface IDaoListener {
|
||||
|
||||
void writeCompleted();
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
|
|||
import ca.uhn.fhir.rest.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||
|
||||
public interface IFhirResourceDao<T extends IResource> {
|
||||
public interface IFhirResourceDao<T extends IResource> extends IDao {
|
||||
|
||||
void addTag(IdDt theId, String theScheme, String theTerm, String theLabel);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import ca.uhn.fhir.model.api.IResource;
|
|||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.rest.server.IBundleProvider;
|
||||
|
||||
public interface IFhirSystemDao {
|
||||
public interface IFhirSystemDao extends IDao {
|
||||
|
||||
void transaction(List<IResource> theResources);
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
package ca.uhn.fhir.jpa.provider;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.IDaoListener;
|
||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance.Rest;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance.RestResource;
|
||||
import ca.uhn.fhir.model.primitive.DecimalDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider;
|
||||
|
||||
|
@ -15,19 +17,33 @@ public class JpaConformanceProvider extends ServerConformanceProvider {
|
|||
|
||||
private String myImplementationDescription;
|
||||
private IFhirSystemDao mySystemDao;
|
||||
private volatile Conformance myCachedValue;
|
||||
|
||||
public JpaConformanceProvider(RestfulServer theRestfulServer, IFhirSystemDao theSystemDao) {
|
||||
public JpaConformanceProvider(RestfulServer theRestfulServer, IFhirSystemDao theSystemDao, @SuppressWarnings("rawtypes") Collection<IFhirResourceDao> theResourceDaos) {
|
||||
super(theRestfulServer);
|
||||
mySystemDao = theSystemDao;
|
||||
super.setCache(false);
|
||||
|
||||
for (IFhirResourceDao<?> nextResourceDao : theResourceDaos) {
|
||||
nextResourceDao.registerDaoListener(new IDaoListener() {
|
||||
@Override
|
||||
public void writeCompleted() {
|
||||
myCachedValue = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Conformance getServerConformance() {
|
||||
Conformance retVal = myCachedValue;
|
||||
if (retVal != null) {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
Map<String, Long> counts = mySystemDao.getResourceCounts();
|
||||
|
||||
Conformance retVal = super.getServerConformance();
|
||||
retVal = super.getServerConformance();
|
||||
for (Rest nextRest : retVal.getRest()) {
|
||||
for (RestResource nextResource : nextRest.getResource()) {
|
||||
Long count = counts.get(nextResource.getType().getValueAsString());
|
||||
|
@ -38,7 +54,7 @@ public class JpaConformanceProvider extends ServerConformanceProvider {
|
|||
}
|
||||
|
||||
retVal.getImplementation().setDescription(myImplementationDescription);
|
||||
|
||||
myCachedValue = retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
|
||||
import ca.uhn.fhir.jpa.provider.JpaConformanceProvider;
|
||||
import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
|
||||
|
@ -57,7 +58,10 @@ public class TestRestfulServer extends RestfulServer {
|
|||
|
||||
String implDesc = getInitParameter("ImplementationDescription");
|
||||
|
||||
JpaConformanceProvider confProvider = new JpaConformanceProvider(this, systemDao);
|
||||
@SuppressWarnings("rawtypes")
|
||||
Collection<IFhirResourceDao> resourceDaos = myAppCtx.getBeansOfType(IFhirResourceDao.class).values();
|
||||
|
||||
JpaConformanceProvider confProvider = new JpaConformanceProvider(this, systemDao, resourceDaos);
|
||||
confProvider.setImplementationDescription(implDesc);
|
||||
setServerConformanceProvider(confProvider);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="pull-right">
|
||||
<object data="img/fhirtest-architecture.svg" width="383" height="369" type="image/svg+xml" />
|
||||
<object data="img/fhirtest-architecture.svg" width="383" height="369" type="image/svg+xml"></object>
|
||||
</div>
|
||||
<p>
|
||||
This server provides a nearly complete implementation of the FHIR Specification
|
||||
|
|
|
@ -21,9 +21,7 @@
|
|||
<link href="css/tester.css" rel="stylesheet" />
|
||||
<link href="css/hapi-narrative.css" rel="stylesheet" />
|
||||
|
||||
<!--
|
||||
<script type="text/javascript" src="js/moment.min.js"></script>
|
||||
-->
|
||||
|
||||
<!-- Datetimepicker Component -->
|
||||
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
|
||||
|
|
|
@ -82,10 +82,16 @@ function addSearchControls(theSearchParamType, theSearchParamName, theSearchPara
|
|||
$('<input />', { id: 'param.' + theRowNum + '.2', placeholder: 'value', type: 'text', 'class': 'form-control' })
|
||||
)
|
||||
);
|
||||
} else if (theSearchParamType == 'string' || theSearchParamType == 'number') {
|
||||
} else if (theSearchParamType == 'string' || theSearchParamType == 'number' || theSearchParamType == 'reference') {
|
||||
var placeholderText = 'value';
|
||||
if (theSearchParamType == 'number') {
|
||||
placeholderText = 'Number';
|
||||
} else if (theSearchParamType == 'reference') {
|
||||
placeholderText = 'Resource ID';
|
||||
}
|
||||
$('#search-param-rowopts-' + theContainerRowNum).append(
|
||||
$('<div />', { 'class': 'col-sm-3' }).append(
|
||||
$('<input />', { id: 'param.' + theRowNum + '.0', placeholder: 'value', type: 'text', 'class': 'form-control' })
|
||||
$('<input />', { id: 'param.' + theRowNum + '.0', placeholder: placeholderText, type: 'text', 'class': 'form-control' })
|
||||
)
|
||||
);
|
||||
} else if (theSearchParamType == 'date') {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,7 @@
|
|||
package ca.uhn.fhir.jpa.test;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -85,6 +86,9 @@ public class OverlayTestApp {
|
|||
|
||||
|
||||
IFhirSystemDao systemDao = appCtx.getBean("mySystemDao", IFhirSystemDao.class);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
Collection<IFhirResourceDao> resourceDaos = appCtx.getBeansOfType(IFhirResourceDao.class).values();
|
||||
JpaSystemProvider systemProvider = new JpaSystemProvider(systemDao);
|
||||
|
||||
RestfulServer restServer = new RestfulServer();
|
||||
|
@ -97,7 +101,7 @@ public class OverlayTestApp {
|
|||
restServer.setPagingProvider(new FifoMemoryPagingProvider(10));
|
||||
restServer.setImplementationDescription("This is a great server!!!!");
|
||||
|
||||
JpaConformanceProvider confProvider = new JpaConformanceProvider(restServer, systemDao);
|
||||
JpaConformanceProvider confProvider = new JpaConformanceProvider(restServer, systemDao,resourceDaos);
|
||||
restServer.setServerConformanceProvider(confProvider);
|
||||
|
||||
myPort = 8887;
|
||||
|
|
Loading…
Reference in New Issue