Work on terminology expansion

This commit is contained in:
James Agnew 2018-09-01 22:56:42 +08:00
parent a4d8df3c6d
commit bc270584d2
1 changed files with 32 additions and 7 deletions

View File

@ -139,12 +139,13 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
* @param theAdd If true, add the code. If false, remove the code.
* @param theCodeCounter
*/
private void addCodeIfNotAlreadyAdded(String theCodeSystem, ValueSet.ValueSetExpansionComponent theExpansionComponent, Set<String> theAddedCodes, TermConcept theConcept, boolean theAdd, AtomicInteger theCodeCounter) {
private void addCodeIfNotAlreadyAdded(ValueSet.ValueSetExpansionComponent theExpansionComponent, Set<String> theAddedCodes, TermConcept theConcept, boolean theAdd, AtomicInteger theCodeCounter) {
String code = theConcept.getCode();
if (theAdd && theAddedCodes.add(code)) {
String codeSystem = theConcept.getCodeSystemVersion().getCodeSystem().getCodeSystemUri();
ValueSet.ValueSetExpansionContainsComponent contains = theExpansionComponent.addContains();
contains.setCode(code);
contains.setSystem(theCodeSystem);
contains.setSystem(codeSystem);
contains.setDisplay(theConcept.getDisplay());
for (TermConceptDesignation nextDesignation : theConcept.getDesignations()) {
contains
@ -160,7 +161,8 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
}
if (!theAdd && theAddedCodes.remove(code)) {
removeCodeFromExpansion(theCodeSystem, code, theExpansionComponent);
String codeSystem = theConcept.getCodeSystemVersion().getCodeSystem().getCodeSystemUri();
removeCodeFromExpansion(codeSystem, code, theExpansionComponent);
theCodeCounter.decrementAndGet();
}
}
@ -458,8 +460,11 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
public void expandValueSetHandleIncludeOrExclude(ValueSet.ValueSetExpansionComponent theExpansionComponent, Set<String> theAddedCodes, ValueSet.ConceptSetComponent theInclude, boolean theAdd, AtomicInteger theCodeCounter) {
String system = theInclude.getSystem();
ourLog.info("Starting {} expansion around code system: {}", (theAdd ? "inclusion" : "exclusion"), system);
if (isNotBlank(system)) {
boolean hasSystem = isNotBlank(system);
boolean hasValueSet = theInclude.getValueSet().size() > 0;
if (hasSystem) {
ourLog.info("Starting {} expansion around code system: {}", (theAdd ? "inclusion" : "exclusion"), system);
TermCodeSystem cs = myCodeSystemDao.findByCodeSystemUri(system);
if (cs != null) {
@ -584,7 +589,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
for (Object next : jpaQuery.getResultList()) {
count.incrementAndGet();
TermConcept concept = (TermConcept) next;
addCodeIfNotAlreadyAdded(system, theExpansionComponent, theAddedCodes, concept, theAdd, theCodeCounter);
addCodeIfNotAlreadyAdded(theExpansionComponent, theAddedCodes, concept, theAdd, theCodeCounter);
}
@ -625,6 +630,23 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
addConceptsToList(theExpansionComponent, theAddedCodes, system, concept, theAdd);
}
}
} else if (hasValueSet) {
for (CanonicalType nextValueSet : theInclude.getValueSet()) {
ourLog.info("Starting {} expansion around ValueSet URI: {}", (theAdd ? "inclusion" : "exclusion"), nextValueSet.getValueAsString());
List<VersionIndependentConcept> expanded = expandValueSet(nextValueSet.getValueAsString());
for (VersionIndependentConcept nextConcept : expanded) {
if (theAdd) {
TermCodeSystem codeSystem = myCodeSystemDao.findByCodeSystemUri(nextConcept.getSystem());
TermConcept concept = myConceptDao.findByCodeSystemAndCode(codeSystem.getCurrentVersion(), nextConcept.getCode());
addCodeIfNotAlreadyAdded(theExpansionComponent, theAddedCodes, concept, theAdd, theCodeCounter);
}
if (!theAdd && theAddedCodes.remove(nextConcept.getCode())) {
removeCodeFromExpansion(nextConcept.getSystem(), nextConcept.getCode(), theExpansionComponent);
}
}
}
} else {
throw new InvalidRequestException("ValueSet contains " + (theAdd ? "include" : "exclude") + " criteria with no system defined");
@ -659,7 +681,10 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
if (theCode.equals(next.getCode())) {
return next;
}
findCode(next.getConcept(), theCode);
CodeSystem.ConceptDefinitionComponent val = findCode(next.getConcept(), theCode);
if (val != null) {
return val;
}
}
return null;
}