Skip to content

Commit 8e7cb0e

Browse files
authored
registered diff provider (hapifhir#791)
* registered provider * spotless fix
1 parent f4f0585 commit 8e7cb0e

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/main/java/ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import ca.uhn.fhir.jpa.packages.IPackageInstallerSvc;
3333
import ca.uhn.fhir.jpa.packages.PackageInstallationSpec;
3434
import ca.uhn.fhir.jpa.provider.DaoRegistryResourceSupportedSvc;
35+
import ca.uhn.fhir.jpa.provider.DiffProvider;
3536
import ca.uhn.fhir.jpa.provider.IJpaSystemProvider;
3637
import ca.uhn.fhir.jpa.provider.JpaCapabilityStatementProvider;
3738
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2;
@@ -289,7 +290,8 @@ public RestfulServer restfulServer(
289290
ThreadSafeResourceDeleterSvc theThreadSafeResourceDeleterSvc,
290291
ApplicationContext appContext,
291292
Optional<IpsOperationProvider> theIpsOperationProvider,
292-
Optional<IImplementationGuideOperationProvider> implementationGuideOperationProvider) {
293+
Optional<IImplementationGuideOperationProvider> implementationGuideOperationProvider,
294+
DiffProvider diffProvider) {
293295
RestfulServer fhirServer = new RestfulServer(fhirSystemDao.getContext());
294296

295297
List<String> supportedResourceTypes = appProperties.getSupported_resource_types();
@@ -458,6 +460,9 @@ public RestfulServer restfulServer(
458460
// Validation
459461
repositoryValidatingInterceptor.ifPresent(fhirServer::registerInterceptor);
460462

463+
// Diff Provider
464+
fhirServer.registerProvider(diffProvider);
465+
461466
// register custom interceptors
462467
registerCustomInterceptors(fhirServer, appContext, appProperties.getCustomInterceptorClasses());
463468

src/test/java/ca/uhn/fhir/jpa/starter/ExampleServerR4IT.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,39 @@ void testActuatorEndpointExists(String endpoint) throws IOException, URISyntaxEx
325325

326326
}
327327

328+
@Test
329+
void testDiffOperationIsRegistered() {
330+
String methodName = "testDiff";
331+
ourLog.info("Entering " + methodName + "()...");
332+
333+
Patient pt = new Patient();
334+
pt.setActive(true);
335+
pt.getBirthDateElement().setValueAsString("2020-01-01");
336+
pt.addIdentifier().setSystem("http://foo").setValue("12345");
337+
pt.addName().setFamily(methodName);
338+
IIdType id = ourClient.create().resource(pt).execute().getId();
339+
340+
//now update the patient
341+
pt.setId(id);
342+
pt.getBirthDateElement().setValueAsString("2025-01-01");
343+
ourClient.update().resource(pt).execute();
344+
345+
//now try a diff
346+
Parameters outParams = ourClient.operation().onInstance(id).named("$diff").withNoParameters(Parameters.class).execute();
347+
ourLog.trace("Params->\n{}", ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outParams));
348+
boolean foundDobChange = false;
349+
//really, if we get a response at all, then the Diff worked, but we'll check the contents here anyway for good measure to see that our change is reflected
350+
for(Parameters.ParametersParameterComponent ppc : outParams.getParameter() ) {
351+
for(Parameters.ParametersParameterComponent ppc2 : ppc.getPart() ) {
352+
if( "Patient.birthDate".equals(ppc2.getValue().toString()) ){
353+
foundDobChange = true;
354+
break;
355+
}
356+
}
357+
}
358+
assertTrue(foundDobChange);
359+
}
360+
328361
@BeforeEach
329362
void beforeEach() {
330363

@@ -338,4 +371,5 @@ void beforeEach() {
338371
// return activeSubscriptionCount() == 2; // 2 subscription based on mdm-rules.json
339372
//});
340373
}
374+
341375
}

0 commit comments

Comments
 (0)