Add searching by code text
This commit is contained in:
parent
0484c6509f
commit
d3b4a3ad60
|
@ -32,6 +32,10 @@ public abstract class BaseIdentifiableElement extends BaseElement implements IId
|
||||||
return myElementSpecificId;
|
return myElementSpecificId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #getElementSpecificId()} instead. This method will be removed because it is easily
|
||||||
|
* confused with other ID methods (such as patient#getIdentifier)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IdDt getId() {
|
public IdDt getId() {
|
||||||
if (myElementSpecificId == null) {
|
if (myElementSpecificId == null) {
|
||||||
|
@ -46,6 +50,10 @@ public abstract class BaseIdentifiableElement extends BaseElement implements IId
|
||||||
myElementSpecificId = theElementSpecificId;
|
myElementSpecificId = theElementSpecificId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #setElementSpecificId(String)} instead. This method will be removed because it is easily
|
||||||
|
* confused with other ID methods (such as patient#getIdentifier)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setId(IdDt theId) {
|
public void setId(IdDt theId) {
|
||||||
if (theId == null) {
|
if (theId == null) {
|
||||||
|
@ -55,6 +63,10 @@ public abstract class BaseIdentifiableElement extends BaseElement implements IId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #setElementSpecificId(String)} instead. This method will be removed because it is easily
|
||||||
|
* confused with other ID methods (such as patient#getIdentifier)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setId(String theId) {
|
public void setId(String theId) {
|
||||||
myElementSpecificId = theId;
|
myElementSpecificId = theId;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.ConfigurationException;
|
import ca.uhn.fhir.context.ConfigurationException;
|
||||||
|
@ -423,7 +424,8 @@ public abstract class BaseFhirDao {
|
||||||
|
|
||||||
if (nextObject instanceof QuantityDt) {
|
if (nextObject instanceof QuantityDt) {
|
||||||
QuantityDt nextValue = (QuantityDt) nextObject;
|
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);
|
nextEntity.setResource(theEntity);
|
||||||
retVal.add(nextEntity);
|
retVal.add(nextEntity);
|
||||||
} else {
|
} else {
|
||||||
|
@ -472,7 +474,7 @@ public abstract class BaseFhirDao {
|
||||||
IPrimitiveDatatype<?> nextValue = (IPrimitiveDatatype<?>) nextObject;
|
IPrimitiveDatatype<?> nextValue = (IPrimitiveDatatype<?>) nextObject;
|
||||||
String searchTerm = nextValue.getValueAsString();
|
String searchTerm = nextValue.getValueAsString();
|
||||||
if (searchTerm.length() > ResourceIndexedSearchParamString.MAX_LENGTH) {
|
if (searchTerm.length() > ResourceIndexedSearchParamString.MAX_LENGTH) {
|
||||||
searchTerm=searchTerm.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH);
|
searchTerm = searchTerm.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceIndexedSearchParamString nextEntity = new ResourceIndexedSearchParamString(resourceName, normalizeString(searchTerm), searchTerm);
|
ResourceIndexedSearchParamString nextEntity = new ResourceIndexedSearchParamString(resourceName, normalizeString(searchTerm), searchTerm);
|
||||||
|
@ -511,7 +513,8 @@ public abstract class BaseFhirDao {
|
||||||
} else if (nextObject instanceof ContactDt) {
|
} else if (nextObject instanceof ContactDt) {
|
||||||
ContactDt nextContact = (ContactDt) nextObject;
|
ContactDt nextContact = (ContactDt) nextObject;
|
||||||
if (nextContact.getValue().isEmpty() == false) {
|
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);
|
nextEntity.setResource(theEntity);
|
||||||
retVal.add(nextEntity);
|
retVal.add(nextEntity);
|
||||||
}
|
}
|
||||||
|
@ -558,23 +561,39 @@ public abstract class BaseFhirDao {
|
||||||
if (nextValue.isEmpty()) {
|
if (nextValue.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
systems.add( nextValue.getSystem().getValueAsString());
|
systems.add(nextValue.getSystem().getValueAsString());
|
||||||
codes.add( nextValue.getValue().getValue());
|
codes.add(nextValue.getValue().getValue());
|
||||||
} else if (nextObject instanceof IPrimitiveDatatype<?>) {
|
} else if (nextObject instanceof IPrimitiveDatatype<?>) {
|
||||||
IPrimitiveDatatype<?> nextValue = (IPrimitiveDatatype<?>) nextObject;
|
IPrimitiveDatatype<?> nextValue = (IPrimitiveDatatype<?>) nextObject;
|
||||||
if (nextValue.isEmpty()) {
|
if (nextValue.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
systems.add(null);
|
systems.add(null);
|
||||||
codes .add (nextValue.getValueAsString());
|
codes.add(nextValue.getValueAsString());
|
||||||
} else if (nextObject instanceof CodeableConceptDt) {
|
} else if (nextObject instanceof CodeableConceptDt) {
|
||||||
CodeableConceptDt nextCC = (CodeableConceptDt) nextObject;
|
CodeableConceptDt nextCC = (CodeableConceptDt) nextObject;
|
||||||
|
if (!nextCC.getText().isEmpty()) {
|
||||||
|
systems.add(null);
|
||||||
|
codes.add(nextCC.getText().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
for (CodingDt nextCoding : nextCC.getCoding()) {
|
for (CodingDt nextCoding : nextCC.getCoding()) {
|
||||||
if (nextCoding.isEmpty()) {
|
if (nextCoding.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
systems.add(nextCoding.getSystem().getValueAsString());
|
|
||||||
codes.add( nextCoding.getCode().getValue());
|
String nextSystem = nextCoding.getSystem().getValueAsString();
|
||||||
|
String nextCode = nextCoding.getCode().getValue();
|
||||||
|
if (isNotBlank(nextSystem) || isNotBlank(nextCode)) {
|
||||||
|
systems.add(nextSystem);
|
||||||
|
codes.add(nextCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nextCoding.getDisplay().isEmpty()) {
|
||||||
|
systems.add(null);
|
||||||
|
codes.add(nextCoding.getDisplay().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!multiType) {
|
if (!multiType) {
|
||||||
|
@ -585,10 +604,15 @@ public abstract class BaseFhirDao {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert systems.size() == codes.size();
|
assert systems.size() == codes.size() : "Systems contains " + systems + ", codes contains: " + codes;
|
||||||
|
|
||||||
|
Set<Pair<String, String>> haveValues = new HashSet<Pair<String,String>>();
|
||||||
for (int i = 0; i < systems.size(); i++) {
|
for (int i = 0; i < systems.size(); i++) {
|
||||||
String system = systems.get(i);
|
String system = systems.get(i);
|
||||||
String code = codes.get(i);
|
String code = codes.get(i);
|
||||||
|
if (isBlank(system) && isBlank(code)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (system != null && system.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) {
|
if (system != null && system.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) {
|
||||||
system = system.substring(0, ResourceIndexedSearchParamToken.MAX_LENGTH);
|
system = system.substring(0, ResourceIndexedSearchParamToken.MAX_LENGTH);
|
||||||
|
@ -597,6 +621,12 @@ public abstract class BaseFhirDao {
|
||||||
code = code.substring(0, ResourceIndexedSearchParamToken.MAX_LENGTH);
|
code = code.substring(0, ResourceIndexedSearchParamToken.MAX_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Pair<String, String> nextPair = Pair.of(system,code);
|
||||||
|
if (haveValues.contains(nextPair)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
haveValues.add(nextPair);
|
||||||
|
|
||||||
ResourceIndexedSearchParamToken nextEntity;
|
ResourceIndexedSearchParamToken nextEntity;
|
||||||
nextEntity = new ResourceIndexedSearchParamToken(nextSpDef.getName(), system, code);
|
nextEntity = new ResourceIndexedSearchParamToken(nextSpDef.getName(), system, code);
|
||||||
nextEntity.setResource(theEntity);
|
nextEntity.setResource(theEntity);
|
||||||
|
@ -740,7 +770,7 @@ public abstract class BaseFhirDao {
|
||||||
|
|
||||||
List<ResourceReferenceDt> refs = myContext.newTerser().getAllPopulatedChildElementsOfType(theResource, ResourceReferenceDt.class);
|
List<ResourceReferenceDt> refs = myContext.newTerser().getAllPopulatedChildElementsOfType(theResource, ResourceReferenceDt.class);
|
||||||
for (ResourceReferenceDt nextRef : refs) {
|
for (ResourceReferenceDt nextRef : refs) {
|
||||||
if (nextRef.getReference().isEmpty()==false) {
|
if (nextRef.getReference().isEmpty() == false) {
|
||||||
if (nextRef.getReference().hasVersionIdPart()) {
|
if (nextRef.getReference().hasVersionIdPart()) {
|
||||||
nextRef.setReference(nextRef.getReference().toUnqualifiedVersionless());
|
nextRef.setReference(nextRef.getReference().toUnqualifiedVersionless());
|
||||||
}
|
}
|
||||||
|
@ -772,7 +802,7 @@ public abstract class BaseFhirDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
String title = ResourceMetadataKeyEnum.TITLE.get(theResource);
|
String title = ResourceMetadataKeyEnum.TITLE.get(theResource);
|
||||||
if (title != null && title.length()>BaseHasResource.MAX_TITLE_LENGTH) {
|
if (title != null && title.length() > BaseHasResource.MAX_TITLE_LENGTH) {
|
||||||
title = title.substring(0, BaseHasResource.MAX_TITLE_LENGTH);
|
title = title.substring(0, BaseHasResource.MAX_TITLE_LENGTH);
|
||||||
}
|
}
|
||||||
theEntity.setTitle(title);
|
theEntity.setTitle(title);
|
||||||
|
@ -814,11 +844,11 @@ public abstract class BaseFhirDao {
|
||||||
retVal.getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, theEntity.getPublished());
|
retVal.getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, theEntity.getPublished());
|
||||||
retVal.getResourceMetadata().put(ResourceMetadataKeyEnum.UPDATED, theEntity.getUpdated());
|
retVal.getResourceMetadata().put(ResourceMetadataKeyEnum.UPDATED, theEntity.getUpdated());
|
||||||
|
|
||||||
if (theEntity.getTitle()!=null) {
|
if (theEntity.getTitle() != null) {
|
||||||
ResourceMetadataKeyEnum.TITLE.put(retVal, theEntity.getTitle());
|
ResourceMetadataKeyEnum.TITLE.put(retVal, theEntity.getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theEntity.getDeleted()!=null) {
|
if (theEntity.getDeleted() != null) {
|
||||||
ResourceMetadataKeyEnum.DELETED_AT.put(retVal, new InstantDt(theEntity.getDeleted()));
|
ResourceMetadataKeyEnum.DELETED_AT.put(retVal, new InstantDt(theEntity.getDeleted()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -950,7 +980,7 @@ public abstract class BaseFhirDao {
|
||||||
|
|
||||||
myEntityManager.flush();
|
myEntityManager.flush();
|
||||||
|
|
||||||
if (theResource!=null) {
|
if (theResource != null) {
|
||||||
theResource.setId(new IdDt(entity.getResourceType(), entity.getId().toString(), Long.toString(entity.getVersion())));
|
theResource.setId(new IdDt(entity.getResourceType(), entity.getId().toString(), Long.toString(entity.getVersion())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue