Skip to content

Commit

Permalink
Fixed all the structure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madduci committed Mar 5, 2025
1 parent dc622ab commit 781b538
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1286,13 +1286,11 @@ public void wereBack() {
super.wereBack();

IResource nextResource = (IResource) getCurrentElement();
String version = nextResource.getId().getVersionIdPart();
// for DSTU2, we cannot use directly "nextResource.getId().getVersionIdPart();"
String version = ResourceMetadataKeyEnum.VERSION.get(nextResource);
String resourceName = myContext.getResourceType(nextResource);
String bundleIdPart = nextResource.getId().getIdPart();
if (isNotBlank(bundleIdPart)) {
// if (isNotBlank(entryBaseUrl)) {
// nextResource.setId(new IdDt(entryBaseUrl, resourceName, bundleIdPart, version));
// } else {
IdDt previousId = nextResource.getId();
nextResource.setId(new IdDt(null, resourceName, bundleIdPart, version));
// Copy extensions
Expand All @@ -1301,7 +1299,6 @@ public void wereBack() {
nextResource.getId().addUndeclaredExtension(ext);
}
}
// }
}
}
}
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 @@ -1345,7 +1345,7 @@ public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnPar

@Test
public void testParseAndEncodeBundle() throws Exception {
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"), StandardCharsets.UTF_8);

Bundle parsed = ourCtx.newJsonParser().parseResource(Bundle.class, content);
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
Expand Down Expand Up @@ -1391,7 +1391,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(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 +1400,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 All @@ -1415,12 +1415,12 @@ public void testParseAndEncodeBundleFromXmlToJson() throws Exception {

@Test
public void testParseAndEncodeBundleNewStyle() throws Exception {
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));

String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"), StandardCharsets.UTF_8);
ourLog.info("Parsed Content \n{}", content);
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, content);
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
assertThat(parsed.getResourceMetadata()).containsEntry(ResourceMetadataKeyEnum.VERSION, "1");
assertEquals("1", parsed.getId().getVersionIdPart());
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
assertEquals("searchset", parsed.getTypeElement().getValue());
assertEquals(3, parsed.getTotal().intValue());
Expand Down Expand Up @@ -1459,7 +1459,7 @@ public void testParseAndEncodeBundleNewStyle() throws Exception {

@Test
public void testParseAndEncodeBundleOldStyle() throws Exception {
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"), StandardCharsets.UTF_8);

Bundle parsed = ourCtx.newJsonParser().parseResource(Bundle.class, content);

Expand Down Expand Up @@ -1501,7 +1501,7 @@ public void testParseAndEncodeBundleOldStyle() throws Exception {

@Test
public void testParseAndEncodeBundleResourceWithComments() throws Exception {
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-transaction2.json"));
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-transaction2.json"), StandardCharsets.UTF_8);

ourCtx.newJsonParser().parseResource(Bundle.class, content);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ public void testParseWovenContainedResources() throws IOException {

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 @@ -536,7 +536,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 @@ -2523,7 +2523,6 @@ public void testParseBundleWithResourceId() {
+ "<entry><fullUrl value=\"http://localhost:58402/fhir/context/Patient/1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"1\"/><meta><versionId value=\"1\"/><lastUpdated value=\"2015-09-11T23:35:42.295-04:00\"/></meta><name><family value=\"testHistoryWithDeletedResource\"/></name></Patient></resource></entry>"
+ "</Bundle>\n";
//@formatter:on

ca.uhn.fhir.model.dstu2.resource.Bundle bundle = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
assertEquals("http://localhost:58402/fhir/context/Patient/1/_history/3", bundle.getEntry().get(0).getResource().getId().getValue());
assertEquals("http://localhost:58402/fhir/context/Patient/1/_history/2", bundle.getEntry().get(1).getResource().getId().getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void testEncodeContained() {

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 @@ -241,7 +241,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

0 comments on commit 781b538

Please sign in to comment.