From 8e7cb0e0a1318cca67e0dd5b22eb4ab1eeba52ed Mon Sep 17 00:00:00 2001 From: craig mcclendon Date: Thu, 13 Mar 2025 09:34:28 -0500 Subject: [PATCH] registered diff provider (#791) * registered provider * spotless fix --- .../jpa/starter/common/StarterJpaConfig.java | 7 +++- .../fhir/jpa/starter/ExampleServerR4IT.java | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.java b/src/main/java/ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.java index 167dc77..386c503 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.java @@ -32,6 +32,7 @@ import ca.uhn.fhir.jpa.model.config.SubscriptionSettings; import ca.uhn.fhir.jpa.packages.IPackageInstallerSvc; import ca.uhn.fhir.jpa.packages.PackageInstallationSpec; import ca.uhn.fhir.jpa.provider.DaoRegistryResourceSupportedSvc; +import ca.uhn.fhir.jpa.provider.DiffProvider; import ca.uhn.fhir.jpa.provider.IJpaSystemProvider; import ca.uhn.fhir.jpa.provider.JpaCapabilityStatementProvider; import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2; @@ -289,7 +290,8 @@ public class StarterJpaConfig { ThreadSafeResourceDeleterSvc theThreadSafeResourceDeleterSvc, ApplicationContext appContext, Optional theIpsOperationProvider, - Optional implementationGuideOperationProvider) { + Optional implementationGuideOperationProvider, + DiffProvider diffProvider) { RestfulServer fhirServer = new RestfulServer(fhirSystemDao.getContext()); List supportedResourceTypes = appProperties.getSupported_resource_types(); @@ -458,6 +460,9 @@ public class StarterJpaConfig { // Validation repositoryValidatingInterceptor.ifPresent(fhirServer::registerInterceptor); + // Diff Provider + fhirServer.registerProvider(diffProvider); + // register custom interceptors registerCustomInterceptors(fhirServer, appContext, appProperties.getCustomInterceptorClasses()); diff --git a/src/test/java/ca/uhn/fhir/jpa/starter/ExampleServerR4IT.java b/src/test/java/ca/uhn/fhir/jpa/starter/ExampleServerR4IT.java index b33dc74..d8044d8 100644 --- a/src/test/java/ca/uhn/fhir/jpa/starter/ExampleServerR4IT.java +++ b/src/test/java/ca/uhn/fhir/jpa/starter/ExampleServerR4IT.java @@ -325,6 +325,39 @@ class ExampleServerR4IT implements IServerSupport { } + @Test + void testDiffOperationIsRegistered() { + String methodName = "testDiff"; + ourLog.info("Entering " + methodName + "()..."); + + Patient pt = new Patient(); + pt.setActive(true); + pt.getBirthDateElement().setValueAsString("2020-01-01"); + pt.addIdentifier().setSystem("http://foo").setValue("12345"); + pt.addName().setFamily(methodName); + IIdType id = ourClient.create().resource(pt).execute().getId(); + + //now update the patient + pt.setId(id); + pt.getBirthDateElement().setValueAsString("2025-01-01"); + ourClient.update().resource(pt).execute(); + + //now try a diff + Parameters outParams = ourClient.operation().onInstance(id).named("$diff").withNoParameters(Parameters.class).execute(); + ourLog.trace("Params->\n{}", ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outParams)); + boolean foundDobChange = false; + //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 + for(Parameters.ParametersParameterComponent ppc : outParams.getParameter() ) { + for(Parameters.ParametersParameterComponent ppc2 : ppc.getPart() ) { + if( "Patient.birthDate".equals(ppc2.getValue().toString()) ){ + foundDobChange = true; + break; + } + } + } + assertTrue(foundDobChange); + } + @BeforeEach void beforeEach() { @@ -338,4 +371,5 @@ class ExampleServerR4IT implements IServerSupport { // return activeSubscriptionCount() == 2; // 2 subscription based on mdm-rules.json //}); } + }