Obtain current CodeSystem from null-pointed ForcedId, as done for ValueSet
This commit is contained in:
parent
5b6ac3e6d6
commit
8288d12e97
|
@ -34,7 +34,6 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.param.StringParam;
|
import ca.uhn.fhir.rest.param.StringParam;
|
||||||
import ca.uhn.fhir.rest.param.TokenParam;
|
import ca.uhn.fhir.rest.param.TokenParam;
|
||||||
import ca.uhn.fhir.rest.param.UriParam;
|
import ca.uhn.fhir.rest.param.UriParam;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||||
import com.github.benmanes.caffeine.cache.Cache;
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
|
@ -74,7 +73,8 @@ public class JpaPersistedResourceValidationSupport implements IValidationSupport
|
||||||
|
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(JpaPersistedResourceValidationSupport.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(JpaPersistedResourceValidationSupport.class);
|
||||||
|
|
||||||
public static final String LOINC_GENERIC_VALUESET_URL = "http://loinc.org/vs";
|
public static final String LOINC_GENERIC_CODE_SYSTEM_URL = "http://loinc.org";
|
||||||
|
public static final String LOINC_GENERIC_VALUESET_URL = LOINC_GENERIC_CODE_SYSTEM_URL + "/vs";
|
||||||
public static final String LOINC_GENERIC_VALUESET_URL_PLUS_SLASH = LOINC_GENERIC_VALUESET_URL + "/";
|
public static final String LOINC_GENERIC_VALUESET_URL_PLUS_SLASH = LOINC_GENERIC_VALUESET_URL + "/";
|
||||||
|
|
||||||
private final FhirContext myFhirContext;
|
private final FhirContext myFhirContext;
|
||||||
|
@ -107,9 +107,29 @@ public class JpaPersistedResourceValidationSupport implements IValidationSupport
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBaseResource fetchCodeSystem(String theSystem) {
|
public IBaseResource fetchCodeSystem(String theSystem) {
|
||||||
|
if (myTermReadSvc.isLoincNotGenericUnversionedCodeSystem(theSystem)) {
|
||||||
|
Optional<IBaseResource> currentCSOpt = getCodeSystemCurrentVersion(new UriType(theSystem));
|
||||||
|
return currentCSOpt.orElseThrow(() -> new ResourceNotFoundException(
|
||||||
|
"Couldn't find current version CodeSystem for url: " + theSystem));
|
||||||
|
}
|
||||||
|
|
||||||
return fetchResource(myCodeSystemType, theSystem);
|
return fetchResource(myCodeSystemType, theSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the current version of a CodeSystem using the fact that the current
|
||||||
|
* version is always pointed by the ForcedId for the no-versioned CS
|
||||||
|
*/
|
||||||
|
private Optional<IBaseResource> getCodeSystemCurrentVersion(UriType theUrl) {
|
||||||
|
if (! theUrl.getValueAsString().contains("loinc")) return Optional.empty();
|
||||||
|
|
||||||
|
IFhirResourceDao<? extends IBaseResource> valueSetResourceDao = myDaoRegistry.getResourceDao(myCodeSystemType);
|
||||||
|
String forcedId = "loinc";
|
||||||
|
IBaseResource codeSystem = valueSetResourceDao.read(new IdDt("CodeSystem", forcedId));
|
||||||
|
return Optional.ofNullable(codeSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBaseResource fetchValueSet(String theSystem) {
|
public IBaseResource fetchValueSet(String theSystem) {
|
||||||
if (myTermReadSvc.isLoincNotGenericUnversionedValueSet(theSystem)) {
|
if (myTermReadSvc.isLoincNotGenericUnversionedValueSet(theSystem)) {
|
||||||
|
@ -126,17 +146,11 @@ public class JpaPersistedResourceValidationSupport implements IValidationSupport
|
||||||
* version is always pointed by the ForcedId for the no-versioned VS
|
* version is always pointed by the ForcedId for the no-versioned VS
|
||||||
*/
|
*/
|
||||||
private Optional<IBaseResource> getValueSetCurrentVersion(UriType theUrl) {
|
private Optional<IBaseResource> getValueSetCurrentVersion(UriType theUrl) {
|
||||||
if (! theUrl.getValueAsString().startsWith(LOINC_GENERIC_VALUESET_URL)) return Optional.empty();
|
if (myTermReadSvc.mustReturnEmptyValueSet(theUrl.getValueAsString())) return Optional.empty();
|
||||||
|
|
||||||
if (! theUrl.getValue().startsWith(LOINC_GENERIC_VALUESET_URL_PLUS_SLASH)) {
|
|
||||||
throw new InternalErrorException("Don't know how to extract ForcedId from url: " + theUrl.getValueAsString());
|
|
||||||
}
|
|
||||||
|
|
||||||
String forcedId = theUrl.getValue().substring(LOINC_GENERIC_VALUESET_URL_PLUS_SLASH.length());
|
String forcedId = theUrl.getValue().substring(LOINC_GENERIC_VALUESET_URL_PLUS_SLASH.length());
|
||||||
if (StringUtils.isBlank(forcedId)) return Optional.empty();
|
if (StringUtils.isBlank(forcedId)) return Optional.empty();
|
||||||
|
|
||||||
if (myTermReadSvc.mustReturnEmptyValueSet(theUrl.getValueAsString())) return Optional.empty();
|
|
||||||
|
|
||||||
IFhirResourceDao<? extends IBaseResource> valueSetResourceDao = myDaoRegistry.getResourceDao(myValueSetType);
|
IFhirResourceDao<? extends IBaseResource> valueSetResourceDao = myDaoRegistry.getResourceDao(myValueSetType);
|
||||||
IBaseResource valueSet = valueSetResourceDao.read(new IdDt("ValueSet", forcedId));
|
IBaseResource valueSet = valueSetResourceDao.read(new IdDt("ValueSet", forcedId));
|
||||||
return Optional.ofNullable(valueSet);
|
return Optional.ofNullable(valueSet);
|
||||||
|
|
|
@ -2382,6 +2382,15 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLoincNotGenericUnversionedCodeSystem(String theUrl) {
|
||||||
|
boolean isLoincCodeSystem = StringUtils.containsIgnoreCase(theUrl, "loinc");
|
||||||
|
boolean isNoVersion = ! theUrl.contains("|");
|
||||||
|
|
||||||
|
return isLoincCodeSystem && isNoVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private CodeValidationResult codeSystemValidateCode(String theCodeSystemUrl, String theCodeSystemVersion, String theCode, String theDisplay) {
|
private CodeValidationResult codeSystemValidateCode(String theCodeSystemUrl, String theCodeSystemVersion, String theCode, String theDisplay) {
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,19 @@ public interface ITermReadSvc extends IValidationSupport {
|
||||||
*/
|
*/
|
||||||
Optional<TermValueSet> findCurrentTermValueSet(String theUrl);
|
Optional<TermValueSet> findCurrentTermValueSet(String theUrl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version independent
|
||||||
|
*/
|
||||||
boolean mustReturnEmptyValueSet(String theUrl);
|
boolean mustReturnEmptyValueSet(String theUrl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version independent
|
||||||
|
*/
|
||||||
|
boolean isLoincNotGenericUnversionedCodeSystem(String theSystem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version independent
|
||||||
|
*/
|
||||||
boolean isLoincNotGenericUnversionedValueSet(String theUrl);
|
boolean isLoincNotGenericUnversionedValueSet(String theUrl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue