use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderWebTest method verifyUri.
private void verifyUri(String uri) throws Exception {
when(fhirMedicationService.searchForMedications(any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), 10, 1));
MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
Bundle results = readBundleResponse(response);
assertThat(results.getEntry(), notNullValue());
assertThat(results.getEntry(), not(empty()));
assertThat(results.getEntry().get(0).getResource(), notNullValue());
assertThat(results.getEntry().get(0).getResource().getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationNarrativeTest method shouldGenerateMedicationNarrative.
/**
* Check that the expected narrative is generated for some example Medication resource
*
* @throws IOException
*/
@Test
public void shouldGenerateMedicationNarrative() throws IOException {
Medication given = parser.parseResource(Medication.class, getClass().getClassLoader().getResourceAsStream(EXAMPLE_RESOURCE_PATH));
Medication result = parser.parseResource(Medication.class, parser.encodeResourceToString(given));
assertThat(result, notNullValue());
assertThat(result.getText(), notNullValue());
assertThat(result.getText().getStatusAsString(), equalTo("generated"));
assertThat(result.getText().getDivAsString(), equalTo(readNarrativeFile(EXPECTED_NARRATIVE_PATH)));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsXML.
@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsXML() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.XML).go();
Medication medication = readResponse(response);
// update the existing record
medication.setId(WRONG_MEDICATION_UUID);
// send the update to the server
response = put("/Medication/" + MEDICATION_UUID).xmlContent(toXML(medication)).accept(FhirMediaTypes.XML).go();
assertThat(response, isBadRequest());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderIntegrationTest method shouldReturnCountForMedicationAsJson.
@Test
public void shouldReturnCountForMedicationAsJson() throws Exception {
MockHttpServletResponse response = get("/Medication?_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(4)));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderIntegrationTest method shouldCreateNewMedicationAsXml.
@Test
public void shouldCreateNewMedicationAsXml() throws Exception {
String xmlMedication;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_MEDICATION_DOCUMENT)) {
Objects.requireNonNull(is);
xmlMedication = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create medication
MockHttpServletResponse response = post("/Medication").accept(FhirMediaTypes.XML).xmlContent(xmlMedication).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Medication medication = readResponse(response);
assertThat(medication, notNullValue());
assertThat(medication.getStatus(), is(Medication.MedicationStatus.ACTIVE));
assertThat(medication.getCode().getCodingFirstRep().getCode(), equalTo(MEDICATION_CODE_UUID));
// try to get new medication
response = get(medication.getId()).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
Medication newMedication = readResponse(response);
assertThat(newMedication.getId(), equalTo(medication.getId()));
assertThat(newMedication.getStatus(), equalTo(medication.getStatus()));
}
Aggregations