-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement R4RepositorySubjectProvider logic for managingOrganization …
…and partOf. Draft unit test class. No conditional logic for partOf yet.
- Loading branch information
1 parent
f8b5dab
commit 16bb417
Showing
3 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...-cr/src/test/java/org/opencds/cqf/fhir/cr/measure/r4/R4RepositorySubjectProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.opencds.cqf.fhir.cr.measure.r4; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.hl7.fhir.instance.model.api.IIdType; | ||
import org.hl7.fhir.r4.model.IdType; | ||
import org.hl7.fhir.r4.model.Organization; | ||
import org.hl7.fhir.r4.model.Patient; | ||
import org.hl7.fhir.r4.model.Reference; | ||
import org.hl7.fhir.r4.model.ResourceType; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.opencds.cqf.fhir.api.Repository; | ||
import org.opencds.cqf.fhir.cr.measure.common.MeasureEvalType; | ||
import org.opencds.cqf.fhir.utility.repository.InMemoryFhirRepository; | ||
|
||
class R4RepositorySubjectProviderTest { | ||
|
||
private static final String PAT_ID_1 = "pat1"; | ||
private static final String PAT_ID_2 = "pat2"; | ||
private static final String ORG_ID_1 = "org1"; | ||
private static final String ORG_ID_2 = "org2"; | ||
|
||
private final Repository repository = new InMemoryFhirRepository(FhirContext.forR4Cached()); | ||
private final R4RepositorySubjectProvider testSubject = new R4RepositorySubjectProvider(); | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
final Organization org1 = | ||
(Organization) new Organization().setId(new IdType(ResourceType.Organization.toString(), ORG_ID_1)); | ||
final IIdType orgId1 = repository.update(org1).getId().toUnqualifiedVersionless(); | ||
|
||
final Organization org2 = (Organization) new Organization() | ||
.setPartOf(new Reference(orgId1.toUnqualifiedVersionless().getValue())) | ||
.setId(new IdType(ResourceType.Organization.toString(), ORG_ID_2)); | ||
|
||
final IIdType orgId2 = repository.update(org2).getId().toUnqualifiedVersionless(); | ||
|
||
final Patient patient1 = new Patient(); | ||
patient1.setId(PAT_ID_1); | ||
patient1.setManagingOrganization( | ||
new Reference(orgId1.toUnqualifiedVersionless().getValue())); | ||
|
||
final Patient patient2 = new Patient(); | ||
patient2.setId(PAT_ID_2); | ||
patient2.setManagingOrganization( | ||
new Reference(orgId2.toUnqualifiedVersionless().getValue())); | ||
|
||
final IIdType patientId1 = repository.update(patient1).getId().toUnqualifiedVersionless(); | ||
final IIdType patientId2 = repository.update(patient2).getId().toUnqualifiedVersionless(); | ||
} | ||
|
||
public static Stream<Arguments> getSubjectsParams() { | ||
return Stream.of(Arguments.of( | ||
MeasureEvalType.SUBJECT, | ||
List.of(resourcify(ResourceType.Organization, ORG_ID_1)), | ||
Stream.of(PAT_ID_1, PAT_ID_2) | ||
.map(id -> resourcify(ResourceType.Patient, id)) | ||
.toList())); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getSubjectsParams") | ||
void getSubjects(MeasureEvalType measureEvalType, List<String> subjectIds, List<String> expectedSubjects) { | ||
final List<String> actualSubjects = | ||
testSubject.getSubjects(repository, measureEvalType, subjectIds).collect(Collectors.toList()); | ||
|
||
assertThat(actualSubjects, equalTo(expectedSubjects)); | ||
} | ||
|
||
private static String resourcify(ResourceType resourceType, String rawId) { | ||
return String.format("%s/%s", resourceType.toString(), rawId); | ||
} | ||
} |