use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldCreateNewAllergyAsJson.
@Test
public void shouldCreateNewAllergyAsJson() throws Exception {
// read JSON record
String jsonAllergy;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_ALLERGY_DOCUMENT)) {
Objects.requireNonNull(is);
jsonAllergy = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create allergy
MockHttpServletResponse response = post("/AllergyIntolerance").accept(FhirMediaTypes.JSON).jsonContent(jsonAllergy).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
AllergyIntolerance allergy = readResponse(response);
assertThat(allergy, notNullValue());
assertThat(allergy.getPatient().getReferenceElement().getIdPart(), equalTo("da7f524f-27ce-4bb2-86d6-6d1d05312bd5"));
assertThat(allergy.getRecorder().getReferenceElement().getIdPart(), equalTo("c98a1558-e131-11de-babe-001e378eb67e"));
assertThat(allergy.getCategory().get(0).getValue().toCode(), equalTo("medication"));
assertThat(allergy.getReactionFirstRep().getSeverity().toCode(), equalTo("severe"));
assertThat(allergy.getReactionFirstRep().getManifestationFirstRep().getCodingFirstRep().getCode(), equalTo("5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
assertThat(allergy.getReactionFirstRep().getManifestationFirstRep().getText(), equalTo("manifestation text"));
assertThat(allergy.getCode().getCodingFirstRep().getCode(), equalTo("5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
assertThat(allergy.getClinicalStatus().toCode(), equalTo("active"));
assertThat(allergy.getVerificationStatus().toCode(), equalTo("confirmed"));
assertThat(allergy.getType().toCode(), equalTo("allergy"));
assertThat(allergy, validResource());
// try to get new allergy
response = get("/AllergyIntolerance/" + allergy.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
AllergyIntolerance newAllergy = readResponse(response);
assertThat(newAllergy.getId(), equalTo(allergy.getId()));
}
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 shouldReturnCountForMedicationAsXml.
@Test
public void shouldReturnCountForMedicationAsXml() throws Exception {
MockHttpServletResponse response = get("/Medication?_summary=count").accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.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 shouldReturnExistingMedicationAsJson.
@Test
public void shouldReturnExistingMedicationAsJson() throws Exception {
MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Medication medication = readResponse(response);
assertThat(medication, notNullValue());
assertThat(medication.getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
assertThat(medication, validResource());
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderIntegrationTest method shouldReturnExistingMedicationAsXML.
@Test
public void shouldReturnExistingMedicationAsXML() throws Exception {
MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Medication medication = readResponse(response);
assertThat(medication, notNullValue());
assertThat(medication.getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
assertThat(medication, validResource());
}
Aggregations