Search in sources :

Example 6 with Patient

use of io.undertree.symptom.domain.Patient in project spring-boot-jpa by ssherwood.

the class PatientControllerWebTests method test_PatientController_patchPatient_TODO.

@Test
public void test_PatientController_patchPatient_TODO() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("id", 1L);
    Patient patchPatient = new Patient();
    patchPatient.setEmail("somewhere@overtherainbow.com");
    HttpEntity<Patient> patientToUpdate = new HttpEntity<>(patchPatient);
// great the default impl doesn't appear to support PATCH...
// this appears to have been fixed in 1.4.3: https://github.com/spring-projects/spring-boot/issues/7412
// but still won't work until 1.4.4: https://github.com/spring-projects/spring-boot/issues/7742
// ResponseEntity<Patient> entity = restTemplate.exchange("/patient/{id}", HttpMethod.PATCH,
// patientToUpdate, Patient.class, params);
// assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
// assertThat(entity.getBody()).isNotNull()
// .isEqualToIgnoringGivenFields(patientToUpdate.getBody(), "id");
}
Also used : HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) Patient(io.undertree.symptom.domain.Patient) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with Patient

use of io.undertree.symptom.domain.Patient in project spring-boot-jpa by ssherwood.

the class PatientControllerWebTests method test_PatientController_addPatient_WithBirthDate_Expect_ValidAge.

@Test
public void test_PatientController_addPatient_WithBirthDate_Expect_ValidAge() throws Exception {
    ResponseEntity<Patient> entity = restTemplate.postForEntity("/patients", new TestPatientBuilder().withBirthDate(LocalDate.of(1980, 1, 1)).build(), Patient.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).isNotNull().hasFieldOrPropertyWithValue("age", LocalDate.now().getYear() - 1980);
}
Also used : TestPatientBuilder(io.undertree.symptom.domain.TestPatientBuilder) Patient(io.undertree.symptom.domain.Patient) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with Patient

use of io.undertree.symptom.domain.Patient in project spring-boot-jpa by ssherwood.

the class PatientController method updatePatientExcludingNulls.

/**
 * Applies changes to an existing resource as described by the JSON Merge Patch RFC
 * (https://tools.ietf.org/html/rfc7386).
 * <p>
 * Unlike PUT, the PATCH operation is intended apply delta changes as opposed to a complete
 * resource replacement.  Like PUT this operation verifies that a resource exists by first
 * loading it and then copies the properties from the RequestBody Map (i.e. any property that is
 * in the map -- null values can be set using this technique).
 * <p>
 * TODO needs more testing to verify that it complies with the RFC
 *
 * @param patientId  the UUID of the Patient to patch
 * @param patientMap a JSON map of properties to use as the merge patch source
 * @return the Patient as modified by the merge patch
 */
@PatchMapping("/{id}")
public Patient updatePatientExcludingNulls(@PathVariable("id") final UUID patientId, @RequestBody final Map<String, Object> patientMap) {
    Patient originalPatient = this.getPatient(patientId);
    updateProperties(patientId, originalPatient, patientMap);
    return this.patientRepository.save(originalPatient);
}
Also used : Patient(io.undertree.symptom.domain.Patient) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Example 9 with Patient

use of io.undertree.symptom.domain.Patient in project spring-boot-jpa by ssherwood.

the class PatientController method getPatientsByExample.

/**
 * Returns a "paged" collection of resources matching the input query params using default
 * matching rules for strings of "contains and ignores case".
 * <p>
 * TODO I'm not exactly happy with the resource name "queryByExample".  Need to research more what
 * other APIs look like for this kind of functionality
 *
 * @param paramMap a Map of fields to use to search with
 * @param pageable a Pageable to restrict results
 * @return A paged result of matching Patients
 */
@GetMapping("/search/by-example")
public Page<Patient> getPatientsByExample(@RequestParam Map<String, Object> paramMap, @PageableDefault(size = DEFAULT_PAGE_SZ) Pageable pageable) {
    // naively copies map entries to matching properties in the Patient POJO
    Patient examplePatient = this.jacksonObjectMapper.convertValue(paramMap, Patient.class);
    Page<Patient> pagedResults = this.patientRepository.findAll(Example.of(examplePatient, DEFAULT_MATCHER), pageable);
    if (!pagedResults.hasContent()) {
        throw new NotFoundException(Patient.RESOURCE_PATH, "No Patients found matching example query " + examplePatient);
    }
    return pagedResults;
}
Also used : Patient(io.undertree.symptom.domain.Patient) NotFoundException(io.undertree.symptom.exceptions.NotFoundException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Patient (io.undertree.symptom.domain.Patient)9 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 TestPatientBuilder (io.undertree.symptom.domain.TestPatientBuilder)3 NotFoundException (io.undertree.symptom.exceptions.NotFoundException)2 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)2 GivenName (io.undertree.symptom.domain.GivenName)1 HashMap (java.util.HashMap)1 HttpEntity (org.springframework.http.HttpEntity)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1