Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump org.hl7.fhir.core to 6.4.4 #6510

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public void wereBack() {
myErrorHandler.containedResourceWithNoId(null);
} else {
if (!res.getId().isLocal()) {
res.setId(new IdDt('#' + res.getId().getIdPart()));
res.setId(new IdDt(res.getId().getIdPart()));
}
getPreResourceState().getContainedResources().put(res.getId().getValueAsString(), res);
}
Expand Down Expand Up @@ -439,7 +439,7 @@ public void wereBack() {
// need an ID to be referred to)
myErrorHandler.containedResourceWithNoId(null);
} else {
res.getIdElement().setValue('#' + res.getIdElement().getIdPart());
res.getIdElement().setValue(res.getIdElement().getIdPart());
getPreResourceState()
.getContainedResources()
.put(res.getIdElement().getValue(), res);
Expand Down Expand Up @@ -1238,12 +1238,13 @@ void weaveContainedResources() {
String ref = nextRef.getReferenceElement().getValue();
if (isNotBlank(ref)) {
if (ref.startsWith("#") && ref.length() > 1) {
IBaseResource target = myContainedResources.get(ref);
String refId = ref.substring(1);
IBaseResource target = myContainedResources.get(refId);
if (target != null) {
ourLog.debug("Resource contains local ref {}", ref);
ourLog.debug("Resource contains local ref {}", refId);
nextRef.setResource(target);
} else {
myErrorHandler.unknownReference(null, ref);
myErrorHandler.unknownReference(null, refId);
}
}
}
Expand Down
20 changes: 7 additions & 13 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import ca.uhn.fhir.model.api.ISupportsUndeclaredExtensions;
import ca.uhn.fhir.model.base.composite.BaseContainedDt;
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.parser.DataFormatException;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -1507,16 +1508,7 @@ public ContainedResources containResources(IBaseResource theResource, OptionsEnu
ContainedResources contained = new ContainedResources();

List<? extends IBaseResource> containedResources = getContainedResourceList(theResource);
for (IBaseResource next : containedResources) {
String nextId = next.getIdElement().getValue();
if (StringUtils.isNotBlank(nextId)) {
if (!nextId.startsWith("#")) {
nextId = '#' + nextId;
}
next.getIdElement().setValue(nextId);
}
contained.addContained(next);
}
containedResources.forEach(contained::addContained);

if (myContext.getParserOptions().isAutoContainReferenceTargetsWithNoId()) {
containResourcesForEncoding(contained, theResource, modifyResource);
Expand Down Expand Up @@ -1809,10 +1801,12 @@ public IIdType addContained(IBaseResource theResource) {
if (existing != null) {
return existing;
}

IIdType newId = theResource.getIdElement();
IIdType newId = new IdDt(theResource.getIdElement());
if (isBlank(newId.getValue())) {
newId.setValue("#" + UUID.randomUUID());
UUID randomUUID = UUID.randomUUID();
theResource.getIdElement().setValue(randomUUID.toString());
newId.setValue("#" + randomUUID);
}

getResourceToIdMap().put(theResource, newId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ select foo()
IHfqlExecutionResult result = myHfqlExecutor.executeInitialSearch(statement, null, mySrd);
IHfqlExecutionResult.Row row = result.getNextRow();
assertEquals(IHfqlExecutionResult.ROW_OFFSET_ERROR, row.getRowOffset());
assertEquals("Failed to evaluate FHIRPath expression \"foo()\". Error: HAPI-2404: Error in ?? at 1, 1: The name foo is not a valid function name", row.getRowValues().get(0));
assertEquals("Failed to evaluate FHIRPath expression \"foo()\". Error: HAPI-2404: Error @1, 1: The name foo is not a valid function name", row.getRowValues().get(0));
assertFalse(result.hasNext());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,10 @@ public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base
public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
return null;
}

@Override
public boolean paramIsType(String name, int index) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,18 @@ private void extractSearchIndexParametersForTargetResources(

private IBaseResource findContainedResource(Collection<IBaseResource> resources, IBaseReference reference) {
for (IBaseResource resource : resources) {
if (resource.getIdElement().equals(reference.getReferenceElement())) return resource;
String idElementId = resource.getIdElement().getValueAsString();
String referenceElementId = reference.getReferenceElement().getValueAsString();
if (containedResourceEquals(idElementId, referenceElementId)) return resource;
}
return null;
}

private static boolean containedResourceEquals(String idElementId, String referenceElementId) {
String normalizedIdElementId = idElementId.startsWith("#") ? idElementId : "#" + idElementId;
return StringUtils.equals(normalizedIdElementId, referenceElementId);
}

private void mergeParams(ResourceIndexedSearchParams theSrcParams, ResourceIndexedSearchParams theTargetParams) {

theTargetParams.myNumberParams.addAll(theSrcParams.myNumberParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ public void testShouldResolveAThreeLinkChainWithAContainedResourceAtTheEndOfTheC
obs.getCode().addCoding().setCode("obs2").setSystem("Some System").setDisplay("Body weight as measured by me");
obs.setStatus(Observation.ObservationStatus.FINAL);
obs.setValue(new Quantity(81));
obs.setSubject(new Reference(p.getId()));
obs.setSubject(new Reference("#" + p.getId()));
obs.setEncounter(new Reference(encounter.getId()));
oid1 = myObservationDao.create(obs, mySrd).getId().toUnqualifiedVersionless();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ public void testSearchParameterDescendsIntoContainedResource() {
mySearchParamRegistry.forceRefresh();

Specimen specimen = new Specimen();
specimen.setId("#FOO");
specimen.setId("FOO");
specimen.setReceivedTimeElement(new DateTimeType("2011-01-01"));
Observation o = new Observation();
o.setId("O1");
Expand All @@ -1529,7 +1529,7 @@ public void testSearchParameterDescendsIntoContainedResource() {
myObservationDao.update(o);

specimen = new Specimen();
specimen.setId("#FOO");
specimen.setId("FOO");
specimen.setReceivedTimeElement(new DateTimeType("2011-01-03"));
o = new Observation();
o.setId("O2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3224,7 +3224,7 @@ public void testTransactionWithContainedResource() {
patient = myPatientDao.read(new IdType(id));

assertThat(patient.getManagingOrganization().getReference()).containsPattern(HASH_UUID_PATTERN);
assertEquals(patient.getManagingOrganization().getReference(), patient.getContained().get(0).getId());
assertEquals(patient.getManagingOrganization().getReference(), "#" + patient.getContained().get(0).getId());
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy;
import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.validation.instance.advisor.BasePolicyAdvisorForFullValidation;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
Expand Down Expand Up @@ -1069,6 +1070,18 @@ public boolean isSuppressMessageId(String path, String messageId) {
public ReferenceValidationPolicy getReferencePolicy() {
return ReferenceValidationPolicy.IGNORE;
}

@Override
public IValidationPolicyAdvisor getPolicyAdvisor() {
return new BasePolicyAdvisorForFullValidation(getReferencePolicy());
}

@Override
public IValidationPolicyAdvisor setPolicyAdvisor(IValidationPolicyAdvisor policyAdvisor) {
return null;
}


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void testMatcherBadFhirPath() throws IOException {
try {
setMdmRuleJson("bad-rules-bad-fhirpath.json");
fail(); } catch (ConfigurationException e) {
assertThat(e.getMessage()).startsWith(Msg.code(1518) + "MatchField [given-name] resourceType [Patient] has failed FHIRPath evaluation. Error in ?? at 1, 1: The name blurst is not a valid function name");
assertThat(e.getMessage()).startsWith(Msg.code(1518) + "MatchField [given-name] resourceType [Patient] has failed FHIRPath evaluation. Error @1, 1: The name blurst is not a valid function name");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy;
import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.validation.instance.advisor.BasePolicyAdvisorForFullValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -123,6 +124,16 @@ public boolean isSuppressMessageId(String path, String messageId) {
return false;
}

@Override
public IValidationPolicyAdvisor getPolicyAdvisor() {
return new BasePolicyAdvisorForFullValidation(getReferencePolicy());
}

@Override
public IValidationPolicyAdvisor setPolicyAdvisor(IValidationPolicyAdvisor policyAdvisor) {
return null;
}

@Override
public ReferenceValidationPolicy getReferencePolicy() {
return ReferenceValidationPolicy.IGNORE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
import org.hl7.fhir.r5.utils.validation.ValidatorSession;
import org.hl7.fhir.validation.instance.InstanceValidator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -56,7 +57,7 @@ public void checkFetchByUrl() {
InstanceValidator v = new InstanceValidator(
wrappedWorkerContext,
new FhirInstanceValidator.NullEvaluationContext(),
new XVerExtensionManager(null));
new XVerExtensionManager(null), new ValidatorSession());
RequestDetails r = new SystemRequestDetails();
// test
Element returnedResource = fetcher.fetch(v, r,"http://www.test-url-for-questionnaire.com/Questionnaire/test-id|1.0.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public void testEncodeAndParseContained() {

assertNotNull(patient.getManagingOrganization().getResource());
org = (Organization) patient.getManagingOrganization().getResource();
assertEquals("#" + organizationUuid, org.getIdElement().getValue());
assertEquals(organizationUuid, org.getIdElement().getValue());
assertEquals("Contained Test Organization", org.getName());

// And re-encode a second time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testConstrainedFieldContainedResource() {

medication = (Medication) mo.getMedication().getResource();
assertNotNull(medication);
assertEquals("#" + medicationUuid, medication.getId().getValue());
assertEquals(medicationUuid, medication.getId().getValue());
assertEquals("MED TEXT", medication.getCode().getText());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -1391,7 +1392,7 @@ public void testParseAndEncodeBundle() throws Exception {
*/
@Test
public void testParseAndEncodeBundleFromXmlToJson() throws Exception {
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example2.xml"));
String content = IOUtils.toString(Objects.requireNonNull(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example2.xml")), StandardCharsets.UTF_8);

ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, content);

Expand All @@ -1400,7 +1401,7 @@ public void testParseAndEncodeBundleFromXmlToJson() throws Exception {

Medication m = (Medication) ((ResourceReferenceDt) p.getMedication()).getResource();
assertNotNull(m);
assertEquals("#med", m.getId().getValue());
assertEquals("med", m.getId().getValue());
assertThat(p.getContained().getContainedResources()).hasSize(1);
assertThat(p.getContained().getContainedResources().get(0)).isSameAs(m);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -221,18 +222,18 @@ public void testParseXmlModifierExtensionWithoutUrl() {
*/
@Test
public void testParseWovenContainedResources() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_woven_obs.xml"), StandardCharsets.UTF_8);
String string = IOUtils.toString(Objects.requireNonNull(getClass().getResourceAsStream("/bundle_with_woven_obs.xml")), StandardCharsets.UTF_8);

IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);

DiagnosticReport resource = (DiagnosticReport) bundle.getEntry().get(0).getResource();
Observation obs = (Observation) resource.getResult().get(1).getResource();
assertEquals("#2", obs.getId().getValue());
assertEquals("2", obs.getId().getValue());
ResourceReferenceDt performerFirstRep = obs.getPerformer().get(0);
Practitioner performer = (Practitioner) performerFirstRep.getResource();
assertEquals("#3", performer.getId().getValue());
assertEquals("3", performer.getId().getValue());
}

@Test
Expand Down Expand Up @@ -301,13 +302,13 @@ public void testContainedResourceWithNoIdLenient() throws IOException {
@Test
public void testParseWithInvalidLocalRef() throws IOException {
try {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
String string = IOUtils.toString(Objects.requireNonNull(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml")), StandardCharsets.UTF_8);

IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
fail(); } catch (DataFormatException e) {
assertEquals(Msg.code(1851) + "DataFormatException at [[row,col {unknown-source}]: [47,7]]: " + Msg.code(1826) + "Resource has invalid reference: #1", e.getMessage());
assertEquals(Msg.code(1851) + "DataFormatException at [[row,col {unknown-source}]: [47,7]]: " + Msg.code(1826) + "Resource has invalid reference: 1", e.getMessage());
}
}

Expand Down Expand Up @@ -536,7 +537,7 @@ public void testEncodeAndParseContained() {

assertNotNull(patient.getManagingOrganization().getResource());
org = (Organization) patient.getManagingOrganization().getResource();
assertEquals("#" + organizationUuid, org.getId().getValue());
assertEquals(organizationUuid, org.getId().getValue());
assertEquals("Contained Test Organization", org.getName());

// And re-encode a second time
Expand Down Expand Up @@ -568,6 +569,35 @@ public void testEncodeAndParseContained() {

}

@Test
void testEncodeContainedResourceWithNoExplicitId() {
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);

String organizationUuid = UUID.randomUUID().toString();
// Create an organization, note that the organization does not have an ID
Organization org = new Organization();
org.getNameElement().setValue("Contained Test Organization");
org.setId(organizationUuid);

Patient patient = new Patient();
patient.setId("Patient/1333");
patient.addIdentifier().setSystem("urn:mrns").setValue("253345");

// Put the organization as a reference in the patient resource
patient.getManagingOrganization().setResource(org);


//patient.getContained().getContainedResources().clear();
patient.getManagingOrganization().setReference((String) null);
String encoded = xmlParser.encodeResourceToString(patient);
ourLog.info(encoded);
assertThat(encoded).containsSubsequence(Arrays.asList("<contained>", "<Organization ", "<id value=\"" + organizationUuid +
"\"/>", "</Organization", "</contained>", "<reference value=\"#" + organizationUuid + "\"/>"));
assertThat(encoded).doesNotContainPattern("(?s)<contained>.*<Org.*<contained>");
assertThat(encoded).contains("<reference value=\"#" + organizationUuid + "\"/>");

}

@Test
public void testEncodeAndParseContainedCustomTypes() {
ourCtx = FhirContext.forDstu2();
Expand Down Expand Up @@ -2953,11 +2983,7 @@ public static void afterClassClearContext() {
TestUtil.randomizeLocaleAndTimezone();
}

public static void main(String[] args) {
IGenericClient c = ourCtx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open");
// c.registerInterceptor(new LoggingInterceptor(true));
c.read().resource("Patient").withId("324").execute();
}


public static void compareXml(String content, String reEncoded) {
Diff d = DiffBuilder.compare(Input.fromString(content))
Expand Down
Loading
Loading