Skip to content

Commit

Permalink
Lift measure parameter cleanup (#551)
Browse files Browse the repository at this point in the history
* fix null pointer and add test

* fix order of null check

* clean up method structure
  • Loading branch information
Capt-Mac authored Oct 8, 2024
1 parent 522fe39 commit a68715f
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.hl7.fhir.r4.model.CanonicalType;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Parameters;
Expand Down Expand Up @@ -75,22 +74,28 @@ protected List<Either3<IdType, String, CanonicalType>> liftMeasureParameters(
List<Either3<IdType, String, CanonicalType>> eitherList = new ArrayList<>();

measureId.stream()
.filter(Objects::nonNull)
.filter(x -> x.getIdPart() != null)
.collect(Collectors.toList())
.forEach(id -> eitherList.add(Eithers.forLeft3(id)));
.filter(this::isValidMeasureIdType)
.map(Eithers::<IdType, String, CanonicalType>forLeft3)
.forEach(eitherList::add);
measureIdentifier.stream()
.filter(Objects::nonNull)
.collect(Collectors.toList())
.forEach(identifier -> eitherList.add(Eithers.forMiddle3(identifier)));
.map(Eithers::<IdType, String, CanonicalType>forMiddle3)
.forEach(eitherList::add);
measureUrl.stream()
.filter(Objects::nonNull)
.filter(x -> !x.toString().contains("null"))
.collect(Collectors.toList())
.forEach(canonical -> eitherList.add(Eithers.forRight3(canonical)));
.filter(this::isValidCanonical)
.map(Eithers::<IdType, String, CanonicalType>forRight3)
.forEach(eitherList::add);
if (eitherList.isEmpty()) {
throw new IllegalArgumentException("no measure resolving parameter was specified");
}
return eitherList;
}

private boolean isValidCanonical(CanonicalType canonicalType) {
return canonicalType != null && !canonicalType.toString().contains("null");
}

private boolean isValidMeasureIdType(IdType measureId) {
return measureId != null && measureId.getIdPart() != null;
}
}

0 comments on commit a68715f

Please sign in to comment.