Skip to content

Commit

Permalink
Address some code review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukedegruchy committed Nov 20, 2024
1 parent e9d1a54 commit 2124ae4
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ public class SubjectProviderOptions {

private boolean isPartOfEnabled;

/**
* @return true if clinical-reasoning is configured to resolve subject Organization queries
* in which Organizations related by partOf when compiling the list of Patients related by
* managingOrganization.
* <p/>
* false to disregard any Organizations and patients related by partOf.
*/
public boolean isPartOfEnabled() {
return isPartOfEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.stream.Stream;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Group;
import org.hl7.fhir.r4.model.Group.GroupMemberComponent;
import org.hl7.fhir.r4.model.Group.GroupType;
Expand Down Expand Up @@ -159,17 +158,7 @@ private Stream<String> getManagingOrganizationSubjectIds(String organization, Re

searchParams.put("organization", Collections.singletonList(new ReferenceParam(organization)));

var bundle = repository.search(Bundle.class, Patient.class, searchParams);

var bundleEntries = bundle.getEntry();

if (bundleEntries == null || bundleEntries.isEmpty()) {
return Stream.empty();
}

return bundleEntries.stream()
.map(BundleEntryComponent::getResource)
.map(idElement -> idElement.getResourceType() + "/" + idElement.getIdPart());
return handlePatientBundle(repository, searchParams);
}

private Stream<String> getPartOfSubjectIds(String organization, Repository repository) {
Expand All @@ -184,10 +173,28 @@ private Stream<String> getPartOfSubjectIds(String organization, Repository repos
"organization",
Collections.singletonList(new ReferenceParam("organization", organization).setChain("partof")));

return repository.search(Bundle.class, Patient.class, searchParam).getEntry().stream()
.map(BundleEntryComponent::getResource)
.filter(Patient.class::isInstance)
.map(Patient.class::cast)
.map(idElement -> String.format("%s/%s", ResourceType.Patient, idElement.getIdPart()));
return handlePatientBundle(repository, searchParam);
}

private static Stream<String> handlePatientBundle(
Repository repository, Map<String, List<IQueryParameterType>> searchParam) {
var bundle = repository.search(Bundle.class, Patient.class, searchParam);

var bundleEntries = bundle.getEntry();

if (bundleEntries == null || bundleEntries.isEmpty()) {
return Stream.empty();
}

var iterator = new BundleIterator<>(repository, bundle);
var patientIds = new ArrayList<String>();

iterator.forEachRemaining(item -> {
var resource = item.getResource();
var idElement = resource.getIdElement();
patientIds.add(ResourceType.Patient + "/" + idElement.getIdPart());
});

return patientIds.stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,9 @@ void MultiMeasure_EightMeasures_ReporterNotAcceptedResource() {
.hasReporter("Patient/male-2022"));
}

// This test is effectively a sanity test to ensure that Organization subjects
// do not error out as they did previous to the new feature that enables to this feature./
// For more complex scenarios please see R4RepositorySubjectProviderTest.
@Test
void MultiMeasure_EightMeasures_SubjectOrganization() {
var when = GIVEN_REPO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class R4RepositorySubjectProviderTest {
private static final String ORG_ID_1 = "org1";
private static final String ORG_ID_2 = "org2";

private static final String PRACTITIONER_ID_1 = "pra1";

private static final R4RepositorySubjectProvider TEST_SUBJECT_ENABLE_PART_OF =
new R4RepositorySubjectProvider(new SubjectProviderOptions().setPartOfEnabled(true));
private static final R4RepositorySubjectProvider TEST_SUBJECT_DISABLE_PART_OF =
Expand Down Expand Up @@ -74,14 +76,62 @@ public static Stream<Arguments> getSubjectsParams() {
// with a repository that supports DAOs.
Stream.of(PAT_ID_1, PAT_ID_1)
.map(id -> resourcify(ResourceType.Patient, id))
.collect(Collectors.toList())),
.toList()),
Arguments.of(
TEST_SUBJECT_DISABLE_PART_OF,
MeasureEvalType.SUBJECT,
List.of(resourcify(ResourceType.Organization, ORG_ID_1)),
Stream.of(PAT_ID_1)
.map(id -> resourcify(ResourceType.Patient, id))
.collect(Collectors.toList())));
.toList()),
Arguments.of(
TEST_SUBJECT_ENABLE_PART_OF,
MeasureEvalType.POPULATION,
List.of(resourcify(ResourceType.Organization, ORG_ID_1)),
// TODO: LD: this is technically incorrect: it should be PAT_ID_1, PAT_ID_2
// However, due to the fact that both InMemoryFhirRepository and IgRepository
// do NOT support chained searches, the results can only be accurately verified
// with a repository that supports DAOs.
Stream.of(PAT_ID_1, PAT_ID_1)
.map(id -> resourcify(ResourceType.Patient, id))
.toList())
// ,
// Arguments.of(
// TEST_SUBJECT_DISABLE_PART_OF,
// MeasureEvalType.POPULATION,
// List.of(resourcify(ResourceType.Organization, ORG_ID_1)),
// Stream.of(PAT_ID_1)
// .map(id -> resourcify(ResourceType.Patient, id))
// .toList()),
// Arguments.of(
// TEST_SUBJECT_ENABLE_PART_OF,
// MeasureEvalType.SUBJECT,
// List.of(resourcify(ResourceType.Practitioner, PRACTITIONER_ID_1)),
// Stream.of(PAT_ID_1, PAT_ID_1)
// .map(id -> resourcify(ResourceType.Patient, id))
// .toList()),
// Arguments.of(
// TEST_SUBJECT_DISABLE_PART_OF,
// MeasureEvalType.SUBJECT,
// List.of(resourcify(ResourceType.Practitioner, PRACTITIONER_ID_1)),
// Stream.of(PAT_ID_1)
// .map(id -> resourcify(ResourceType.Patient, id))
// .toList()),
// Arguments.of(
// TEST_SUBJECT_ENABLE_PART_OF,
// MeasureEvalType.POPULATION,
// List.of(resourcify(ResourceType.Practitioner, PRACTITIONER_ID_1)),
// Stream.of(PAT_ID_1, PAT_ID_1)
// .map(id -> resourcify(ResourceType.Patient, id))
// .toList()),
// Arguments.of(
// TEST_SUBJECT_DISABLE_PART_OF,
// MeasureEvalType.POPULATION,
// List.of(resourcify(ResourceType.Practitioner, PRACTITIONER_ID_1)),
// Stream.of(PAT_ID_1)
// .map(id -> resourcify(ResourceType.Patient, id))
// .toList())
);
}

@ParameterizedTest
Expand Down

0 comments on commit 2124ae4

Please sign in to comment.