Skip to content

Commit

Permalink
changes according to review
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Jun 30, 2023
1 parent 147f93f commit 0b7237d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public MethodOutcome updateEncounter(@IdParam IdType id, @ResourceParam Encounte
public MethodOutcome patchEncounter(@IdParam IdType id, PatchTypeEnum patchType, @ResourceParam String body,
RequestDetails requestDetails) {
if (id == null || id.getIdPart() == null) {
throw new InvalidRequestException("id must be specified to update encounter resource");
throw new InvalidRequestException("id must be specified to update Encounter resource");
}

Encounter encounter = encounterService.patch(id.getIdPart(), patchType, body, requestDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,62 +114,6 @@ public void shouldReturnExistingEncounterAsJson() throws Exception {
assertThat(encounter, validResource());
}

@Test
public void shouldPatchExistingMedicationViaJsonMergePatch() throws Exception {
String jsonEncounterPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_MERGE_PATCH_ENCOUNTER_PATH)) {
Objects.requireNonNull(is);
jsonEncounterPatch = inputStreamToString(is, UTF_8);
}

MockHttpServletResponse response = patch("/Encounter/" + ENCOUNTER_UUID).jsonMergePatch(jsonEncounterPatch)
.accept(FhirMediaTypes.JSON).go();

assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());

Encounter encounter = readResponse(response);

assertThat(encounter, notNullValue());
assertThat(encounter.getIdElement().getIdPart(), equalTo(ENCOUNTER_UUID));
assertThat(encounter, validResource());

assertThat(encounter.getPeriod(), notNullValue());
assertThat(encounter.getPeriod().hasStart(), is(true));
assertThat(encounter.getPeriod().getStart(),
sameDay(LocalDate.of(2005, 2, 1).atStartOfDay(ZoneId.ofOffset("UTC", ZoneOffset.of("+05:30")))
.withZoneSameInstant(ZoneId.systemDefault()).toLocalDate()));
}

@Test
public void shouldPatchExistingMedicationViaJsonPatch() throws Exception {
String jsonEncounterPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_ENCOUNTER_PATH)) {
Objects.requireNonNull(is);
jsonEncounterPatch = inputStreamToString(is, UTF_8);
}

MockHttpServletResponse response = patch("/Encounter/" + ENCOUNTER_UUID).jsonPatch(jsonEncounterPatch)
.accept(FhirMediaTypes.JSON).go();

assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());

Encounter encounter = readResponse(response);

assertThat(encounter, notNullValue());
assertThat(encounter.getIdElement().getIdPart(), equalTo(ENCOUNTER_UUID));
assertThat(encounter, validResource());

assertThat(encounter.getPeriod(), notNullValue());
assertThat(encounter.getPeriod().hasStart(), is(true));
assertThat(encounter.getPeriod().getStart(),
sameDay(LocalDate.of(2005, 2, 1).atStartOfDay(ZoneId.ofOffset("UTC", ZoneOffset.of("+05:30")))
.withZoneSameInstant(ZoneId.systemDefault()).toLocalDate()));
}

@Test
public void shouldReturnExistingEncounterFromOpenMrsVisitAsJson() throws Exception {
MockHttpServletResponse response = get("/Encounter/" + VISIT_UUID).accept(FhirMediaTypes.JSON).go();
Expand Down Expand Up @@ -878,6 +822,62 @@ public void shouldThrow404WhenUpdatingNonExistingVisitAsJson() throws Exception
assertThat(response.getContentAsString(), notNullValue());
}

@Test
public void shouldPatchExistingMedicationUsingJsonMergePatch() throws Exception {
String jsonEncounterPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_MERGE_PATCH_ENCOUNTER_PATH)) {
Objects.requireNonNull(is);
jsonEncounterPatch = inputStreamToString(is, UTF_8);
}

MockHttpServletResponse response = patch("/Encounter/" + ENCOUNTER_UUID).jsonMergePatch(jsonEncounterPatch)
.accept(FhirMediaTypes.JSON).go();

assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());

Encounter encounter = readResponse(response);

assertThat(encounter, notNullValue());
assertThat(encounter.getIdElement().getIdPart(), equalTo(ENCOUNTER_UUID));
assertThat(encounter, validResource());

assertThat(encounter.getPeriod(), notNullValue());
assertThat(encounter.getPeriod().hasStart(), is(true));
assertThat(encounter.getPeriod().getStart(),
sameDay(LocalDate.of(2005, 2, 1).atStartOfDay(ZoneId.ofOffset("UTC", ZoneOffset.of("+05:30")))
.withZoneSameInstant(ZoneId.systemDefault()).toLocalDate()));
}

@Test
public void shouldPatchExistingMedicationUsingJsonPatch() throws Exception {
String jsonEncounterPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_ENCOUNTER_PATH)) {
Objects.requireNonNull(is);
jsonEncounterPatch = inputStreamToString(is, UTF_8);
}

MockHttpServletResponse response = patch("/Encounter/" + ENCOUNTER_UUID).jsonPatch(jsonEncounterPatch)
.accept(FhirMediaTypes.JSON).go();

assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());

Encounter encounter = readResponse(response);

assertThat(encounter, notNullValue());
assertThat(encounter.getIdElement().getIdPart(), equalTo(ENCOUNTER_UUID));
assertThat(encounter, validResource());

assertThat(encounter.getPeriod(), notNullValue());
assertThat(encounter.getPeriod().hasStart(), is(true));
assertThat(encounter.getPeriod().getStart(),
sameDay(LocalDate.of(2005, 2, 1).atStartOfDay(ZoneId.ofOffset("UTC", ZoneOffset.of("+05:30")))
.withZoneSameInstant(ZoneId.systemDefault()).toLocalDate()));
}

@Test
public void shouldReturnEncountersWithMedicationRequestAsJson() throws Exception {

Expand Down

0 comments on commit 0b7237d

Please sign in to comment.