Work on issue 534

This commit is contained in:
James Agnew 2017-03-29 15:19:52 +08:00
parent 3ecfbf098f
commit d9749b652d
5 changed files with 33 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
*/
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.trim;
import java.io.UnsupportedEncodingException;
import java.text.Normalizer;
@ -311,6 +312,29 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
}
Set<String> treatReferencesAsLogical = myConfig.getTreatReferencesAsLogical();
if (treatReferencesAsLogical != null) {
boolean isLogical = false;
for (String nextLogicalRef : treatReferencesAsLogical) {
nextLogicalRef = trim(nextLogicalRef);
if (nextLogicalRef.charAt(nextLogicalRef.length() - 1) == '*') {
if (nextId.getValue().startsWith(nextLogicalRef.substring(0, nextLogicalRef.length() -1))) {
isLogical = true;
break;
}
} else {
if (nextId.getValue().equals(nextLogicalRef)) {
isLogical = true;
break;
}
}
}
if (isLogical) {
continue;
}
}
String baseUrl = nextId.getBaseUrl();
String typeString = nextId.getResourceType();
if (isBlank(typeString)) {

View File

@ -42,6 +42,8 @@ public class DaoConfig {
* </ul>
*/
public static final Set<String> DEFAULT_LOGICAL_BASE_URLS = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
"http://hl7.org/fhir/ValueSet/*",
"http://hl7.org/fhir/CodeSystem/*",
"http://hl7.org/fhir/valueset-*",
"http://hl7.org/fhir/codesystem-*",
"http://hl7.org/fhir/StructureDefinition/*")));

View File

@ -75,6 +75,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
*/
@Test
public void testBuiltInLogicalReferences() throws IOException {
myDaoConfig.getTreatReferencesAsLogical().add("http://phr.kanta.fi/fiphr-vs-*");
ValueSet vsBodySite = loadResourceFromClasspath(ValueSet.class, "/issue534/fiphr-vs-bodysite.xml");
myValueSetDao.create(vsBodySite, mySrd);
ValueSet vsObsMethod = loadResourceFromClasspath(ValueSet.class, "/issue534/fiphr-vs-observationmethod.xml");
myValueSetDao.create(vsObsMethod, mySrd);
StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/issue534/bw_profile_snapshot.xml");
myStructureDefinitionDao.create(sd, mySrd);
@ -93,6 +99,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
@After
public final void after() {
myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences());
myDaoConfig.setTreatReferencesAsLogical(new DaoConfig().getTreatReferencesAsLogical());
}

View File

@ -1,5 +1,4 @@
<ValueSet>
<id value="ce86ecda-449a-4549-9b23-da29385d842a" />
<meta>
<versionId value="1" />
<lastUpdated value="2017-02-23T08:25:27.174+00:00" />

View File

@ -1,5 +1,4 @@
<ValueSet>
<id value="cace1036-1195-49f4-981e-9e8f3f95ef27" />
<meta>
<versionId value="5" />
<lastUpdated value="2017-03-02T14:04:07.769+00:00" />