Skip to content

Commit

Permalink
Support URI (and prepare for lat/lon search params) in JPA server, and
Browse files Browse the repository at this point in the history
don't store duplicate tags
  • Loading branch information
jamesagnew committed Sep 1, 2015
1 parent b6f6340 commit 97e6073
Show file tree
Hide file tree
Showing 38 changed files with 49,884 additions and 981 deletions.
2 changes: 2 additions & 0 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Tag.java
Expand Up @@ -37,6 +37,8 @@
*/
public class Tag extends BaseElement implements IElement {

private static final long serialVersionUID = 1L;

public static final String ATTR_LABEL = "label";
public static final String ATTR_SCHEME = "scheme";
public static final String ATTR_TERM = "term";
Expand Down
Expand Up @@ -633,8 +633,9 @@ public AtomPrimitiveState(IPrimitiveDatatype<?> thePrimitive) {
public void attributeValue(String theName, String theValue) throws DataFormatException {
if (myJsonMode) {
string(theValue);
} else {
super.attributeValue(theName, theValue);
}
super.attributeValue(theName, theValue);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions hapi-fhir-cli/.gitignore
@@ -1,2 +1,3 @@
/build/
/target/
/target/
Expand Up @@ -31,6 +31,9 @@ private void execute() throws IOException, ClientProtocolException, UnsupportedE

IGenericClient client = newClient(ctx);

int total;
int count;

// String vsContents =
// IOUtils.toString(ValidationDataUploader.class.getResourceAsStream("/org/hl7/fhir/instance/model/valueset/valuesets.xml"),
// "UTF-8");
Expand All @@ -50,12 +53,8 @@ private void execute() throws IOException, ClientProtocolException, UnsupportedE
//
// ourLog.info("Finished uploading ValueSets");

String vsContents = IOUtils.toString(ValidationDataUploader.class.getResourceAsStream("/org/hl7/fhir/instance/model/valueset/v3-codesystems.xml"), "UTF-8");
Bundle bundle = ctx.newXmlParser().parseResource(Bundle.class, vsContents);

int total;
int count;

// String vsContents = IOUtils.toString(ValidationDataUploader.class.getResourceAsStream("/org/hl7/fhir/instance/model/valueset/v3-codesystems.xml"), "UTF-8");
// Bundle bundle = ctx.newXmlParser().parseResource(Bundle.class, vsContents);
// total = bundle.getEntry().size();
// count = 1;
// for (BundleEntryComponent i : bundle.getEntry()) {
Expand All @@ -68,19 +67,36 @@ private void execute() throws IOException, ClientProtocolException, UnsupportedE
// count++;
// }


String vsContents = IOUtils.toString(ValidationDataUploader.class.getResourceAsStream("/org/hl7/fhir/instance/model/valueset/v2-tables.xml"), "UTF-8");
Bundle bundle = ctx.newXmlParser().parseResource(Bundle.class, vsContents);
total = bundle.getEntry().size();
count = 1;
for (BundleEntryComponent i : bundle.getEntry()) {
if (count > 1900) {
ValueSet next = (ValueSet) i.getResource();
next.setId(next.getIdElement().toUnqualifiedVersionless());

ourLog.info("Uploading v2-tables ValueSet {}/{} : {}", new Object[] { count, total, next.getIdElement().getValue() });
client.update().resource(next).execute();
}
count++;
}

ourLog.info("Finished uploading ValueSets");

ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
Resource[] mappingLocations = patternResolver.getResources("classpath*:org/hl7/fhir/instance/model/profile/*.profile.xml");
total = mappingLocations.length;
count = 1;
for (Resource i : mappingLocations) {
if (count > 140) {
StructureDefinition next = ctx.newXmlParser().parseResource(StructureDefinition.class, IOUtils.toString(i.getInputStream(), "UTF-8"));
next.setId(next.getIdElement().toUnqualifiedVersionless());

ourLog.info("Uploading StructureDefinition {}/{} : {}", new Object[] { count, total, next.getIdElement().getValue() });
client.update().resource(next).execute();

}
count++;
}

Expand Down
1 change: 1 addition & 0 deletions hapi-fhir-jpaserver-base/db.txt
Expand Up @@ -8,6 +8,7 @@ delete from hfj_spidx_quantity where res_id in (select res_id from hfj_resource
delete from hfj_spidx_string where res_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_spidx_token where res_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_res_link where src_resource_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_res_link where target_resource_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_res_tag where res_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_resource where res_id in (select res_id from hfj_resource where sp_index_status = 2);

Expand Up @@ -77,11 +77,13 @@
import ca.uhn.fhir.jpa.entity.ResourceEncodingEnum;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTag;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamCoords;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamDate;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamNumber;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamQuantity;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamToken;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri;
import ca.uhn.fhir.jpa.entity.ResourceLink;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.entity.ResourceTag;
Expand Down Expand Up @@ -255,10 +257,17 @@ protected List<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceT
return mySearchParamExtractor.extractSearchParamDates(theEntity, theResource);
}

protected ArrayList<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IResource theResource) {
protected List<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IResource theResource) {
return mySearchParamExtractor.extractSearchParamNumber(theEntity, theResource);
}

protected List<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IResource theResource) {
return mySearchParamExtractor.extractSearchParamUri(theEntity, theResource);
}
protected List<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IResource theResource) {
return mySearchParamExtractor.extractSearchParamCoords(theEntity, theResource);
}

protected List<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) {
return mySearchParamExtractor.extractSearchParamQuantity(theEntity, theResource);
}
Expand Down Expand Up @@ -611,10 +620,13 @@ protected void populateResourceIntoEntity(IResource theResource, ResourceTable t
throw new InternalErrorException(e);
}

Set<TagDefinition> allDefs = new HashSet<TagDefinition>();

TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource);
if (tagList != null) {
for (Tag next : tagList) {
TagDefinition tag = getTag(TagTypeEnum.TAG, next.getScheme(), next.getTerm(), next.getLabel());
allDefs.add(tag);
theEntity.addTag(tag);
theEntity.setHasTags(true);
}
Expand All @@ -624,19 +636,33 @@ protected void populateResourceIntoEntity(IResource theResource, ResourceTable t
if (securityLabels != null) {
for (BaseCodingDt next : securityLabels) {
TagDefinition tag = getTag(TagTypeEnum.SECURITY_LABEL, next.getSystemElement().getValue(), next.getCodeElement().getValue(), next.getDisplayElement().getValue());
allDefs.add(tag);
theEntity.addTag(tag);
theEntity.setHasTags(true);
}
}

}
List<IdDt> profiles = ResourceMetadataKeyEnum.PROFILES.get(theResource);
if (profiles != null) {
for (IIdType next : profiles) {
TagDefinition tag = getTag(TagTypeEnum.PROFILE, NS_JPA_PROFILE, next.getValue(), null);
allDefs.add(tag);
theEntity.addTag(tag);
theEntity.setHasTags(true);
}
}


for (ResourceTag next : new ArrayList<ResourceTag>(theEntity.getTags())) {
TagDefinition nextDef = next.getTag();
if (!allDefs.contains(nextDef)) {
theEntity.getTags().remove(next);
}
}
if (theEntity.getTags().size() == 0) {
theEntity.setHasTags(false);
}


String title = ResourceMetadataKeyEnum.TITLE.get(theResource);
if (title != null && title.length() > BaseHasResource.MAX_TITLE_LENGTH) {
Expand Down Expand Up @@ -1065,18 +1091,31 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable
entity.setVersion(entity.getVersion() + 1);
}

boolean paramsStringPopulated = entity.isParamsStringPopulated();
boolean paramsTokenPopulated = entity.isParamsTokenPopulated();
boolean paramsNumberPopulated = entity.isParamsNumberPopulated();
boolean paramsQuantityPopulated = entity.isParamsQuantityPopulated();
boolean paramsDatePopulated = entity.isParamsDatePopulated();
boolean paramsCoordsPopulated = entity.isParamsCoordsPopulated();
boolean paramsUriPopulated = entity.isParamsUriPopulated();
boolean hasLinks = entity.isHasLinks();

Collection<ResourceIndexedSearchParamString> paramsString = new ArrayList<ResourceIndexedSearchParamString>(entity.getParamsString());
Collection<ResourceIndexedSearchParamToken> paramsToken = new ArrayList<ResourceIndexedSearchParamToken>(entity.getParamsToken());
Collection<ResourceIndexedSearchParamNumber> paramsNumber = new ArrayList<ResourceIndexedSearchParamNumber>(entity.getParamsNumber());
Collection<ResourceIndexedSearchParamQuantity> paramsQuantity = new ArrayList<ResourceIndexedSearchParamQuantity>(entity.getParamsQuantity());
Collection<ResourceIndexedSearchParamDate> paramsDate = new ArrayList<ResourceIndexedSearchParamDate>(entity.getParamsDate());
Collection<ResourceIndexedSearchParamUri> paramsUri = new ArrayList<ResourceIndexedSearchParamUri>(entity.getParamsUri());
Collection<ResourceIndexedSearchParamCoords> paramsCoords = new ArrayList<ResourceIndexedSearchParamCoords>(entity.getParamsCoords());
Collection<ResourceLink> resourceLinks = new ArrayList<ResourceLink>(entity.getResourceLinks());

List<ResourceIndexedSearchParamString> stringParams = null;
List<ResourceIndexedSearchParamToken> tokenParams = null;
List<ResourceIndexedSearchParamNumber> numberParams = null;
List<ResourceIndexedSearchParamQuantity> quantityParams = null;
List<ResourceIndexedSearchParamDate> dateParams = null;
List<ResourceIndexedSearchParamUri> uriParams = null;
List<ResourceIndexedSearchParamCoords> coordsParams = null;
List<ResourceLink> links = null;

if (theDeletedTimestampOrNull != null) {
Expand All @@ -1086,6 +1125,8 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable
numberParams = Collections.emptyList();
quantityParams = Collections.emptyList();
dateParams = Collections.emptyList();
uriParams = Collections.emptyList();
coordsParams = Collections.emptyList();
links = Collections.emptyList();
entity.setDeleted(theDeletedTimestampOrNull);
entity.setUpdated(theDeletedTimestampOrNull);
Expand All @@ -1100,6 +1141,8 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable
numberParams = extractSearchParamNumber(entity, theResource);
quantityParams = extractSearchParamQuantity(entity, theResource);
dateParams = extractSearchParamDates(entity, theResource);
uriParams = extractSearchParamUri(entity, theResource);
coordsParams = extractSearchParamCoords(entity, theResource);

// ourLog.info("Indexing resource: {}", entity.getId());
ourLog.trace("Storing string indexes: {}", stringParams);
Expand All @@ -1115,6 +1158,7 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable

links = extractResourceLinks(entity, theResource);
populateResourceIntoEntity(theResource, entity);

entity.setUpdated(new Date());
entity.setLanguage(theResource.getLanguage().getValue());
entity.setParamsString(stringParams);
Expand All @@ -1127,6 +1171,10 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable
entity.setParamsQuantityPopulated(quantityParams.isEmpty() == false);
entity.setParamsDate(dateParams);
entity.setParamsDatePopulated(dateParams.isEmpty() == false);
entity.setParamsUri(uriParams);
entity.setParamsUriPopulated(uriParams.isEmpty() == false);
entity.setParamsCoords(coordsParams);
entity.setParamsCoordsPopulated(coordsParams.isEmpty() == false);
entity.setResourceLinks(links);
entity.setHasLinks(links.isEmpty() == false);
entity.setIndexStatus(INDEX_STATUS_INDEXED);
Expand Down Expand Up @@ -1155,7 +1203,7 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable

if (thePerformIndexing) {

if (entity.isParamsStringPopulated()) {
if (paramsStringPopulated) {
for (ResourceIndexedSearchParamString next : paramsString) {
myEntityManager.remove(next);
}
Expand All @@ -1164,7 +1212,7 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable
myEntityManager.persist(next);
}

if (entity.isParamsTokenPopulated()) {
if (paramsTokenPopulated) {
for (ResourceIndexedSearchParamToken next : paramsToken) {
myEntityManager.remove(next);
}
Expand All @@ -1173,7 +1221,7 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable
myEntityManager.persist(next);
}

if (entity.isParamsNumberPopulated()) {
if (paramsNumberPopulated) {
for (ResourceIndexedSearchParamNumber next : paramsNumber) {
myEntityManager.remove(next);
}
Expand All @@ -1182,7 +1230,7 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable
myEntityManager.persist(next);
}

if (entity.isParamsQuantityPopulated()) {
if (paramsQuantityPopulated) {
for (ResourceIndexedSearchParamQuantity next : paramsQuantity) {
myEntityManager.remove(next);
}
Expand All @@ -1191,7 +1239,8 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable
myEntityManager.persist(next);
}

if (entity.isParamsDatePopulated()) {
// Store date SP's
if (paramsDatePopulated) {
for (ResourceIndexedSearchParamDate next : paramsDate) {
myEntityManager.remove(next);
}
Expand All @@ -1200,7 +1249,27 @@ protected ResourceTable updateEntity(final IResource theResource, ResourceTable
myEntityManager.persist(next);
}

if (entity.isHasLinks()) {
// Store URI SP's
if (paramsUriPopulated) {
for (ResourceIndexedSearchParamUri next : paramsUri) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamUri next : uriParams) {
myEntityManager.persist(next);
}

// Store Coords SP's
if (paramsCoordsPopulated) {
for (ResourceIndexedSearchParamCoords next : paramsCoords) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamCoords next : coordsParams) {
myEntityManager.persist(next);
}

if (hasLinks) {
for (ResourceLink next : resourceLinks) {
myEntityManager.remove(next);
}
Expand Down

0 comments on commit 97e6073

Please sign in to comment.