use of org.hl7.fhir.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationFhirResourceProviderTest method getImmunizationById_shouldReturnImmunization.
@Test
public void getImmunizationById_shouldReturnImmunization() {
IdType id = new IdType();
id.setValue(IMMUNIZATION_UUID);
when(immunizationService.get(IMMUNIZATION_UUID)).thenReturn(immunization);
Immunization result = resourceProvider.getImmunizationByUuid(id);
assertThat(result.isResource(), is(true));
assertThat(result, notNullValue());
assertThat(result.getId(), notNullValue());
assertThat(result.getId(), equalTo(IMMUNIZATION_UUID));
}
use of org.hl7.fhir.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationFhirResourceProviderTest method getImmunizationHistory_shouldReturnProvenanceResources.
@Test
public void getImmunizationHistory_shouldReturnProvenanceResources() {
IdType id = new IdType();
id.setValue(IMMUNIZATION_UUID);
when(immunizationService.get(IMMUNIZATION_UUID)).thenReturn(immunization);
List<Resource> resources = resourceProvider.getImmunizationHistoryById(id);
assertThat(resources, not(empty()));
assertThat(resources.stream().findAny().isPresent(), is(true));
assertThat(resources.stream().findAny().get().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
use of org.hl7.fhir.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationTranslatorImpl method toFhirResource.
@Override
public Immunization toFhirResource(@Nonnull Obs openmrsImmunization) {
if (openmrsImmunization == null) {
return null;
}
Immunization immunization = new Immunization();
immunization.setId(openmrsImmunization.getUuid());
immunization.setStatus(ImmunizationStatus.COMPLETED);
immunization.setPatient(patientReferenceTranslator.toFhirResource(new Patient(openmrsImmunization.getPerson())));
immunization.setEncounter(visitReferenceTranslator.toFhirResource(openmrsImmunization.getEncounter().getVisit()));
immunization.setPerformer(Collections.singletonList(new ImmunizationPerformerComponent(practitionerReferenceTranslator.toFhirResource(helper.getAdministeringProvider(openmrsImmunization)))));
Map<String, Obs> members = helper.getObsMembersMap(openmrsImmunization);
{
Obs obs = members.get(CIEL_984);
if (obs != null) {
immunization.setVaccineCode(conceptTranslator.toFhirResource(obs.getValueCoded()));
}
}
{
Obs obs = members.get(CIEL_1410);
if (obs != null) {
immunization.setOccurrence(observationValueTranslator.toFhirResource(obs));
}
}
{
Obs obs = members.get(CIEL_1418);
if (obs != null && obs.getValueNumeric() != null) {
immunization.addProtocolApplied(new ImmunizationProtocolAppliedComponent(new PositiveIntType((long) obs.getValueNumeric().doubleValue())));
}
}
{
Obs obs = members.get(CIEL_1419);
if (obs != null) {
immunization.setManufacturer(new Reference().setDisplay(obs.getValueText()));
}
}
{
Obs obs = members.get(CIEL_1420);
if (obs != null) {
immunization.setLotNumber(members.get(CIEL_1420).getValueText());
}
}
{
Obs obs = members.get(CIEL_165907);
if (obs != null) {
immunization.setExpirationDate(obs.getValueDate());
}
}
return immunization;
}
use of org.hl7.fhir.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationFhirResourceProviderIntegrationTest method shouldCreateNewImmunizationWithoutSomeOptionalMembersAsJSON.
@Test
public void shouldCreateNewImmunizationWithoutSomeOptionalMembersAsJSON() throws Exception {
// read JSON record
String jsonImmunization;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_PARTIAL_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("Pfizer"));
assertThat(immunization.getLotNumber(), equalTo("22"));
assertThat(immunization.getExpirationDate(), sameDay(LocalDate.parse("2021-07-28")));
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.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.
the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentImmunizationAsJson.
@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentImmunizationAsJson() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.JSON).go();
Immunization immunization = readResponse(response);
// update the existing record
immunization.setId(UNKNOWN_IMMUNIZATION_UUID);
// send the update to the server
response = put("/Immunization/" + UNKNOWN_IMMUNIZATION_UUID).jsonContent(toJson(immunization)).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