Skip to content

Commit

Permalink
Correctly save deferred concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Apr 6, 2018
1 parent 3eab3c5 commit 0f269a1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
Expand Up @@ -528,14 +528,6 @@ private void persistChildren(TermConcept theConcept, TermCodeSystemVersion theCo
}
}

for (TermConceptProperty next : theConcept.getProperties()) {
myConceptPropertyDao.save(next);
}

for (TermConceptDesignation next : theConcept.getDesignations()) {
myConceptDesignationDao.save(next);
}

}

private void populateVersion(TermConcept theNext, TermCodeSystemVersion theCodeSystemVersion) {
Expand Down Expand Up @@ -681,6 +673,14 @@ private int saveConcept(TermConcept theConcept) {
retVal++;
theConcept.setIndexStatus(BaseHapiFhirDao.INDEX_STATUS_INDEXED);
myConceptDao.save(theConcept);

for (TermConceptProperty next : theConcept.getProperties()) {
myConceptPropertyDao.save(next);
}

for (TermConceptDesignation next : theConcept.getDesignations()) {
myConceptDesignationDao.save(next);
}
}

ourLog.trace("Saved {} and got PID {}", theConcept.getCode(), theConcept.getId());
Expand Down
@@ -1,5 +1,6 @@
package ca.uhn.fhir.jpa.term;

import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemDao;
import ca.uhn.fhir.jpa.dao.dstu3.BaseJpaDstu3Test;
import ca.uhn.fhir.jpa.entity.ResourceTable;
Expand All @@ -13,6 +14,7 @@
import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.ValueSet;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -42,6 +44,14 @@ private IIdType createCodeSystem() {
TermCodeSystemVersion cs = new TermCodeSystemVersion();
cs.setResource(table);

TermConcept parent;
parent = new TermConcept(cs, "ParentWithNoChildrenA");
cs.getConcepts().add(parent);
parent = new TermConcept(cs, "ParentWithNoChildrenB");
cs.getConcepts().add(parent);
parent = new TermConcept(cs, "ParentWithNoChildrenC");
cs.getConcepts().add(parent);

TermConcept parentA = new TermConcept(cs, "ParentA");
cs.getConcepts().add(parentA);

Expand Down Expand Up @@ -223,6 +233,47 @@ public void testPropertiesAndDesignationsPreservedInExpansion() {
assertEquals("D1V", concept.getDesignation().get(0).getValue());
}

@After
public void after() {
myDaoConfig.setDeferIndexingForCodesystemsOfSize(new DaoConfig().getDeferIndexingForCodesystemsOfSize());
BaseHapiTerminologySvcImpl.setForceSaveDeferredAlwaysForUnitTest(false);
}


@Test
public void testCreatePropertiesAndDesignationsWithDeferredConcepts() {
myDaoConfig.setDeferIndexingForCodesystemsOfSize(1);
BaseHapiTerminologySvcImpl.setForceSaveDeferredAlwaysForUnitTest(true);

createCodeSystem();

myTermSvc.saveDeferred();
myTermSvc.saveDeferred();
myTermSvc.saveDeferred();
myTermSvc.saveDeferred();
myTermSvc.saveDeferred();
myTermSvc.saveDeferred();

ValueSet vs = new ValueSet();
ValueSet.ConceptSetComponent include = vs.getCompose().addInclude();
include.setSystem(CS_URL);
include.addConcept().setCode("childAAB");
ValueSet outcome = myTermSvc.expandValueSet(vs);

List<String> codes = toCodesContains(outcome.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("childAAB"));

ValueSet.ValueSetExpansionContainsComponent concept = outcome.getExpansion().getContains().get(0);
assertEquals("childAAB", concept.getCode());
assertEquals("http://example.com/my_code_system", concept.getSystem());
assertEquals(null, concept.getDisplay());
assertEquals("D1S", concept.getDesignation().get(0).getUse().getSystem());
assertEquals("D1C", concept.getDesignation().get(0).getUse().getCode());
assertEquals("D1D", concept.getDesignation().get(0).getUse().getDisplay());
assertEquals("D1V", concept.getDesignation().get(0).getValue());
}


@Test
public void testFindCodesAbove() {
IIdType id = createCodeSystem();
Expand Down

0 comments on commit 0f269a1

Please sign in to comment.