Add searching by code text

This commit is contained in:
James Agnew 2014-07-07 18:34:49 -04:00
parent 0484c6509f
commit d3b4a3ad60
2 changed files with 70 additions and 28 deletions

View File

@ -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;

View File

@ -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 {
@ -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);
} }
@ -569,12 +572,28 @@ public abstract class BaseFhirDao {
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);