use of org.hl7.fhir.dstu3.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenImmunizationNotFoundAsXML.
@Test
public void shouldReturnNotFoundWhenImmunizationNotFoundAsXML() throws Exception {
MockHttpServletResponse response = get("/Immunization/" + UNKNOWN_IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
assertThat(response, isNotFound());
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.dstu3.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationFhirResourceProviderIntegrationTest method shouldCreateNewImmunizationAsJson.
@Test
public void shouldCreateNewImmunizationAsJson() throws Exception {
// read JSON record
String jsonImmunization;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_IMMUNIZATION_DOCUMENT)) {
Objects.requireNonNull(is);
jsonImmunization = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create IMMUNIZATION
MockHttpServletResponse response = post("/Immunization").accept(FhirMediaTypes.JSON).jsonContent(jsonImmunization).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Immunization immunization = readResponse(response);
assertThat(immunization, notNullValue());
assertThat(immunization.getResourceType().toString(), equalTo("Immunization"));
assertThat(immunization.getStatus().toCode(), equalTo("completed"));
assertThat(immunization.getVaccineCode().getCodingFirstRep().getCode(), equalTo("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
assertThat(immunization.getPatient().getReferenceElement().getIdPart(), equalTo("8d703ff2-c3e2-4070-9737-73e713d5a50d"));
assertThat(immunization.getOccurrenceDateTimeType().getValueAsCalendar().getTime(), sameInstant(Date.from(ZonedDateTime.parse("2020-07-08T18:30:00.000Z").toInstant())));
assertThat(immunization.hasManufacturer(), is(true));
assertThat(immunization.getManufacturer().getDisplay(), equalTo("ACME"));
assertThat(immunization.getLotNumber(), equalTo("FOO1234"));
assertThat(immunization.getExpirationDate(), sameDay(Date.from(ZonedDateTime.parse("2022-07-31T18:30:00.000Z").toInstant())));
assertThat(immunization.getPerformer().get(0).getActor().getReferenceElement().getIdPart(), equalTo("6f763a67-2bd1-451c-93b9-95caeb36cc24"));
assertThat(immunization, validResource());
// try to get new immunization
response = get("/Immunization/" + immunization.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Immunization newImmunization = readResponse(response);
assertThat(newImmunization.getId(), equalTo(immunization.getId()));
}
use of org.hl7.fhir.dstu3.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnExistingImmunizationAsJson.
@Test
public void shouldReturnExistingImmunizationAsJson() throws Exception {
MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Immunization Immunization = readResponse(response);
assertThat(Immunization, notNullValue());
assertThat(Immunization.getIdElement().getIdPart(), equalTo(IMMUNIZATION_UUID));
assertThat(Immunization, validResource());
}
use of org.hl7.fhir.dstu3.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationFhirResourceProviderIntegrationTest method shouldUpdateExistingImmunizationAsXML.
@Test
public void shouldUpdateExistingImmunizationAsXML() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
Immunization immunization = readResponse(response);
// update the existing record
Date expirationDate = DateUtils.truncate(new Date(), Calendar.DATE);
immunization.setExpirationDate(expirationDate);
// send the update to the server
response = put("/Immunization/" + IMMUNIZATION_UUID).xmlContent(toXML(immunization)).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
// read the updated record
Immunization updatedImmunization = readResponse(response);
assertThat(updatedImmunization, notNullValue());
assertThat(updatedImmunization.getIdElement().getIdPart(), equalTo(IMMUNIZATION_UUID));
assertThat(updatedImmunization.getExpirationDate(), equalTo(expirationDate));
assertThat(immunization, validResource());
// double-check the record returned via get
response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
Immunization reReadImmunization = readResponse(response);
assertThat(reReadImmunization.getExpirationDate(), equalTo(expirationDate));
}
use of org.hl7.fhir.dstu3.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnExistingImmunizationAsXML.
@Test
public void shouldReturnExistingImmunizationAsXML() throws Exception {
MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Immunization Immunization = readResponse(response);
assertThat(Immunization, notNullValue());
assertThat(Immunization.getIdElement().getIdPart(), equalTo(IMMUNIZATION_UUID));
assertThat(Immunization, validResource());
}
Aggregations