From da05e9dec2e99bb0e66d8da1f6a9308e48a90a52 Mon Sep 17 00:00:00 2001 From: Luke deGruchy Date: Wed, 29 Jan 2025 09:23:22 -0500 Subject: [PATCH] Spotless. Convert types in parmas constructors. Fix Builder constructors. --- .../server/method/EmbeddedOperationUtils.java | 13 +++++--- .../method/MethodUtilGenericsContext.java | 15 +++++---- .../r4/measure/CareGapsOperationProvider.java | 8 +---- .../fhir/cr/r4/measure/CareGapsParams.java | 33 ++++++++++++------- .../measure/EvaluateMeasureSingleParams.java | 28 +++++++++------- 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/EmbeddedOperationUtils.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/EmbeddedOperationUtils.java index e9d19a088f3..370eaa444af 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/EmbeddedOperationUtils.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/EmbeddedOperationUtils.java @@ -26,6 +26,8 @@ import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.OperationParameterRangeType; import jakarta.annotation.Nonnull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; @@ -46,6 +48,7 @@ * Common operations for any functionality that work with {@link EmbeddedOperationParams} */ public class EmbeddedOperationUtils { + private static final Logger ourLog = LoggerFactory.getLogger(EmbeddedOperationUtils.class); private EmbeddedOperationUtils() {} @@ -230,10 +233,12 @@ private static void validateConstructorArgs(Constructor theConstructor, Field } if (constructorParameterTypeAtIndex != fieldTypeAtIndex) { - final String error = String.format( - "%sInvalid operation embedded parameters. Constructor parameter type does not match field type: %s", - Msg.code(87421741), theConstructor.getDeclaringClass()); - throw new ConfigurationException(error); + // LUKETODO: debug + ourLog.info( + "constructor: {} parameter type: {} is transformed to field type: {}", + theConstructor.getDeclaringClass(), + constructorParameterTypeAtIndex, + fieldTypeAtIndex); } if (Collection.class.isAssignableFrom(constructorParameterTypeAtIndex) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtilGenericsContext.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtilGenericsContext.java index 956b99649ca..f99bae5f080 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtilGenericsContext.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtilGenericsContext.java @@ -65,7 +65,10 @@ public boolean equals(Object theO) { return false; } MethodUtilGenericsContext that = (MethodUtilGenericsContext) theO; - return Objects.equals(parameterType, that.parameterType) && Objects.equals(declaredParameterType, that.declaredParameterType) && Objects.equals(outerCollectionType, that.outerCollectionType) && Objects.equals(innerCollectionType, that.innerCollectionType); + return Objects.equals(parameterType, that.parameterType) + && Objects.equals(declaredParameterType, that.declaredParameterType) + && Objects.equals(outerCollectionType, that.outerCollectionType) + && Objects.equals(innerCollectionType, that.innerCollectionType); } @Override @@ -76,10 +79,10 @@ public int hashCode() { @Override public String toString() { return new StringJoiner(", ", MethodUtilGenericsContext.class.getSimpleName() + "[", "]") - .add("parameterType=" + parameterType) - .add("declaredParameterType=" + declaredParameterType) - .add("outerCollectionType=" + outerCollectionType) - .add("innerCollectionType=" + innerCollectionType) - .toString(); + .add("parameterType=" + parameterType) + .add("declaredParameterType=" + declaredParameterType) + .add("outerCollectionType=" + outerCollectionType) + .add("innerCollectionType=" + innerCollectionType) + .toString(); } } diff --git a/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/CareGapsOperationProvider.java b/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/CareGapsOperationProvider.java index 8ada0d58de6..9b16b4b5d8b 100644 --- a/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/CareGapsOperationProvider.java +++ b/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/CareGapsOperationProvider.java @@ -26,14 +26,12 @@ import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.provider.ProviderConstants; import org.hl7.fhir.r4.model.BooleanType; -import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Measure; import org.hl7.fhir.r4.model.Parameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Optional; -import java.util.stream.Collectors; public class CareGapsOperationProvider { private static final Logger ourLog = LoggerFactory.getLogger(CareGapsOperationProvider.class); @@ -90,11 +88,7 @@ public Parameters careGapsReport( theParams.getSubject(), theParams.getStatus(), // LUKETODO: why can't we have a List @OperationParam? - theParams.getMeasureId() == null - ? null - : theParams.getMeasureId().stream() - .map(IdType::new) - .collect(Collectors.toList()), + theParams.getMeasureId(), theParams.getMeasureIdentifier(), theParams.getMeasureUrl(), Optional.ofNullable(theParams.getNonDocument()) diff --git a/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/CareGapsParams.java b/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/CareGapsParams.java index befb34d71dd..302061179de 100644 --- a/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/CareGapsParams.java +++ b/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/CareGapsParams.java @@ -24,11 +24,13 @@ import ca.uhn.fhir.rest.annotation.OperationParameterRangeType; import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.CanonicalType; +import org.hl7.fhir.r4.model.IdType; import java.time.ZonedDateTime; import java.util.List; import java.util.Objects; import java.util.StringJoiner; +import java.util.stream.Collectors; /** * Non-RequestDetails parameters for the myStatus; - private final List myMeasureId; + private final List myMeasureId; private final List myMeasureIdentifier; @@ -107,21 +109,22 @@ public CareGapsParams( myPeriodEnd = thePeriodEnd; mySubject = theSubject; myStatus = theStatus; - myMeasureId = theMeasureId; + myMeasureId = convertMeasureId(theMeasureId); myMeasureIdentifier = theMeasureIdentifier; myMeasureUrl = theMeasureUrl; myNonDocument = theNonDocument; } - private CareGapsParams(Builder builder) { - myPeriodStart = builder.myPeriodStart; - myPeriodEnd = builder.myPeriodEnd; - mySubject = builder.mySubject; - myStatus = builder.myStatus; - myMeasureId = builder.myMeasureId; - myMeasureIdentifier = builder.myMeasureIdentifier; - myMeasureUrl = builder.myMeasureUrl; - myNonDocument = builder.myNonDocument; + public CareGapsParams(CareGapsParams.Builder builder) { + this( + builder.myPeriodStart, + builder.myPeriodEnd, + builder.mySubject, + builder.myStatus, + builder.myMeasureId, + builder.myMeasureIdentifier, + builder.myMeasureUrl, + builder.myNonDocument); } public ZonedDateTime getPeriodStart() { @@ -140,7 +143,7 @@ public List getStatus() { return myStatus; } - public List getMeasureId() { + public List getMeasureId() { return myMeasureId; } @@ -197,6 +200,12 @@ public String toString() { .toString(); } + private List convertMeasureId(List theMeasureId) { + return theMeasureId == null + ? null + : theMeasureId.stream().map(IdType::new).collect(Collectors.toList()); + } + public static Builder builder() { return new Builder(); } diff --git a/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/EvaluateMeasureSingleParams.java b/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/EvaluateMeasureSingleParams.java index e8329e65e00..8e5ad4493d1 100644 --- a/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/EvaluateMeasureSingleParams.java +++ b/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/r4/measure/EvaluateMeasureSingleParams.java @@ -24,9 +24,13 @@ import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.OperationParameterRangeType; import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.CanonicalType; import org.hl7.fhir.r4.model.Endpoint; import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Measure; import org.hl7.fhir.r4.model.Parameters; +import org.opencds.cqf.fhir.utility.monad.Either3; +import org.opencds.cqf.fhir.utility.monad.Eithers; import java.time.ZonedDateTime; import java.util.Objects; @@ -55,7 +59,7 @@ // LUKETODO: start to integrate this with a clinical reasoning branch @EmbeddableOperationParams public class EvaluateMeasureSingleParams { - private final IdType myId; + private final Either3 myMeasure; private final ZonedDateTime myPeriodStart; @@ -96,7 +100,7 @@ public EvaluateMeasureSingleParams( @OperationParam(name = "additionalData") Bundle theAdditionalData, @OperationParam(name = "terminologyEndpoint") Endpoint theTerminologyEndpoint, @OperationParam(name = "parameters") Parameters theParameters) { - myId = theId; + myMeasure = Eithers.forMiddle3(theId); myPeriodStart = thePeriodStart; myPeriodEnd = thePeriodEnd; myReportType = theReportType; @@ -124,8 +128,8 @@ private EvaluateMeasureSingleParams(Builder builder) { builder.myParameters); } - public IdType getId() { - return myId; + public Either3 getMeasure() { + return myMeasure; } public ZonedDateTime getPeriodStart() { @@ -169,12 +173,12 @@ public Parameters getParameters() { } @Override - public boolean equals(Object o) { - if (o == null || getClass() != o.getClass()) { + public boolean equals(Object theO) { + if (theO == null || getClass() != theO.getClass()) { return false; } - EvaluateMeasureSingleParams that = (EvaluateMeasureSingleParams) o; - return Objects.equals(myId, that.myId) + EvaluateMeasureSingleParams that = (EvaluateMeasureSingleParams) theO; + return Objects.equals(myMeasure, that.myMeasure) && Objects.equals(myPeriodStart, that.myPeriodStart) && Objects.equals(myPeriodEnd, that.myPeriodEnd) && Objects.equals(myReportType, that.myReportType) @@ -190,7 +194,7 @@ public boolean equals(Object o) { @Override public int hashCode() { return Objects.hash( - myId, + myMeasure, myPeriodStart, myPeriodEnd, myReportType, @@ -206,9 +210,9 @@ public int hashCode() { @Override public String toString() { return new StringJoiner(", ", EvaluateMeasureSingleParams.class.getSimpleName() + "[", "]") - .add("myId=" + myId) - .add("myPeriodStart='" + myPeriodStart + "'") - .add("myPeriodEnd='" + myPeriodEnd + "'") + .add("myMeasure=" + myMeasure) + .add("myPeriodStart=" + myPeriodStart) + .add("myPeriodEnd=" + myPeriodEnd) .add("myReportType='" + myReportType + "'") .add("mySubject='" + mySubject + "'") .add("myPractitioner='" + myPractitioner + "'")