Skip to content

Commit

Permalink
Spotless. Convert types in parmas constructors. Fix Builder construct…
Browse files Browse the repository at this point in the history
…ors.
  • Loading branch information
lukedegruchy committed Jan 29, 2025
1 parent 2fba720 commit da05e9d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -90,11 +88,7 @@ public Parameters careGapsReport(
theParams.getSubject(),
theParams.getStatus(),
// LUKETODO: why can't we have a List<IdType> @OperationParam?
theParams.getMeasureId() == null
? null
: theParams.getMeasureId().stream()
.map(IdType::new)
.collect(Collectors.toList()),
theParams.getMeasureId(),
theParams.getMeasureIdentifier(),
theParams.getMeasureUrl(),
Optional.ofNullable(theParams.getNonDocument())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=
Expand Down Expand Up @@ -81,7 +83,7 @@ public class CareGapsParams {

private final List<String> myStatus;

private final List<String> myMeasureId;
private final List<IdType> myMeasureId;

private final List<String> myMeasureIdentifier;

Expand All @@ -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() {
Expand All @@ -140,7 +143,7 @@ public List<String> getStatus() {
return myStatus;
}

public List<String> getMeasureId() {
public List<IdType> getMeasureId() {
return myMeasureId;
}

Expand Down Expand Up @@ -197,6 +200,12 @@ public String toString() {
.toString();
}

private List<IdType> convertMeasureId(List<String> theMeasureId) {
return theMeasureId == null
? null
: theMeasureId.stream().map(IdType::new).collect(Collectors.toList());
}

public static Builder builder() {
return new Builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CanonicalType, IdType, Measure> myMeasure;

private final ZonedDateTime myPeriodStart;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -124,8 +128,8 @@ private EvaluateMeasureSingleParams(Builder builder) {
builder.myParameters);
}

public IdType getId() {
return myId;
public Either3<CanonicalType, IdType, Measure> getMeasure() {
return myMeasure;
}

public ZonedDateTime getPeriodStart() {
Expand Down Expand Up @@ -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)
Expand All @@ -190,7 +194,7 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
return Objects.hash(
myId,
myMeasure,
myPeriodStart,
myPeriodEnd,
myReportType,
Expand All @@ -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 + "'")
Expand Down

0 comments on commit da05e9d

Please sign in to comment.