@Test public void testDeleteMedication() throws Exception { mockMvc.perform(delete("/clients/1/medications/2") .header("If-Match", testClient.getETag())) .andExpect(status().isOk()); mockMvc.perform(get("/clients/1/medications")) .andExpect(status().isOk()) .andExpect(jsonPath("$", hasSize(1))) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$[0].medicationName", is("Name"))); }
@DeleteMapping("/clients/{uid}/medications/{id}") public ResponseEntity deleteMedication( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { Optional<Client> client = State.getClientManager().getClientByID(uid); if (!client.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); MedicationRecord record = client.get().getMedicationRecord(id); if (record == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { DeleteMedicationRecordAction action = new DeleteMedicationRecordAction(client.get(), record, State .getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.get().getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders httpHeaders = new HttpHeaders(); return new ResponseEntity<>(httpHeaders, HttpStatus.OK); } }
ClientMedicationsController { @DeleteMapping("/clients/{uid}/medications/{id}") public ResponseEntity deleteMedication( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { Optional<Client> client = State.getClientManager().getClientByID(uid); if (!client.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); MedicationRecord record = client.get().getMedicationRecord(id); if (record == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { DeleteMedicationRecordAction action = new DeleteMedicationRecordAction(client.get(), record, State .getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.get().getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders httpHeaders = new HttpHeaders(); return new ResponseEntity<>(httpHeaders, HttpStatus.OK); } } }
ClientMedicationsController { @DeleteMapping("/clients/{uid}/medications/{id}") public ResponseEntity deleteMedication( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { Optional<Client> client = State.getClientManager().getClientByID(uid); if (!client.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); MedicationRecord record = client.get().getMedicationRecord(id); if (record == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { DeleteMedicationRecordAction action = new DeleteMedicationRecordAction(client.get(), record, State .getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.get().getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders httpHeaders = new HttpHeaders(); return new ResponseEntity<>(httpHeaders, HttpStatus.OK); } }  }
ClientMedicationsController { @DeleteMapping("/clients/{uid}/medications/{id}") public ResponseEntity deleteMedication( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { Optional<Client> client = State.getClientManager().getClientByID(uid); if (!client.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); MedicationRecord record = client.get().getMedicationRecord(id); if (record == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { DeleteMedicationRecordAction action = new DeleteMedicationRecordAction(client.get(), record, State .getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.get().getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders httpHeaders = new HttpHeaders(); return new ResponseEntity<>(httpHeaders, HttpStatus.OK); } }  @GetMapping("/clients/{uid}/medications") ResponseEntity<List<MedicationRecord>> getMedications(
            @PathVariable int uid,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{uid}/medications") ResponseEntity<List<MedicationRecord>> postMedication(
            @PathVariable int uid,
            @RequestBody CreateMedicationRecordView medicationRecordView,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @DeleteMapping("/clients/{uid}/medications/{id}") ResponseEntity deleteMedication(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{uid}/medications/{id}/start") ResponseEntity<MedicationRecord> postMedicationStart(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{uid}/medications/{id}/stop") ResponseEntity<MedicationRecord> postMedicationStop(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); }
ClientMedicationsController { @DeleteMapping("/clients/{uid}/medications/{id}") public ResponseEntity deleteMedication( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { Optional<Client> client = State.getClientManager().getClientByID(uid); if (!client.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); MedicationRecord record = client.get().getMedicationRecord(id); if (record == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { DeleteMedicationRecordAction action = new DeleteMedicationRecordAction(client.get(), record, State .getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.get().getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders httpHeaders = new HttpHeaders(); return new ResponseEntity<>(httpHeaders, HttpStatus.OK); } }  @GetMapping("/clients/{uid}/medications") ResponseEntity<List<MedicationRecord>> getMedications(
            @PathVariable int uid,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{uid}/medications") ResponseEntity<List<MedicationRecord>> postMedication(
            @PathVariable int uid,
            @RequestBody CreateMedicationRecordView medicationRecordView,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @DeleteMapping("/clients/{uid}/medications/{id}") ResponseEntity deleteMedication(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{uid}/medications/{id}/start") ResponseEntity<MedicationRecord> postMedicationStart(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{uid}/medications/{id}/stop") ResponseEntity<MedicationRecord> postMedicationStop(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken);  }