Merge pull request #1460 from jamesagnew/dm-fix-resourcetable-lookups-for-preexpansion-and-code-validation
Fix ResourceTable lookups for pre-expansion and code validation.
This commit is contained in:
commit
6b826560c4
|
@ -55,6 +55,7 @@ import org.hibernate.search.query.dsl.BooleanJunction;
|
||||||
import org.hibernate.search.query.dsl.QueryBuilder;
|
import org.hibernate.search.query.dsl.QueryBuilder;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseCoding;
|
import org.hl7.fhir.instance.model.api.IBaseCoding;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||||
import org.hl7.fhir.r4.model.*;
|
import org.hl7.fhir.r4.model.*;
|
||||||
|
@ -487,7 +488,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
|
||||||
|
|
||||||
Optional<TermValueSet> optionalTermValueSet;
|
Optional<TermValueSet> optionalTermValueSet;
|
||||||
if (theValueSetToExpand.hasId()) {
|
if (theValueSetToExpand.hasId()) {
|
||||||
Long valueSetResourcePid = IDao.RESOURCE_PID.get(theValueSetToExpand);
|
Long valueSetResourcePid = getValueSetResourcePid(theValueSetToExpand.getIdElement());
|
||||||
optionalTermValueSet = myValueSetDao.findByResourcePid(valueSetResourcePid);
|
optionalTermValueSet = myValueSetDao.findByResourcePid(valueSetResourcePid);
|
||||||
} else if (theValueSetToExpand.hasUrl()) {
|
} else if (theValueSetToExpand.hasUrl()) {
|
||||||
optionalTermValueSet = myValueSetDao.findByUrl(theValueSetToExpand.getUrl());
|
optionalTermValueSet = myValueSetDao.findByUrl(theValueSetToExpand.getUrl());
|
||||||
|
@ -956,7 +957,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValueSetPreExpandedForCodeValidation(ValueSet theValueSet) {
|
public boolean isValueSetPreExpandedForCodeValidation(ValueSet theValueSet) {
|
||||||
Long valueSetResourcePid = IDao.RESOURCE_PID.get(theValueSet);
|
Long valueSetResourcePid = getValueSetResourcePid(theValueSet.getIdElement());
|
||||||
Optional<TermValueSet> optionalTermValueSet = myValueSetDao.findByResourcePid(valueSetResourcePid);
|
Optional<TermValueSet> optionalTermValueSet = myValueSetDao.findByResourcePid(valueSetResourcePid);
|
||||||
|
|
||||||
if (!optionalTermValueSet.isPresent()) {
|
if (!optionalTermValueSet.isPresent()) {
|
||||||
|
@ -980,7 +981,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
|
||||||
ValueSet theValueSet, String theSystem, String theCode, String theDisplay, Coding theCoding, CodeableConcept theCodeableConcept) {
|
ValueSet theValueSet, String theSystem, String theCode, String theDisplay, Coding theCoding, CodeableConcept theCodeableConcept) {
|
||||||
|
|
||||||
ValidateUtil.isNotNullOrThrowUnprocessableEntity(theValueSet.hasId(), "ValueSet.id is required");
|
ValidateUtil.isNotNullOrThrowUnprocessableEntity(theValueSet.hasId(), "ValueSet.id is required");
|
||||||
Long valueSetResourcePid = IDao.RESOURCE_PID.get(theValueSet);
|
Long valueSetResourcePid = getValueSetResourcePid(theValueSet.getIdElement());
|
||||||
|
|
||||||
List<TermValueSetConcept> concepts = new ArrayList<>();
|
List<TermValueSetConcept> concepts = new ArrayList<>();
|
||||||
if (isNotBlank(theCode)) {
|
if (isNotBlank(theCode)) {
|
||||||
|
@ -1158,6 +1159,27 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
|
||||||
|
|
||||||
protected abstract CodeSystem getCodeSystemFromContext(String theSystem);
|
protected abstract CodeSystem getCodeSystemFromContext(String theSystem);
|
||||||
|
|
||||||
|
private Long getCodeSystemResourcePid(IIdType theIdType) {
|
||||||
|
return getCodeSystemResourcePid(theIdType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long getCodeSystemResourcePid(IIdType theIdType, RequestDetails theRequestDetails) {
|
||||||
|
return getResourcePid(myCodeSystemResourceDao, theIdType, theRequestDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long getValueSetResourcePid(IIdType theIdType) {
|
||||||
|
return getValueSetResourcePid(theIdType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long getValueSetResourcePid(IIdType theIdType, RequestDetails theRequestDetails) {
|
||||||
|
return getResourcePid(myValueSetResourceDao, theIdType, theRequestDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long getResourcePid(IFhirResourceDao<? extends IBaseResource> theResourceDao, IIdType theIdType, RequestDetails theRequestDetails) {
|
||||||
|
ResourceTable resourceTable = (ResourceTable) theResourceDao.readEntity(theIdType, theRequestDetails);
|
||||||
|
return resourceTable.getId();
|
||||||
|
}
|
||||||
|
|
||||||
private void persistChildren(TermConcept theConcept, TermCodeSystemVersion theCodeSystem, IdentityHashMap<TermConcept, Object> theConceptsStack, int theTotalConcepts) {
|
private void persistChildren(TermConcept theConcept, TermCodeSystemVersion theCodeSystem, IdentityHashMap<TermConcept, Object> theConceptsStack, int theTotalConcepts) {
|
||||||
if (theConceptsStack.put(theConcept, PLACEHOLDER_OBJECT) != null) {
|
if (theConceptsStack.put(theConcept, PLACEHOLDER_OBJECT) != null) {
|
||||||
return;
|
return;
|
||||||
|
@ -1625,7 +1647,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
|
||||||
if (theCodeSystem.getContent() == CodeSystem.CodeSystemContentMode.COMPLETE || theCodeSystem.getContent() == null || theCodeSystem.getContent() == CodeSystem.CodeSystemContentMode.NOTPRESENT) {
|
if (theCodeSystem.getContent() == CodeSystem.CodeSystemContentMode.COMPLETE || theCodeSystem.getContent() == null || theCodeSystem.getContent() == CodeSystem.CodeSystemContentMode.NOTPRESENT) {
|
||||||
ourLog.info("CodeSystem {} has a status of {}, going to store concepts in terminology tables", theResourceEntity.getIdDt().getValue(), theCodeSystem.getContentElement().getValueAsString());
|
ourLog.info("CodeSystem {} has a status of {}, going to store concepts in terminology tables", theResourceEntity.getIdDt().getValue(), theCodeSystem.getContentElement().getValueAsString());
|
||||||
|
|
||||||
Long codeSystemResourcePid = IDao.RESOURCE_PID.get(theCodeSystem);
|
Long codeSystemResourcePid = getCodeSystemResourcePid(theCodeSystem.getIdElement());
|
||||||
TermCodeSystemVersion persCs = myCodeSystemVersionDao.findCurrentVersionForCodeSystemResourcePid(codeSystemResourcePid);
|
TermCodeSystemVersion persCs = myCodeSystemVersionDao.findCurrentVersionForCodeSystemResourcePid(codeSystemResourcePid);
|
||||||
if (persCs != null) {
|
if (persCs != null) {
|
||||||
ourLog.info("Code system version already exists in database");
|
ourLog.info("Code system version already exists in database");
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package ca.uhn.fhir.jpa.term;
|
package ca.uhn.fhir.jpa.term;
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||||
import ca.uhn.fhir.jpa.dao.IDao;
|
|
||||||
import ca.uhn.fhir.jpa.dao.dstu3.BaseJpaDstu3Test;
|
import ca.uhn.fhir.jpa.dao.dstu3.BaseJpaDstu3Test;
|
||||||
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
|
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
|
||||||
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
|
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
|
||||||
|
@ -601,7 +600,9 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test {
|
||||||
new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() {
|
new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() {
|
||||||
@Override
|
@Override
|
||||||
protected void doInTransactionWithoutResult(TransactionStatus theStatus) {
|
protected void doInTransactionWithoutResult(TransactionStatus theStatus) {
|
||||||
TermCodeSystem codeSystem = myTermCodeSystemDao.findByResourcePid(IDao.RESOURCE_PID.get(codeSystemResource));
|
ResourceTable resourceTable = (ResourceTable) myCodeSystemDao.readEntity(codeSystemResource.getIdElement(), null);
|
||||||
|
Long codeSystemResourcePid = resourceTable.getId();
|
||||||
|
TermCodeSystem codeSystem = myTermCodeSystemDao.findByResourcePid(codeSystemResourcePid);
|
||||||
assertEquals(CS_URL, codeSystem.getCodeSystemUri());
|
assertEquals(CS_URL, codeSystem.getCodeSystemUri());
|
||||||
assertEquals("SYSTEM NAME", codeSystem.getName());
|
assertEquals("SYSTEM NAME", codeSystem.getName());
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ca.uhn.fhir.jpa.term;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.support.IContextValidationSupport;
|
import ca.uhn.fhir.context.support.IContextValidationSupport;
|
||||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||||
import ca.uhn.fhir.jpa.dao.IDao;
|
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult;
|
||||||
import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test;
|
import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test;
|
||||||
import ca.uhn.fhir.jpa.entity.*;
|
import ca.uhn.fhir.jpa.entity.*;
|
||||||
|
@ -1591,7 +1590,9 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test {
|
||||||
new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() {
|
new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() {
|
||||||
@Override
|
@Override
|
||||||
protected void doInTransactionWithoutResult(TransactionStatus theStatus) {
|
protected void doInTransactionWithoutResult(TransactionStatus theStatus) {
|
||||||
TermCodeSystem codeSystem = myTermCodeSystemDao.findByResourcePid(IDao.RESOURCE_PID.get(codeSystemResource));
|
ResourceTable resourceTable = (ResourceTable) myCodeSystemDao.readEntity(codeSystemResource.getIdElement(), null);
|
||||||
|
Long codeSystemResourcePid = resourceTable.getId();
|
||||||
|
TermCodeSystem codeSystem = myTermCodeSystemDao.findByResourcePid(codeSystemResourcePid);
|
||||||
assertEquals(CS_URL, codeSystem.getCodeSystemUri());
|
assertEquals(CS_URL, codeSystem.getCodeSystemUri());
|
||||||
assertEquals("SYSTEM NAME", codeSystem.getName());
|
assertEquals("SYSTEM NAME", codeSystem.getName());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue