use of org.hl7.fhir.r4.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupResourceProviderIntegrationTest method shouldReturnPaginatedListOfGroupMembersAsXml.
@Test
public void shouldReturnPaginatedListOfGroupMembersAsXml() throws Exception {
MockHttpServletResponse response = get("/Group/" + GROUP_UUID + "/$members").accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Bundle groupMembers = readBundleResponse(response);
assertThat(groupMembers, notNullValue());
assertThat(groupMembers.getEntry(), not(empty()));
assertThat(groupMembers.getTotal(), is(1));
List<Bundle.BundleEntryComponent> entries = groupMembers.getEntry();
assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/GroupMember/"))));
assertThat(entries, everyItem(hasResource(instanceOf(GroupMember.class))));
assertThat(entries, everyItem(hasResource(hasProperty("entity", hasProperty("reference", startsWith("Patient/"))))));
}
use of org.hl7.fhir.r4.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenDeletingNonExistentGroup.
@Test
public void shouldReturnNotFoundWhenDeletingNonExistentGroup() throws Exception {
MockHttpServletResponse response = delete("/Group/" + BAD_COHORT_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isNotFound());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
use of org.hl7.fhir.r4.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderIntegrationTest method shouldReturnCountForGroupAsJson.
@Test
public void shouldReturnCountForGroupAsJson() throws Exception {
MockHttpServletResponse response = get("/Group?_summary=count").accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Bundle result = readBundleResponse(response);
assertThat(result, notNullValue());
assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(result, hasProperty("total", equalTo(1)));
}
use of org.hl7.fhir.r4.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderIntegrationTest method shouldUpdateExistingGroupAsXML.
@Test
public void shouldUpdateExistingGroupAsXML() throws Exception {
// Before update
MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Group group = readResponse(response);
Extension descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION);
assertThat(group, notNullValue());
assertThat(group, validResource());
assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID));
assertThat(descExtension.getValue().toString(), equalTo("Covid19 patients"));
// Get existing group with updated name
String xmlGroup;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_UPDATE_GROUP_DOCUMENT)) {
Objects.requireNonNull(is);
xmlGroup = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// Update
response = put("/Group/" + COHORT_UUID).xmlContent(xmlGroup).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
// read updated record
group = readResponse(response);
descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION);
assertThat(group, notNullValue());
assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID));
assertThat(group.getActive(), is(true));
assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter"));
assertThat(group, validResource());
// Double-check via get
response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go();
Group updatedGroup = readResponse(response);
descExtension = updatedGroup.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION);
assertThat(updatedGroup, validResource());
assertThat(updatedGroup, notNullValue());
assertThat(updatedGroup.getActive(), is(true));
assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter"));
}
use of org.hl7.fhir.r4.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentGroupAsJSON.
@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentGroupAsJSON() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go();
Group group = readResponse(response);
// update the existing record
group.setId(BAD_COHORT_UUID);
// send the update to the server
response = put("/Group/" + BAD_COHORT_UUID).jsonContent(toJson(group)).accept(FhirMediaTypes.JSON).go();
assertThat(response, isNotFound());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
Aggregations