From e46914708175ae93632a4dc0446af8d6f00ecea4 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Mon, 30 May 2022 09:08:57 +0100 Subject: [PATCH 01/24] update works --- pom.xml | 5 ++ .../isf/accounting/rest/BillController.java | 63 ++++++++++++------- .../org/isf/admission/dto/AdmissionDTO.java | 1 - .../admission/rest/AdmissionController.java | 30 ++++----- .../isf/disease/rest/DiseaseController.java | 4 +- .../isf/lab/rest/LaboratoryController.java | 41 +++++++----- .../rest/StockMovementController.java | 54 +++++++++------- .../rest/MedicalStockWardController.java | 27 ++++---- .../java/org/isf/opd/rest/OpdController.java | 18 ++++-- .../org/isf/patvac/rest/PatVacController.java | 18 ++++-- .../isf/pricesothers/dto/PricesOthersDTO.java | 3 +- .../java/org/isf/sms/rest/SmsController.java | 15 ++++- .../org/isf/stats/rest/ReportsController.java | 14 +++-- .../accounting/rest/BillControllerTest.java | 5 +- .../rest/AdmissionControllerTest.java | 12 +++- .../disease/rest/DiseaseControllerTest.java | 4 +- 16 files changed, 194 insertions(+), 120 deletions(-) diff --git a/pom.xml b/pom.xml index 05a5adf40..e0f260898 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,11 @@ + + commons-logging + commons-logging + 1.1.1 + org.isf @@ -16,6 +16,7 @@ 2.0.0 + 1.12.0-SNAPSHOT 1.8 2.1.3 UTF-8 @@ -78,10 +79,21 @@ spring-boot-starter-test test + + junit + junit + 4.12 + test + + + org.hibernate + hibernate-validator + 7.0.4.Final + org.isf OH-core - ${oh.version} + ${oh-core.version} org.hibernate.javax.persistence @@ -96,7 +108,7 @@ org.isf OH-core - ${oh.version} + ${oh-core.version} tests test-jar test @@ -148,6 +160,16 @@ java-jwt 3.18.2 + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-test + test + diff --git a/src/main/java/org/isf/config/SecurityConfig.java b/src/main/java/org/isf/config/SecurityConfig.java index e8573d5ed..6d01c3f46 100644 --- a/src/main/java/org/isf/config/SecurityConfig.java +++ b/src/main/java/org/isf/config/SecurityConfig.java @@ -33,6 +33,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; +import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; @@ -87,6 +88,12 @@ public PasswordEncoder encoder() { return new BCryptPasswordEncoder(); } + @Bean + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); @@ -96,7 +103,7 @@ public CorsFilter corsFilter() { // config.setAllowedHeaders(Arrays.asList("Accept", "Accept-Encoding", "Accept-Language", "Authorization", "Content-Type", "Cache-Control", "Connection", "Cookie", "Host", "Pragma", "Referer, User-Agent")); config.setAllowedMethods(Arrays.asList("*")); // config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); - config.setAllowCredentials(true); + //config.setAllowCredentials(true); config.setAllowedOrigins(Arrays.asList("*")); config.setMaxAge(3600L); source.registerCorsConfiguration("/**", config); diff --git a/src/main/java/org/isf/security/LoginApi.java b/src/main/java/org/isf/security/LoginApi.java index 613aed8fc..c2cfd6c07 100644 --- a/src/main/java/org/isf/security/LoginApi.java +++ b/src/main/java/org/isf/security/LoginApi.java @@ -39,8 +39,8 @@ * * @author antonio */ -@Api("Login") -@RestController +//@Api("Login") +//@RestController public class LoginApi { /** * Implemented by Spring Security diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 129ae7dc5..32dbd8858 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,7 +4,8 @@ server.tomcat.accesslog.enabled=true server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms) spring.jpa.hibernate.use-new-id-generator-mappings=false spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl -server.context-path=/oh-api -#spring.main.allow-bean-definition-overriding=true +server.servlet.context-path=/oh-api +spring.main.allow-bean-definition-overriding=true api.host=localhost:8080 -api.protocol=http \ No newline at end of file +api.protocol=http +spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER \ No newline at end of file diff --git a/src/test/java/org/isf/accounting/rest/BillControllerTest.java b/src/test/java/org/isf/accounting/rest/BillControllerTest.java index a2b64fcb9..d76c80450 100644 --- a/src/test/java/org/isf/accounting/rest/BillControllerTest.java +++ b/src/test/java/org/isf/accounting/rest/BillControllerTest.java @@ -28,8 +28,8 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; diff --git a/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java b/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java index 014a0c6cc..b3d53ff56 100644 --- a/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java +++ b/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java @@ -22,8 +22,8 @@ package org.isf.admission.rest; import static org.hamcrest.Matchers.containsString; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; diff --git a/src/test/java/org/isf/patient/rest/PatientControllerTest.java b/src/test/java/org/isf/patient/rest/PatientControllerTest.java index 8f73c6088..cf698303e 100644 --- a/src/test/java/org/isf/patient/rest/PatientControllerTest.java +++ b/src/test/java/org/isf/patient/rest/PatientControllerTest.java @@ -28,8 +28,8 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; From 6f4fee7114faba6b2477887fb3f1b83648f34e38 Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Mon, 6 Jun 2022 08:41:13 +0100 Subject: [PATCH 03/24] improvment: Update docker environment configuration --- .env | 12 ++++++++++++ Dockerfile.backend | 22 ++++++++++++++++++++++ Dockerfile.database | 18 ++++++++++++++++++ Read Me.txt | 13 +++++++++++++ docker-compose.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 .env create mode 100644 Dockerfile.backend create mode 100644 Dockerfile.database create mode 100644 Read Me.txt create mode 100644 docker-compose.yml diff --git a/.env b/.env new file mode 100644 index 000000000..8e3c6c03b --- /dev/null +++ b/.env @@ -0,0 +1,12 @@ +MYSQL_TAG=8.0.25 +MYSQL_DATABASE=oh +MYSQL_PORT=3306 +MYSQL_ROOT_PASSWORD=root +MYSQL_USER=isf +MYSQL_PASSWORD=isf123 + +GITHUB_ORG=SteveGT96 +OH_CORE_BRANCH=staging3 +OH_API_BRANCH=staging3-upgrade-2.6.7 +API_VERSION=0.0.1 +API_PORT:8080 \ No newline at end of file diff --git a/Dockerfile.backend b/Dockerfile.backend new file mode 100644 index 000000000..d8d659221 --- /dev/null +++ b/Dockerfile.backend @@ -0,0 +1,22 @@ +FROM maven:3.8-jdk-8 + +ARG GITHUB_ORG +ARG OH_CORE_BRANCH +ARG OH_API_BRANCH +ARG OH_VERSION + +RUN mkdir /oh_web +RUN apt-get update +RUN apt-get install -y git +WORKDIR /oh_web +RUN git clone https://github.com/${GITHUB_ORG}/openhospital-core.git --depth=1 -b ${OH_CORE_BRANCH} +WORKDIR ./openhospital-core +RUN mvn clean install -DskipTests=true +WORKDIR /oh_web +RUN git clone https://github.com/${GITHUB_ORG}/openhospital-api.git --depth=1 -b ${OH_API_BRANCH} +WORKDIR ./openhospital-api +# Database connection must be changed in order to work in docker network +RUN sed -i 's/localhost/database/g' src/main/resources/database.properties +RUN mvn clean install -DskipTests=true + +CMD mvn spring-boot:run \ No newline at end of file diff --git a/Dockerfile.database b/Dockerfile.database new file mode 100644 index 000000000..95ff4ac40 --- /dev/null +++ b/Dockerfile.database @@ -0,0 +1,18 @@ +FROM mysql:5.7.9 + +ARG GITHUB_ORG +ARG OH_CORE_BRANCH + +ENV MYSQL_DATABASE=oh +ENV MYSQL_ROOT_PASSWORD=root +ENV MYSQL_USER=isf +ENV MYSQL_PASSWORD=isf123 + +RUN mkdir /oh_web +RUN apt-get update +RUN apt-get install -y git +WORKDIR /oh_web +RUN git clone https://github.com/${GITHUB_ORG}/openhospital-core.git --depth=1 -b ${OH_CORE_BRANCH} +WORKDIR ./openhospital-core + +EXPOSE 3306 \ No newline at end of file diff --git a/Read Me.txt b/Read Me.txt new file mode 100644 index 000000000..0e3c907f9 --- /dev/null +++ b/Read Me.txt @@ -0,0 +1,13 @@ +### Deploy OH2 API in docker environmenet + +1. DOCKER_BUILDKIT=0 docker-compose build [--no-cache] +2. docker-compose up + +3. docker-compose exec database /bin/bash +4. cd sql/ +5. mysql -u isf -p +9. source create_all_demo.sql; + +When done successfully, head over at http://localhost:8080/oh-api/swagger-ui.html + +You can change the deployment branch and the repository organization in the .env file. \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..e30a4df2c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +version: '3.8' +services: + database: + container_name: database + restart: always + command: --lower_case_table_names=1 + environment: + - "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" + - "MYSQL_PASSWORD=${MYSQL_PASSWORD}" + - "MYSQL_USER=${MYSQL_USER}" + - "MYSQL_DATABASE=${MYSQL_DATABASE}" + build: + context: . + dockerfile: Dockerfile.database + args: + OH_CORE_BRANCH: ${OH_CORE_BRANCH} + GITHUB_ORG: ${GITHUB_ORG} + ports: + - "${MYSQL_PORT}:3306" + backend: + container_name: backend + build: + context: . + dockerfile: Dockerfile.backend + args: + API_VERSION: ${API_VERSION} + OH_CORE_BRANCH: ${OH_CORE_BRANCH} + OH_API_BRANCH: ${OH_API_BRANCH} + GITHUB_ORG: ${GITHUB_ORG} + restart: always + ports: + - "${API_PORT}:8080" + depends_on: + - database + logging: + driver: "json-file" + options: + max-size: "100m" + max-file: "10" + From 03ad1f0f5188aa8d9ad6c53202f8dcee55c48069 Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Mon, 6 Jun 2022 08:57:48 +0100 Subject: [PATCH 04/24] refactor: Update Readme file --- README.md | 15 +++++++++++++++ Read Me.txt | 13 ------------- 2 files changed, 15 insertions(+), 13 deletions(-) delete mode 100644 Read Me.txt diff --git a/README.md b/README.md index 6a2dd3368..f1c6ebb4d 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,21 @@ For the moment, to build this project you should Service available on localhost:8080 +## How to deploy backend in docker environment + +Make sure you have docker with docker-compose installed, then run the following commands: + + - DOCKER_BUILDKIT=0 docker-compose build [--no-cache] + - docker-compose up + - docker-compose exec database /bin/bash + - cd sql/ + - mysql -u isf -p + - source create_all_demo.sql; + +When done successfully, head over at http://localhost:[API_PORT]/oh-api/swagger-ui.html + +You can change the deployment branch and the repository organization in the .env file. + ## How to contribute You can find the contribution guidelines in the [Open Hospital wiki][contribution-guide]. diff --git a/Read Me.txt b/Read Me.txt deleted file mode 100644 index 0e3c907f9..000000000 --- a/Read Me.txt +++ /dev/null @@ -1,13 +0,0 @@ -### Deploy OH2 API in docker environmenet - -1. DOCKER_BUILDKIT=0 docker-compose build [--no-cache] -2. docker-compose up - -3. docker-compose exec database /bin/bash -4. cd sql/ -5. mysql -u isf -p -9. source create_all_demo.sql; - -When done successfully, head over at http://localhost:8080/oh-api/swagger-ui.html - -You can change the deployment branch and the repository organization in the .env file. \ No newline at end of file From d2257df37a4e6bef8463d9c7a8a5a0f9acbe7de5 Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Thu, 9 Jun 2022 17:17:30 +0100 Subject: [PATCH 05/24] Fix login api --- .../java/org/isf/login/dto/LoginResponse.java | 16 ++++++++-------- src/main/java/org/isf/security/LoginApi.java | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/isf/login/dto/LoginResponse.java b/src/main/java/org/isf/login/dto/LoginResponse.java index f6faea2a2..0065651fb 100644 --- a/src/main/java/org/isf/login/dto/LoginResponse.java +++ b/src/main/java/org/isf/login/dto/LoginResponse.java @@ -5,25 +5,25 @@ public class LoginResponse { private String token; private String type = "Bearer"; private String username; - public LoginResponse(String accessToken, String username) { - this.token = accessToken; + public LoginResponse(String token, String username) { + this.token = token; this.username = username; } - public String getAccessToken() { + public String getToken() { return token; } - public void setAccessToken(String accessToken) { - this.token = accessToken; + public void setToken(String token) { + this.token = token; } - public String getTokenType() { + public String getType() { return type; } - public void setTokenType(String tokenType) { - this.type = tokenType; + public void setType(String type) { + this.type = type; } public String getUsername() { diff --git a/src/main/java/org/isf/security/LoginApi.java b/src/main/java/org/isf/security/LoginApi.java index c2cfd6c07..a417fb81d 100644 --- a/src/main/java/org/isf/security/LoginApi.java +++ b/src/main/java/org/isf/security/LoginApi.java @@ -39,15 +39,15 @@ * * @author antonio */ -//@Api("Login") -//@RestController +@Api("Login") +@RestController public class LoginApi { /** * Implemented by Spring Security */ - @ApiOperation(value = "Login", notes = "Login with the given credentials.") - @ApiResponses({@ApiResponse(code = 200, message = "", response = LoginResponse.class)}) - @PostMapping(value = "/auth/login") + //@ApiOperation(value = "Login", notes = "Login with the given credentials.") + //@ApiResponses({@ApiResponse(code = 200, message = "", response = LoginResponse.class)}) + //@PostMapping(value = "/auth/login") void login(@Valid @RequestParam String username, @RequestParam String password) { throw new IllegalStateException("Add Spring Security to handle authentication"); } From ff41729aeb649a5e087111b5320c8a65aa9ae4c4 Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Thu, 9 Jun 2022 17:46:24 +0100 Subject: [PATCH 06/24] Update newAdmissions end poind --- src/main/java/org/isf/admission/rest/AdmissionController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/isf/admission/rest/AdmissionController.java b/src/main/java/org/isf/admission/rest/AdmissionController.java index 206910718..9e83868c0 100644 --- a/src/main/java/org/isf/admission/rest/AdmissionController.java +++ b/src/main/java/org/isf/admission/rest/AdmissionController.java @@ -390,7 +390,7 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA } List diseases = null; if (newAdmissionDTO.getDiseaseIn() != null && newAdmissionDTO.getDiseaseIn().getCode() != null) { - //diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseIn().getCode()); + diseases = diseaseManager.getDiseaseAll(); List dIns = diseases.stream() .filter(d -> d.getCode()==newAdmissionDTO.getDiseaseIn().getCode()) .collect(Collectors.toList()); From 258a68ae28923717fd531ae8903ee1fd83b2ecdc Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Fri, 10 Jun 2022 16:42:59 +0100 Subject: [PATCH 07/24] change post and put methode to return and objet --- .../admission/rest/AdmissionController.java | 97 ++++++++++--------- .../admtype/rest/AdmissionTypeController.java | 8 +- .../rest/DischargeTypeController.java | 8 +- .../rest/DeliveryResultTypeController.java | 8 +- .../dlvrtype/rest/DeliveryTypeController.java | 8 +- .../org/isf/exam/rest/ExamController.java | 11 ++- .../org/isf/exam/rest/ExamRowController.java | 8 +- .../isf/exatype/rest/ExamTypeController.java | 15 +-- .../isf/hospital/rest/HospitalController.java | 6 +- .../rest/MalnutritionController.java | 8 +- .../isf/medical/rest/MedicalController.java | 16 +-- .../rest/MedStockMovementTypeController.java | 16 +-- .../medtype/rest/MedicalTypeController.java | 16 +-- .../java/org/isf/opd/rest/OpdController.java | 12 +-- .../operation/rest/OperationController.java | 17 ++-- .../opetype/rest/OperationTypeController.java | 18 ++-- .../isf/patient/rest/PatientController.java | 8 +- .../org/isf/patvac/rest/PatVacController.java | 16 +-- .../rest/PregnantTreatmentTypeController.java | 18 ++-- .../priceslist/rest/PriceListController.java | 16 +-- .../rest/PricesOthersController.java | 16 +-- .../isf/supplier/rest/SupplierController.java | 16 +-- .../isf/vaccine/rest/VaccineController.java | 18 ++-- .../vactype/rest/VaccineTypeController.java | 16 +-- .../org/isf/visits/rest/VisitsController.java | 4 +- .../org/isf/ward/rest/WardController.java | 8 +- 26 files changed, 204 insertions(+), 204 deletions(-) diff --git a/src/main/java/org/isf/admission/rest/AdmissionController.java b/src/main/java/org/isf/admission/rest/AdmissionController.java index 9e83868c0..10f88fb0c 100644 --- a/src/main/java/org/isf/admission/rest/AdmissionController.java +++ b/src/main/java/org/isf/admission/rest/AdmissionController.java @@ -21,6 +21,7 @@ */ package org.isf.admission.rest; +import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; @@ -144,10 +145,10 @@ public AdmissionController(AdmissionBrowserManager admissionManager, PatientBrow * @return the {@link Admission} found or NO_CONTENT otherwise. * @throws OHServiceException */ - @GetMapping(value = "/admissions/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getAdmissions(@PathVariable int id) throws OHServiceException { - LOGGER.info("Get admission by id: {}", id); - Admission admission = admissionManager.getAdmission(id); + @GetMapping(value = "/admissions/{patientCode}", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity getAdmissions(@PathVariable int patientCode) throws OHServiceException { + LOGGER.info("Get admission by id: {}", patientCode); + Admission admission = admissionManager.getAdmission(patientCode); if (admission == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } @@ -164,7 +165,7 @@ public ResponseEntity getAdmissions(@PathVariable int id) throws O * @throws OHServiceException */ @GetMapping(value = "/admissions/current", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getCurrentAdmission(@RequestParam("patientcode") Integer patientCode) + public ResponseEntity getCurrentAdmission(@RequestParam("patientCode") int patientCode) throws OHServiceException { LOGGER.info("Get admission by patient code: {}", patientCode); Patient patient = patientManager.getPatientById(patientCode); @@ -225,7 +226,7 @@ public ResponseEntity> getAdmittedPatients( * @throws OHServiceException */ @GetMapping(value = "/admissions", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getPatientAdmissions(@RequestParam("patientcode") Integer patientCode) + public ResponseEntity> getPatientAdmissions(@RequestParam("patientCode") int patientCode) throws OHServiceException { LOGGER.info("Get patient admissions by patient code: {}", patientCode); Patient patient = patientManager.getPatientById(patientCode); @@ -307,10 +308,10 @@ public ResponseEntity dischargePatient(@RequestParam("patientCode") int LOGGER.info("discharge the patient"); Patient patient = patientManager.getPatientById(patientCode); - Boolean bol = false; + boolean bol = false; if (patient == null) - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(bol); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); Admission admission = admissionManager.getCurrentAdmission(patient); @@ -318,9 +319,9 @@ public ResponseEntity dischargePatient(@RequestParam("patientCode") int return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); Admission adm = admissionMapper.map2Model(currentAdmissionDTO); - + adm.setAdmDate(currentAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); if (adm == null || admission.getId() != adm.getId()) - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(bol); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); if (adm.getDiseaseOut1() == null) { throw new OHAPIException( @@ -335,8 +336,11 @@ public ResponseEntity dischargePatient(@RequestParam("patientCode") int OHSeverityLevel.ERROR)); } adm.setAdmitted(0); - bol = admissionManager.updateAdmission(adm); - + if(admissionManager.updateAdmission(adm)!= null) { + + bol = true; + } + return ResponseEntity.status(HttpStatus.OK).body(bol); } @@ -351,6 +355,7 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA throws OHServiceException { Admission newAdmission = admissionMapper.map2Model(newAdmissionDTO); + newAdmission.setAdmDate(newAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); if (newAdmissionDTO.getWard() != null && newAdmissionDTO.getWard().getCode() != null && !newAdmissionDTO.getWard().getCode().trim().isEmpty()) { @@ -388,49 +393,39 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA } else { throw new OHAPIException(new OHExceptionMessage(null, "Patient field is required!", OHSeverityLevel.ERROR)); } - List diseases = null; + Disease diseases = null; if (newAdmissionDTO.getDiseaseIn() != null && newAdmissionDTO.getDiseaseIn().getCode() != null) { - diseases = diseaseManager.getDiseaseAll(); - List dIns = diseases.stream() - .filter(d -> d.getCode()==newAdmissionDTO.getDiseaseIn().getCode()) - .collect(Collectors.toList()); - if (dIns.isEmpty()) { + diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseIn().getCode()); + + if (diseases == null) { throw new OHAPIException(new OHExceptionMessage(null, "Disease in not found!", OHSeverityLevel.ERROR)); } - newAdmission.setDiseaseIn(dIns.get(0)); + newAdmission.setDiseaseIn(diseases); } if (newAdmissionDTO.getDiseaseOut1() != null && newAdmissionDTO.getDiseaseOut1().getCode() != null) { - if (diseases == null) diseases = diseaseManager.getDisease(); - List dOut1s = diseases.stream() - .filter(d -> d.getCode().equals(newAdmissionDTO.getDiseaseOut1().getCode())) - .collect(Collectors.toList()); - if (dOut1s.isEmpty()) { + if (diseases == null) diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseOut1().getCode()); + + if (diseases == null) { throw new OHAPIException(new OHExceptionMessage(null, "Disease out 1 not found!", OHSeverityLevel.ERROR)); } - newAdmission.setDiseaseOut1(dOut1s.get(0)); + newAdmission.setDiseaseOut1(diseases); } if (newAdmissionDTO.getDiseaseOut2() != null && newAdmissionDTO.getDiseaseOut2().getCode() != null) { - if (diseases == null) diseases = diseaseManager.getDisease(); - List dOut2s = diseases.stream() - .filter(d -> d.getCode().equals(newAdmissionDTO.getDiseaseOut2().getCode())) - .collect(Collectors.toList()); - if (dOut2s.isEmpty()) { + if (diseases == null) diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseOut2().getCode()); + if (diseases == null) { throw new OHAPIException(new OHExceptionMessage(null, "Disease out 2 not found!", OHSeverityLevel.ERROR)); } - newAdmission.setDiseaseOut2(dOut2s.get(0)); + newAdmission.setDiseaseOut2(diseases); } if (newAdmissionDTO.getDiseaseOut3() != null && newAdmissionDTO.getDiseaseOut3().getCode() != null) { - if (diseases == null) diseases = diseaseManager.getDisease(); - List dOut3s = diseases.stream() - .filter(d -> d.getCode().equals(newAdmissionDTO.getDiseaseOut3().getCode())) - .collect(Collectors.toList()); - if (dOut3s.isEmpty()) { + if (diseases == null) diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseOut3().getCode()); + if (diseases == null) { throw new OHAPIException(new OHExceptionMessage(null, "Disease out 3 not found!", OHSeverityLevel.ERROR)); } - newAdmission.setDiseaseOut3(dOut3s.get(0)); + newAdmission.setDiseaseOut3(diseases); } if (newAdmissionDTO.getOperation() != null && newAdmissionDTO.getOperation().getCode() != null && !newAdmissionDTO.getOperation().getCode().trim().isEmpty()) { @@ -496,13 +491,15 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA ? newAdmission.getPatient().getFirstName() + " " + newAdmission.getPatient().getSecondName() : newAdmission.getPatient().getName(); LOGGER.info("Create admission for patient {}", name); - int aId = admissionManager.newAdmissionReturnKey(newAdmission); - if (aId > 0) { - System.out.println(aId); - Admission ad = admissionManager.getAdmission(aId); - return ResponseEntity.status(HttpStatus.CREATED).body(admissionMapper.map2DTO(ad)); + Admission ad = admissionManager.newAdmission(newAdmission); + if (ad == null) { + throw new OHAPIException(new OHExceptionMessage(null, "Admission is not created!", OHSeverityLevel.ERROR)); } - throw new OHAPIException(new OHExceptionMessage(null, "Admission is not created!", OHSeverityLevel.ERROR)); + AdmissionDTO admDTO = admissionMapper.map2DTO(ad); + Instant instant = ad.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = Date.from(instant); + admDTO.setAdmDate(date); + return ResponseEntity.status(HttpStatus.CREATED).body(admDTO); } /** @@ -664,11 +661,17 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmis ? updAdmission.getPatient().getFirstName() + " " + updAdmission.getPatient().getSecondName() : updAdmission.getPatient().getName(); LOGGER.info("update admission for patient {}", name); - boolean isUpdated = admissionManager.updateAdmission(updAdmission); - if (isUpdated) { - return ResponseEntity.ok(admissionMapper.map2DTO(updAdmission)); + Admission isUpdated = admissionManager.updateAdmission(updAdmission); + + if (isUpdated == null) { + throw new OHAPIException(new OHExceptionMessage(null, "Admission is not updated!", OHSeverityLevel.ERROR)); } - throw new OHAPIException(new OHExceptionMessage(null, "Admission is not updated!", OHSeverityLevel.ERROR)); + + AdmissionDTO admDTO= admissionMapper.map2DTO(isUpdated); + Instant instant = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = Date.from(instant); + admDTO.setAdmDate(date); + return ResponseEntity.ok(admDTO); } diff --git a/src/main/java/org/isf/admtype/rest/AdmissionTypeController.java b/src/main/java/org/isf/admtype/rest/AdmissionTypeController.java index 16a6ad2f8..5ac327e9c 100644 --- a/src/main/java/org/isf/admtype/rest/AdmissionTypeController.java +++ b/src/main/java/org/isf/admtype/rest/AdmissionTypeController.java @@ -71,7 +71,7 @@ public AdmissionTypeController(AdmissionTypeBrowserManager admtManager, Admissio * @throws OHServiceException */ @PostMapping(value = "/admissiontypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newAdmissionType(@RequestBody AdmissionTypeDTO admissionTypeDTO) throws OHServiceException { + ResponseEntity newAdmissionType(@RequestBody AdmissionTypeDTO admissionTypeDTO) throws OHServiceException { String code = admissionTypeDTO.getCode(); LOGGER.info("Create Admission Type {}", code); boolean isCreated = admtManager.newAdmissionType(mapper.map2Model(admissionTypeDTO)); @@ -86,7 +86,7 @@ ResponseEntity newAdmissionType(@RequestBody AdmissionTypeDTO admissionT new OHExceptionMessage(null, "Admission Type is not created!", OHSeverityLevel.ERROR), HttpStatus.INTERNAL_SERVER_ERROR); } - return ResponseEntity.status(HttpStatus.CREATED).body(admtCreated.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(admtCreated)); } /** @@ -96,7 +96,7 @@ ResponseEntity newAdmissionType(@RequestBody AdmissionTypeDTO admissionT * @throws OHServiceException */ @PutMapping(value = "/admissiontypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updateAdmissionTypet(@RequestBody AdmissionTypeDTO admissionTypeDTO) + ResponseEntity updateAdmissionTypet(@RequestBody AdmissionTypeDTO admissionTypeDTO) throws OHServiceException { LOGGER.info("Update admissiontypes code: {}", admissionTypeDTO.getCode()); AdmissionType admt = mapper.map2Model(admissionTypeDTO); @@ -107,7 +107,7 @@ ResponseEntity updateAdmissionTypet(@RequestBody AdmissionTypeDTO admiss throw new OHAPIException( new OHExceptionMessage(null, "Admission Type is not updated!", OHSeverityLevel.ERROR), HttpStatus.INTERNAL_SERVER_ERROR); - return ResponseEntity.ok(admt.getCode()); + return ResponseEntity.ok(mapper.map2DTO(admt)); } /** diff --git a/src/main/java/org/isf/disctype/rest/DischargeTypeController.java b/src/main/java/org/isf/disctype/rest/DischargeTypeController.java index 3e170da89..1ae4f4574 100644 --- a/src/main/java/org/isf/disctype/rest/DischargeTypeController.java +++ b/src/main/java/org/isf/disctype/rest/DischargeTypeController.java @@ -71,7 +71,7 @@ public DischargeTypeController(DischargeTypeBrowserManager discTypeManager, Disc * @throws OHServiceException */ @PostMapping(value = "/dischargetypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newDischargeType(@RequestBody DischargeTypeDTO dischTypeDTO) throws OHServiceException { + ResponseEntity newDischargeType(@RequestBody DischargeTypeDTO dischTypeDTO) throws OHServiceException { String code = dischTypeDTO.getCode(); LOGGER.info("Create discharge type {}", code); boolean isCreated = discTypeManager.newDischargeType(mapper.map2Model(dischTypeDTO)); @@ -85,7 +85,7 @@ ResponseEntity newDischargeType(@RequestBody DischargeTypeDTO dischTypeD throw new OHAPIException( new OHExceptionMessage(null, "discharge type is not created!", OHSeverityLevel.ERROR), HttpStatus.INTERNAL_SERVER_ERROR); } - return ResponseEntity.status(HttpStatus.CREATED).body(dischTypeCreated.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(dischTypeCreated)); } /** @@ -95,7 +95,7 @@ ResponseEntity newDischargeType(@RequestBody DischargeTypeDTO dischTypeD * @throws OHServiceException */ @PutMapping(value = "/dischargetypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updateDischargeTypet(@RequestBody DischargeTypeDTO dischTypeDTO) throws OHServiceException { + ResponseEntity updateDischargeTypet(@RequestBody DischargeTypeDTO dischTypeDTO) throws OHServiceException { LOGGER.info("Update dischargetypes code: {}", dischTypeDTO.getCode()); DischargeType dischType = mapper.map2Model(dischTypeDTO); if (!discTypeManager.isCodePresent(dischTypeDTO.getCode())) @@ -105,7 +105,7 @@ ResponseEntity updateDischargeTypet(@RequestBody DischargeTypeDTO dischT if (!isUpdated) throw new OHAPIException( new OHExceptionMessage(null, "discharge type is not updated!", OHSeverityLevel.ERROR), HttpStatus.INTERNAL_SERVER_ERROR); - return ResponseEntity.ok(dischType.getCode()); + return ResponseEntity.ok(mapper.map2DTO(dischType)); } /** diff --git a/src/main/java/org/isf/dlvrrestype/rest/DeliveryResultTypeController.java b/src/main/java/org/isf/dlvrrestype/rest/DeliveryResultTypeController.java index f3aead7a2..defa5a8d3 100644 --- a/src/main/java/org/isf/dlvrrestype/rest/DeliveryResultTypeController.java +++ b/src/main/java/org/isf/dlvrrestype/rest/DeliveryResultTypeController.java @@ -71,7 +71,7 @@ public DeliveryResultTypeController(DeliveryResultTypeBrowserManager dlvrrestMan * @throws OHServiceException */ @PostMapping(value = "/deliveryresulttypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newDeliveryResultType(@RequestBody DeliveryResultTypeDTO dlvrrestTypeDTO) + ResponseEntity newDeliveryResultType(@RequestBody DeliveryResultTypeDTO dlvrrestTypeDTO) throws OHServiceException { String code = dlvrrestTypeDTO.getCode(); LOGGER.info("Create Delivery result type {}", code); @@ -88,7 +88,7 @@ ResponseEntity newDeliveryResultType(@RequestBody DeliveryResultTypeDTO new OHExceptionMessage(null, "Delivery result type is not created!", OHSeverityLevel.ERROR), HttpStatus.INTERNAL_SERVER_ERROR); } - return ResponseEntity.status(HttpStatus.CREATED).body(dlvrrestTypeCreated.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(dlvrrestTypeCreated)); } /** @@ -98,7 +98,7 @@ ResponseEntity newDeliveryResultType(@RequestBody DeliveryResultTypeDTO * @throws OHServiceException */ @PutMapping(value = "/deliveryresulttypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updateDeliveryResultTypet(@RequestBody DeliveryResultTypeDTO dlvrrestTypeDTO) + ResponseEntity updateDeliveryResultTypet(@RequestBody DeliveryResultTypeDTO dlvrrestTypeDTO) throws OHServiceException { LOGGER.info("Update deliveryresulttypes code: {}", dlvrrestTypeDTO.getCode()); DeliveryResultType dlvrrestType = mapper.map2Model(dlvrrestTypeDTO); @@ -110,7 +110,7 @@ ResponseEntity updateDeliveryResultTypet(@RequestBody DeliveryResultType throw new OHAPIException( new OHExceptionMessage(null, "Delivery result type is not updated!", OHSeverityLevel.ERROR), HttpStatus.INTERNAL_SERVER_ERROR); - return ResponseEntity.ok(dlvrrestType.getCode()); + return ResponseEntity.ok(mapper.map2DTO(dlvrrestType)); } /** diff --git a/src/main/java/org/isf/dlvrtype/rest/DeliveryTypeController.java b/src/main/java/org/isf/dlvrtype/rest/DeliveryTypeController.java index ad2dc20ea..ee90affa7 100644 --- a/src/main/java/org/isf/dlvrtype/rest/DeliveryTypeController.java +++ b/src/main/java/org/isf/dlvrtype/rest/DeliveryTypeController.java @@ -71,7 +71,7 @@ public DeliveryTypeController(DeliveryTypeBrowserManager dlvrtypeManager, Delive * @throws OHServiceException */ @PostMapping(value = "/deliverytypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newDeliveryType(@RequestBody DeliveryTypeDTO dlvrTypeDTO) throws OHServiceException { + ResponseEntity newDeliveryType(@RequestBody DeliveryTypeDTO dlvrTypeDTO) throws OHServiceException { String code = dlvrTypeDTO.getCode(); LOGGER.info("Create Delivery type {}", code); boolean isCreated = dlvrtypeManager.newDeliveryType(deliveryTypeMapper.map2Model(dlvrTypeDTO)); @@ -85,7 +85,7 @@ ResponseEntity newDeliveryType(@RequestBody DeliveryTypeDTO dlvrTypeDTO) throw new OHAPIException( new OHExceptionMessage(null, "Delivery type is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(dlvrTypeCreated.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(deliveryTypeMapper.map2DTO(dlvrTypeCreated)); } /** @@ -95,7 +95,7 @@ ResponseEntity newDeliveryType(@RequestBody DeliveryTypeDTO dlvrTypeDTO) * @throws OHServiceException */ @PutMapping(value = "/deliverytypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updateDeliveryTypet(@RequestBody DeliveryTypeDTO dlvrTypeDTO) throws OHServiceException { + ResponseEntity updateDeliveryTypet(@RequestBody DeliveryTypeDTO dlvrTypeDTO) throws OHServiceException { LOGGER.info("Update deliverytypes code: {}", dlvrTypeDTO.getCode()); DeliveryType dlvrType = deliveryTypeMapper.map2Model(dlvrTypeDTO); if (!dlvrtypeManager.isCodePresent(dlvrType.getCode())) @@ -105,7 +105,7 @@ ResponseEntity updateDeliveryTypet(@RequestBody DeliveryTypeDTO dlvrType if (!isUpdated) throw new OHAPIException( new OHExceptionMessage(null, "Delivery type is not updated!", OHSeverityLevel.ERROR)); - return ResponseEntity.ok(dlvrType.getCode()); + return ResponseEntity.ok(deliveryTypeMapper.map2DTO(dlvrType)); } /** diff --git a/src/main/java/org/isf/exam/rest/ExamController.java b/src/main/java/org/isf/exam/rest/ExamController.java index 8c1387953..e5e095e8b 100644 --- a/src/main/java/org/isf/exam/rest/ExamController.java +++ b/src/main/java/org/isf/exam/rest/ExamController.java @@ -70,7 +70,7 @@ public ExamController(ExamBrowsingManager examManager, ExamMapper examMapper) { } @PostMapping(value = "/exams", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newExam(@RequestBody ExamDTO newExam) throws OHServiceException { + public ResponseEntity newExam(@RequestBody ExamDTO newExam) throws OHServiceException { ExamType examType = examTypeBrowserManager.getExamType().stream().filter(et -> newExam.getExamtype().getCode().equals(et.getCode())).findFirst().orElse(null); if (examType == null) { @@ -84,11 +84,11 @@ public ResponseEntity newExam(@RequestBody ExamDTO newExam) throws OHServiceExce if (!isCreated) { throw new OHAPIException(new OHExceptionMessage(null, "Exam is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.ok(exam.getCode()); + return ResponseEntity.ok(examMapper.map2DTO(exam)); } @PutMapping(value = "/exams/{code:.+}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateExams(@PathVariable String code, @RequestBody ExamDTO updateExam) throws OHServiceException { + public ResponseEntity updateExams(@PathVariable String code, @RequestBody ExamDTO updateExam) throws OHServiceException { if (!updateExam.getCode().equals(code)) { throw new OHAPIException(new OHExceptionMessage(null, "Exam code mismatch", OHSeverityLevel.ERROR)); @@ -105,11 +105,12 @@ public ResponseEntity updateExams(@PathVariable String code, @RequestBody ExamDT Exam exam = examMapper.map2Model(updateExam); exam.setExamtype(examType); exam.setLock(0); - if (!examManager.updateExam(exam)) { + Exam ex = examManager.updateExam(exam); + if (ex == null) { throw new OHAPIException(new OHExceptionMessage(null, "Exam is not updated!", OHSeverityLevel.ERROR)); } - return ResponseEntity.ok(true); + return ResponseEntity.ok(examMapper.map2DTO(ex)); } diff --git a/src/main/java/org/isf/exam/rest/ExamRowController.java b/src/main/java/org/isf/exam/rest/ExamRowController.java index 1047fa9e0..d398700d4 100644 --- a/src/main/java/org/isf/exam/rest/ExamRowController.java +++ b/src/main/java/org/isf/exam/rest/ExamRowController.java @@ -71,7 +71,7 @@ public ExamRowController(ExamBrowsingManager examManager, ExamRowBrowsingManager } @PostMapping(value = "/examrows", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newExamRow(@RequestBody ExamRowDTO examRowDTO) throws OHServiceException { + public ResponseEntity newExamRow(@RequestBody ExamRowDTO examRowDTO) throws OHServiceException { Exam exam = examManager.getExams().stream().filter(e -> examRowDTO.getExam().getCode().equals(e.getCode())).findFirst().orElse(null); if (exam == null) { @@ -81,11 +81,11 @@ public ResponseEntity newExamRow(@RequestBody ExamRowDTO examRowDTO) throws OHSe ExamRow examRow = examRowMapper.map2Model(examRowDTO); examRow.setExamCode(exam); - boolean isCreated = examRowBrowsingManager.newExamRow(examRow); - if (!isCreated) { + ExamRow isCreated = examRowBrowsingManager.newExamRow(examRow); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "ExamRow is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(true); + return ResponseEntity.status(HttpStatus.CREATED).body(examRowMapper.map2DTO(isCreated)); } @GetMapping(value = "/examrows", produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/src/main/java/org/isf/exatype/rest/ExamTypeController.java b/src/main/java/org/isf/exatype/rest/ExamTypeController.java index bc8e600d1..a8eafec99 100644 --- a/src/main/java/org/isf/exatype/rest/ExamTypeController.java +++ b/src/main/java/org/isf/exatype/rest/ExamTypeController.java @@ -65,20 +65,20 @@ public ExamTypeController(ExamTypeBrowserManager examTypeBrowserManager, ExamTyp } @PostMapping(value = "/examtypes", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newExamType(@RequestBody ExamTypeDTO newExamType) throws OHServiceException { + public ResponseEntity newExamType(@RequestBody ExamTypeDTO newExamType) throws OHServiceException { ExamType examType = examTypeMapper.map2Model(newExamType); - boolean created = examTypeBrowserManager.newExamType(examType); + ExamType created = examTypeBrowserManager.newExamType(examType); - if (!created) { + if (created == null) { throw new OHAPIException(new OHExceptionMessage(null, "ExamType type not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(true); + return ResponseEntity.status(HttpStatus.CREATED).body(examTypeMapper.map2DTO(created)); } @PutMapping(value = "/examtypes/{code:.+}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateExamType(@PathVariable String code, @RequestBody ExamTypeDTO updateExamType) throws OHServiceException { + public ResponseEntity updateExamType(@PathVariable String code, @RequestBody ExamTypeDTO updateExamType) throws OHServiceException { if (!updateExamType.getCode().equals(code)) { throw new OHAPIException(new OHExceptionMessage(null, "ExamType code mismatch", OHSeverityLevel.ERROR)); @@ -88,11 +88,12 @@ public ResponseEntity updateExamType(@PathVariable String code, @RequestBody Exa } ExamType examType = examTypeMapper.map2Model(updateExamType); - if (!examTypeBrowserManager.updateExamType(examType)) { + ExamType exType = examTypeBrowserManager.updateExamType(examType); + if (exType == null) { throw new OHAPIException(new OHExceptionMessage(null, "ExamType is not updated!", OHSeverityLevel.ERROR)); } - return ResponseEntity.ok(true); + return ResponseEntity.ok(examTypeMapper.map2DTO(exType)); } diff --git a/src/main/java/org/isf/hospital/rest/HospitalController.java b/src/main/java/org/isf/hospital/rest/HospitalController.java index a1ca89c93..7ec32b99b 100644 --- a/src/main/java/org/isf/hospital/rest/HospitalController.java +++ b/src/main/java/org/isf/hospital/rest/HospitalController.java @@ -60,7 +60,7 @@ public HospitalController(HospitalBrowsingManager hospitalBrowsingManager, Hospi } @PutMapping(value = "/hospitals/{code:.+}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateHospital(@PathVariable String code, @RequestBody HospitalDTO hospitalDTO) throws OHServiceException { + public ResponseEntity updateHospital(@PathVariable String code, @RequestBody HospitalDTO hospitalDTO) throws OHServiceException { if (!hospitalDTO.getCode().equals(code)) { throw new OHAPIException(new OHExceptionMessage(null, "Hospital code mismatch", OHSeverityLevel.ERROR)); @@ -71,9 +71,9 @@ public ResponseEntity updateHospital(@PathVariable String code, @RequestBody Hos Hospital hospital = hospitalMapper.map2Model(hospitalDTO); hospital.setLock(0); - hospitalBrowsingManager.updateHospital(hospital); + Hospital hospi = hospitalBrowsingManager.updateHospital(hospital); - return ResponseEntity.ok(true); + return ResponseEntity.ok(hospitalMapper.map2DTO(hospi)); } @GetMapping(value = "/hospitals", produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/src/main/java/org/isf/malnutrition/rest/MalnutritionController.java b/src/main/java/org/isf/malnutrition/rest/MalnutritionController.java index c0868304a..5900ce3fa 100644 --- a/src/main/java/org/isf/malnutrition/rest/MalnutritionController.java +++ b/src/main/java/org/isf/malnutrition/rest/MalnutritionController.java @@ -69,15 +69,15 @@ public class MalnutritionController { * @throws OHServiceException */ @PostMapping(value = "/malnutritions", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newMalnutrition(@RequestBody @Valid MalnutritionDTO malnutritionDTO) throws OHServiceException{ + public ResponseEntity newMalnutrition(@RequestBody @Valid MalnutritionDTO malnutritionDTO) throws OHServiceException{ LOGGER.info("Creating a new malnutrition ..."); - boolean isCreated = manager.newMalnutrition(mapper.map2Model(malnutritionDTO)); - if (!isCreated) { + Malnutrition isCreated = manager.newMalnutrition(mapper.map2Model(malnutritionDTO)); + if (isCreated == null) { LOGGER.info("Malnutrition is not created!"); throw new OHAPIException(new OHExceptionMessage(null, "Malnutrition is not created!", OHSeverityLevel.ERROR)); } LOGGER.info("Malnutrition successfully created!"); - return ResponseEntity.status(HttpStatus.CREATED).body(null); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** diff --git a/src/main/java/org/isf/medical/rest/MedicalController.java b/src/main/java/org/isf/medical/rest/MedicalController.java index bd416c0ef..d8c5ec7c9 100644 --- a/src/main/java/org/isf/medical/rest/MedicalController.java +++ b/src/main/java/org/isf/medical/rest/MedicalController.java @@ -167,17 +167,17 @@ else if(nameSorted){ * @throws OHServiceException */ @PostMapping(value = "/medicals", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newMedical( + public ResponseEntity newMedical( @RequestBody MedicalDTO medicalDTO, @RequestParam(name="ignore_similar", defaultValue="false") boolean ignoreSimilar) throws OHServiceException { LOGGER.info("Creating a new medical ..."); - boolean isCreated = medicalManager.newMedical(mapper.map2Model(medicalDTO), ignoreSimilar); - if (!isCreated) { + Medical isCreated = medicalManager.newMedical(mapper.map2Model(medicalDTO), ignoreSimilar); + if (isCreated == null) { LOGGER.info("Medical is not created!"); throw new OHAPIException(new OHExceptionMessage(null, "Medical is not created!", OHSeverityLevel.ERROR)); } LOGGER.info("Medical successfully created!"); - return ResponseEntity.status(HttpStatus.CREATED).body(null); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -188,17 +188,17 @@ public ResponseEntity newMedical( * @throws OHServiceException */ @PutMapping(value = "/medicals", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateMedical( + public ResponseEntity updateMedical( @RequestBody @Valid MedicalDTO medicalDTO, @RequestParam(name="ignore_similar", defaultValue="false") boolean ignoreSimilar) throws OHServiceException { LOGGER.info("Updating a medical ..."); - boolean isUpdated = medicalManager.updateMedical(mapper.map2Model(medicalDTO), ignoreSimilar); - if (!isUpdated) { + Medical isUpdated = medicalManager.updateMedical(mapper.map2Model(medicalDTO), ignoreSimilar); + if (isUpdated == null) { LOGGER.info("Medical is not updated!"); throw new OHAPIException(new OHExceptionMessage(null, "Medical is not updated!", OHSeverityLevel.ERROR)); } LOGGER.info("Medical successfully updated!"); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.status(HttpStatus.OK).body(mapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/medstockmovtype/rest/MedStockMovementTypeController.java b/src/main/java/org/isf/medstockmovtype/rest/MedStockMovementTypeController.java index a202f8aa2..a0058bc88 100644 --- a/src/main/java/org/isf/medstockmovtype/rest/MedStockMovementTypeController.java +++ b/src/main/java/org/isf/medstockmovtype/rest/MedStockMovementTypeController.java @@ -103,12 +103,12 @@ public ResponseEntity getMovementType(@PathVariable("code") Str * @throws OHServiceException */ @PostMapping(value = "/medstockmovementtype", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newMedicaldsrstockmovType(@RequestBody @Valid MovementTypeDTO medicaldsrstockmovType) throws OHServiceException { - boolean isCreated = manager.newMedicaldsrstockmovType(mapper.map2Model(medicaldsrstockmovType)); - if (!isCreated) { + public ResponseEntity newMedicaldsrstockmovType(@RequestBody @Valid MovementTypeDTO medicaldsrstockmovType) throws OHServiceException { + MovementType isCreated = manager.newMedicaldsrstockmovType(mapper.map2Model(medicaldsrstockmovType)); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Movement type is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(null); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -118,15 +118,15 @@ public ResponseEntity newMedicaldsrstockmovType(@RequestBody @Valid Moveme * @throws OHServiceException */ @PutMapping(value = "/medstockmovementtype", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateMedicaldsrstockmovType(@RequestBody @Valid MovementTypeDTO medicaldsrstockmovTypeDTO) throws OHServiceException { + public ResponseEntity updateMedicaldsrstockmovType(@RequestBody @Valid MovementTypeDTO medicaldsrstockmovTypeDTO) throws OHServiceException { MovementType medicaldsrstockmovType = mapper.map2Model(medicaldsrstockmovTypeDTO); if (!manager.isCodePresent(medicaldsrstockmovType.getCode())) throw new OHAPIException(new OHExceptionMessage(null, "Movement type not found!", OHSeverityLevel.ERROR)); - boolean isUpdated = manager.updateMedicaldsrstockmovType(medicaldsrstockmovType); - if (!isUpdated) { + MovementType isUpdated = manager.updateMedicaldsrstockmovType(medicaldsrstockmovType); + if (isUpdated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Movement type is not updated!", OHSeverityLevel.ERROR)); } - return ResponseEntity.ok(null); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/medtype/rest/MedicalTypeController.java b/src/main/java/org/isf/medtype/rest/MedicalTypeController.java index 8106571ea..0cebf469a 100644 --- a/src/main/java/org/isf/medtype/rest/MedicalTypeController.java +++ b/src/main/java/org/isf/medtype/rest/MedicalTypeController.java @@ -87,12 +87,12 @@ public ResponseEntity> getMedicalTypes() throws OHServiceEx * @throws OHServiceException */ @PostMapping(value = "/medicaltypes", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity createMedicalType(@RequestBody @Valid MedicalTypeDTO medicalTypeDTO) throws OHServiceException { - boolean isCreated = medicalTypeBrowserManager.newMedicalType(medicalTypeMapper.map2Model(medicalTypeDTO)); - if (!isCreated) { + public ResponseEntity createMedicalType(@RequestBody @Valid MedicalTypeDTO medicalTypeDTO) throws OHServiceException { + MedicalType isCreated = medicalTypeBrowserManager.newMedicalType(medicalTypeMapper.map2Model(medicalTypeDTO)); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Medical type is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(null); + return ResponseEntity.status(HttpStatus.CREATED).body(medicalTypeMapper.map2DTO(isCreated)); } /** @@ -102,15 +102,15 @@ public ResponseEntity createMedicalType(@RequestBody @Valid MedicalTypeDTO * @throws OHServiceException */ @PutMapping(value = "/medicaltypes", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateMedicalType(@RequestBody @Valid MedicalTypeDTO medicalTypeDTO) throws OHServiceException { + public ResponseEntity updateMedicalType(@RequestBody @Valid MedicalTypeDTO medicalTypeDTO) throws OHServiceException { MedicalType medicalType = medicalTypeMapper.map2Model(medicalTypeDTO); if (!medicalTypeBrowserManager.isCodePresent(medicalType.getCode())) throw new OHAPIException(new OHExceptionMessage(null, "Medical type not found!", OHSeverityLevel.ERROR)); - boolean isUpdated = medicalTypeBrowserManager.updateMedicalType(medicalType); - if (!isUpdated) { + MedicalType isUpdated = medicalTypeBrowserManager.updateMedicalType(medicalType); + if (isUpdated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Medical type is not updated!", OHSeverityLevel.ERROR)); } - return ResponseEntity.ok(null); + return ResponseEntity.ok(medicalTypeMapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/opd/rest/OpdController.java b/src/main/java/org/isf/opd/rest/OpdController.java index 4e9e526d9..d4c7e7308 100644 --- a/src/main/java/org/isf/opd/rest/OpdController.java +++ b/src/main/java/org/isf/opd/rest/OpdController.java @@ -85,7 +85,7 @@ public OpdController(OpdBrowserManager opdManager, OpdMapper opdmapper) { * @throws OHServiceException */ @PostMapping(value = "/opds", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newOpd(@RequestBody OpdDTO opdDTO) throws OHServiceException { + ResponseEntity newOpd(@RequestBody OpdDTO opdDTO) throws OHServiceException { int code = opdDTO.getCode(); LOGGER.info("store Out patient {}", code); Patient patient = patientBrowserManager.getPatientById(opdDTO.getPatientCode()); @@ -99,11 +99,11 @@ ResponseEntity newOpd(@RequestBody OpdDTO opdDTO) throws OHServiceExcep throw new OHAPIException(new OHExceptionMessage(null, "not field is mandatory!", OHSeverityLevel.ERROR)); } Opd opdToInsert = mapper.map2Model(opdDTO); - boolean isCreated = opdManager.newOpd(opdToInsert); - if (!isCreated) { + Opd isCreated = opdManager.newOpd(opdToInsert); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Opd is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.OK).body(true); + return ResponseEntity.status(HttpStatus.OK).body(mapper.map2DTO(isCreated)); } /** @@ -113,7 +113,7 @@ ResponseEntity newOpd(@RequestBody OpdDTO opdDTO) throws OHServiceExcep * @throws OHServiceException */ @PutMapping(value = "/opds/{code}", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updateOpd(@PathVariable("code") int code, @RequestBody OpdDTO opdDTO) + ResponseEntity updateOpd(@PathVariable("code") int code, @RequestBody OpdDTO opdDTO) throws OHServiceException { LOGGER.info("Update opds code: {}", opdDTO.getCode()); /* if(opdManager.getOpdByCode(code) == null ) { @@ -135,7 +135,7 @@ ResponseEntity updateOpd(@PathVariable("code") int code, @RequestBody O if(updatedOpd == null) throw new OHAPIException(new OHExceptionMessage(null, "Opd is not updated!", OHSeverityLevel.ERROR)); - return ResponseEntity.ok(updatedOpd.getCode()); + return ResponseEntity.ok(mapper.map2DTO(updatedOpd)); } /** diff --git a/src/main/java/org/isf/operation/rest/OperationController.java b/src/main/java/org/isf/operation/rest/OperationController.java index 31877dec7..7763f519c 100644 --- a/src/main/java/org/isf/operation/rest/OperationController.java +++ b/src/main/java/org/isf/operation/rest/OperationController.java @@ -94,18 +94,17 @@ public OperationController(OperationBrowserManager operationManager, OperationMa * @throws OHServiceException */ @PostMapping(value = "/operations", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newOperation(@RequestBody OperationDTO operationDTO) throws OHServiceException { + ResponseEntity newOperation(@RequestBody OperationDTO operationDTO) throws OHServiceException { String code = operationDTO.getCode(); LOGGER.info("Create operation {}", code); if(operationManager.descriptionControl(operationDTO.getDescription(), operationDTO.getType().getCode())) { throw new OHAPIException(new OHExceptionMessage(null, "another operation has already been created with provided description and types!", OHSeverityLevel.ERROR)); } - boolean isCreated = operationManager.newOperation(mapper.map2Model(operationDTO)); - Operation operationCreated = operationManager.getOperationByCode(code); - if (!isCreated || operationCreated == null) { + Operation isCreated = operationManager.newOperation(mapper.map2Model(operationDTO)); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "operation is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(operationCreated.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -115,17 +114,17 @@ ResponseEntity newOperation(@RequestBody OperationDTO operationDTO) thro * @throws OHServiceException */ @PutMapping(value = "/operations/{code}", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updateOperation(@PathVariable String code, @RequestBody OperationDTO operationDTO) + ResponseEntity updateOperation(@PathVariable String code, @RequestBody OperationDTO operationDTO) throws OHServiceException { LOGGER.info("Update operations code: {}", operationDTO.getCode()); Operation operation = mapper.map2Model(operationDTO); if (!operationManager.isCodePresent(code)) throw new OHAPIException(new OHExceptionMessage(null, "operation not found!", OHSeverityLevel.ERROR)); operation.setLock(0); - boolean isUpdated = operationManager.updateOperation(operation); - if (!isUpdated) + Operation isUpdated = operationManager.updateOperation(operation); + if (isUpdated == null) throw new OHAPIException(new OHExceptionMessage(null, "operation is not updated!", OHSeverityLevel.ERROR)); - return ResponseEntity.ok(operation.getCode()); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/opetype/rest/OperationTypeController.java b/src/main/java/org/isf/opetype/rest/OperationTypeController.java index 53df057f4..f37c1105b 100644 --- a/src/main/java/org/isf/opetype/rest/OperationTypeController.java +++ b/src/main/java/org/isf/opetype/rest/OperationTypeController.java @@ -71,16 +71,14 @@ public OperationTypeController(OperationTypeBrowserManager opeTypeManager, Opera * @throws OHServiceException */ @PostMapping(value = "/operationtypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newOperationType(@RequestBody OperationTypeDTO operationTypeDTO) throws OHServiceException { + ResponseEntity newOperationType(@RequestBody OperationTypeDTO operationTypeDTO) throws OHServiceException { String code = operationTypeDTO.getCode(); LOGGER.info("Create operation Type {}", code); - boolean isCreated = opeTypeManager.newOperationType(mapper.map2Model(operationTypeDTO)); - OperationType opeTypeCreated = opeTypeManager.getOperationType().stream().filter(opetype -> opetype.getCode().equals(code)) - .findFirst().orElse(null); - if (!isCreated || opeTypeCreated == null) { + OperationType isCreated = opeTypeManager.newOperationType(mapper.map2Model(operationTypeDTO)); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "operation Type is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(opeTypeCreated.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -90,16 +88,16 @@ ResponseEntity newOperationType(@RequestBody OperationTypeDTO operationT * @throws OHServiceException */ @PutMapping(value = "/operationtypes/{code}", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updateOperationTypet(@PathVariable String code, @RequestBody OperationTypeDTO operationTypeDTO) + ResponseEntity updateOperationTypet(@PathVariable String code, @RequestBody OperationTypeDTO operationTypeDTO) throws OHServiceException { LOGGER.info("Update operationtypes code: {}", operationTypeDTO.getCode()); OperationType opeType = mapper.map2Model(operationTypeDTO); if (!opeTypeManager.isCodePresent(code)) throw new OHAPIException(new OHExceptionMessage(null, "operation Type not found!", OHSeverityLevel.ERROR)); - boolean isUpdated = opeTypeManager.updateOperationType(opeType); - if (!isUpdated) + OperationType isUpdated = opeTypeManager.updateOperationType(opeType); + if (isUpdated == null) throw new OHAPIException(new OHExceptionMessage(null, "operation Type is not updated!", OHSeverityLevel.ERROR)); - return ResponseEntity.ok(opeType.getCode()); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/patient/rest/PatientController.java b/src/main/java/org/isf/patient/rest/PatientController.java index 32f81eedf..b8c9fed21 100644 --- a/src/main/java/org/isf/patient/rest/PatientController.java +++ b/src/main/java/org/isf/patient/rest/PatientController.java @@ -85,18 +85,18 @@ public PatientController(PatientBrowserManager patientManager, PatientMapper pat * @throws OHServiceException */ @PostMapping(value = "/patients", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newPatient(@RequestBody PatientDTO newPatient) throws OHServiceException { + ResponseEntity newPatient(@RequestBody PatientDTO newPatient) throws OHServiceException { String name = StringUtils.isEmpty(newPatient.getName()) ? newPatient.getFirstName() + " " + newPatient.getSecondName() : newPatient.getName(); LOGGER.info("Create patient {}", name); Patient patient = patientManager.savePatient(patientMapper.map2Model(newPatient)); if(patient == null){ throw new OHAPIException(new OHExceptionMessage(null, "Patient is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(patient.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(patientMapper.map2DTO(patient)); } @PutMapping(value = "/patients/{code}", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updatePatient(@PathVariable int code, @RequestBody PatientDTO updatePatient) throws OHServiceException { + ResponseEntity updatePatient(@PathVariable int code, @RequestBody PatientDTO updatePatient) throws OHServiceException { LOGGER.info("Update patient code: {}", code); if (!updatePatient.getCode().equals(code)) { throw new OHAPIException(new OHExceptionMessage(null, "Patient code mismatch", OHSeverityLevel.ERROR)); @@ -111,7 +111,7 @@ ResponseEntity updatePatient(@PathVariable int code, @RequestBody Patie if (patient == null) { throw new OHAPIException(new OHExceptionMessage(null, "Patient is not updated!", OHSeverityLevel.ERROR)); } - return ResponseEntity.ok(patient.getCode()); + return ResponseEntity.ok(patientMapper.map2DTO(patient)); } @GetMapping(value = "/patients", produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/src/main/java/org/isf/patvac/rest/PatVacController.java b/src/main/java/org/isf/patvac/rest/PatVacController.java index e18047c41..332c7b3f0 100644 --- a/src/main/java/org/isf/patvac/rest/PatVacController.java +++ b/src/main/java/org/isf/patvac/rest/PatVacController.java @@ -74,14 +74,14 @@ public PatVacController(PatVacManager patVacManager, PatVacMapper patientVaccine * @throws OHServiceException */ @PostMapping(value = "/patientvaccines", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newPatientVaccine(@RequestBody PatientVaccineDTO patientVaccineDTO) throws OHServiceException { + ResponseEntity newPatientVaccine(@RequestBody PatientVaccineDTO patientVaccineDTO) throws OHServiceException { int code = patientVaccineDTO.getCode(); LOGGER.info("Create patient vaccine {}", code); - boolean isCreated = patVacManager.newPatientVaccine(mapper.map2Model(patientVaccineDTO)); - if (!isCreated) { + PatientVaccine isCreated = patVacManager.newPatientVaccine(mapper.map2Model(patientVaccineDTO)); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "patient vaccine is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(true); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -91,15 +91,15 @@ ResponseEntity newPatientVaccine(@RequestBody PatientVaccineDTO patient * @throws OHServiceException */ @PutMapping(value = "/patientvaccines/{code}", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updatePatientVaccinet(@PathVariable Integer code, @RequestBody PatientVaccineDTO patientVaccineDTO) + ResponseEntity updatePatientVaccinet(@PathVariable Integer code, @RequestBody PatientVaccineDTO patientVaccineDTO) throws OHServiceException { LOGGER.info("Update patientvaccines code: {}", patientVaccineDTO.getCode()); PatientVaccine patvac = mapper.map2Model(patientVaccineDTO); patvac.setLock(0); - boolean isUpdated = patVacManager.updatePatientVaccine(patvac); - if (!isUpdated) + PatientVaccine isUpdated = patVacManager.updatePatientVaccine(patvac); + if (isUpdated == null) throw new OHAPIException(new OHExceptionMessage(null, "patient vaccine is not updated!", OHSeverityLevel.ERROR)); - return ResponseEntity.ok(patientVaccineDTO.getCode()); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/pregtreattype/rest/PregnantTreatmentTypeController.java b/src/main/java/org/isf/pregtreattype/rest/PregnantTreatmentTypeController.java index 8700ad0f8..197cdf5ee 100644 --- a/src/main/java/org/isf/pregtreattype/rest/PregnantTreatmentTypeController.java +++ b/src/main/java/org/isf/pregtreattype/rest/PregnantTreatmentTypeController.java @@ -71,16 +71,14 @@ public PregnantTreatmentTypeController(PregnantTreatmentTypeBrowserManager pregT * @throws OHServiceException */ @PostMapping(value = "/pregnanttreatmenttypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newPregnantTreatmentType(@RequestBody PregnantTreatmentTypeDTO pregnantTreatmentTypeDTO) throws OHServiceException { + ResponseEntity newPregnantTreatmentType(@RequestBody PregnantTreatmentTypeDTO pregnantTreatmentTypeDTO) throws OHServiceException { String code = pregnantTreatmentTypeDTO.getCode(); LOGGER.info("Create pregnant treatment Type {}", code); - boolean isCreated = pregTreatTypeManager.newPregnantTreatmentType(mapper.map2Model(pregnantTreatmentTypeDTO)); - PregnantTreatmentType pregTreatTypeCreated = pregTreatTypeManager.getPregnantTreatmentType().stream().filter(pregtreattype -> pregtreattype.getCode().equals(code)) - .findFirst().orElse(null); - if (!isCreated || pregTreatTypeCreated == null) { + PregnantTreatmentType isCreated = pregTreatTypeManager.newPregnantTreatmentType(mapper.map2Model(pregnantTreatmentTypeDTO)); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "pregnant treatment Type is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(pregTreatTypeCreated.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -90,16 +88,16 @@ ResponseEntity newPregnantTreatmentType(@RequestBody PregnantTreatmentTy * @throws OHServiceException */ @PutMapping(value = "/pregnanttreatmenttypes/{code}", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updatePregnantTreatmentTypet(@PathVariable String code, @RequestBody PregnantTreatmentTypeDTO pregnantTreatmentTypeDTO) + ResponseEntity updatePregnantTreatmentTypet(@PathVariable String code, @RequestBody PregnantTreatmentTypeDTO pregnantTreatmentTypeDTO) throws OHServiceException { LOGGER.info("Update pregnanttreatmenttypes code: {}", pregnantTreatmentTypeDTO.getCode()); PregnantTreatmentType pregTreatType = mapper.map2Model(pregnantTreatmentTypeDTO); if (!pregTreatTypeManager.isCodePresent(code)) throw new OHAPIException(new OHExceptionMessage(null, "pregnantTreatment Type not found!", OHSeverityLevel.ERROR)); - boolean isUpdated = pregTreatTypeManager.updatePregnantTreatmentType(pregTreatType); - if (!isUpdated) + PregnantTreatmentType isUpdated = pregTreatTypeManager.updatePregnantTreatmentType(pregTreatType); + if (isUpdated == null) throw new OHAPIException(new OHExceptionMessage(null, "pregnantTreatment Type is not updated!", OHSeverityLevel.ERROR)); - return ResponseEntity.ok(pregTreatType.getCode()); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/priceslist/rest/PriceListController.java b/src/main/java/org/isf/priceslist/rest/PriceListController.java index aa80c0121..8fd0be9df 100644 --- a/src/main/java/org/isf/priceslist/rest/PriceListController.java +++ b/src/main/java/org/isf/priceslist/rest/PriceListController.java @@ -78,13 +78,13 @@ public PriceListController(PriceListManager priceListManager, PriceListMapper pr * @throws OHServiceException */ @PostMapping(value = "/pricelists", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newPriceList(@RequestBody PriceListDTO priceListDTO) throws OHServiceException { + ResponseEntity newPriceList(@RequestBody PriceListDTO priceListDTO) throws OHServiceException { LOGGER.info("Create price list {}", priceListDTO.getCode()); - boolean isCreated = priceListManager.newList(mapper.map2Model(priceListDTO)); - if (!isCreated) { + PriceList isCreated = priceListManager.newList(mapper.map2Model(priceListDTO)); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "price list is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(priceListDTO.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -94,14 +94,14 @@ ResponseEntity newPriceList(@RequestBody PriceListDTO priceListDTO) thro * @throws OHServiceException */ @PutMapping(value = "/pricelists/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updatePriceListt(@PathVariable Integer id, @RequestBody PriceListDTO priceListDTO) + ResponseEntity updatePriceListt(@PathVariable Integer id, @RequestBody PriceListDTO priceListDTO) throws OHServiceException { LOGGER.info("Update pricelists code: {}", priceListDTO.getCode()); PriceList priceList = mapper.map2Model(priceListDTO); - boolean isUpdated = priceListManager.updateList(priceList); - if (!isUpdated) + PriceList isUpdated = priceListManager.updateList(priceList); + if (isUpdated == null) throw new OHAPIException(new OHExceptionMessage(null, "price list is not updated!", OHSeverityLevel.ERROR)); - return ResponseEntity.ok(priceList.getCode()); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/pricesothers/rest/PricesOthersController.java b/src/main/java/org/isf/pricesothers/rest/PricesOthersController.java index 72b9be326..3ce817b37 100644 --- a/src/main/java/org/isf/pricesothers/rest/PricesOthersController.java +++ b/src/main/java/org/isf/pricesothers/rest/PricesOthersController.java @@ -71,13 +71,13 @@ public PricesOthersController(PricesOthersManager pricesOthersManager, PricesOth * @throws OHServiceException */ @PostMapping(value = "/pricesothers", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newPricesOthers(@RequestBody PricesOthersDTO pricesOthersDTO) throws OHServiceException { + ResponseEntity newPricesOthers(@RequestBody PricesOthersDTO pricesOthersDTO) throws OHServiceException { LOGGER.info("Create prices others {}", pricesOthersDTO.getCode()); - boolean isCreated = pricesOthersManager.newOther(mapper.map2Model(pricesOthersDTO)); - if (!isCreated) { + PricesOthers isCreated = pricesOthersManager.newOther(mapper.map2Model(pricesOthersDTO)); + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "prices others is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(pricesOthersDTO.getCode()); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -87,17 +87,17 @@ ResponseEntity newPricesOthers(@RequestBody PricesOthersDTO pricesOthers * @throws OHServiceException */ @PutMapping(value = "/pricesothers/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updatePricesOtherst(@PathVariable Integer id, @RequestBody PricesOthersDTO pricesOthersDTO) + ResponseEntity updatePricesOtherst(@PathVariable Integer id, @RequestBody PricesOthersDTO pricesOthersDTO) throws OHServiceException { LOGGER.info("Update pricesothers code: {}", pricesOthersDTO.getCode()); PricesOthers pricesOthers = mapper.map2Model(pricesOthersDTO); List pricesOthersFounds = pricesOthersManager.getOthers().stream().filter(po -> po.getId() == pricesOthersDTO.getId()).collect(Collectors.toList()); if (pricesOthersFounds.isEmpty()) return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); - boolean isUpdated = pricesOthersManager.updateOther(pricesOthers); - if (!isUpdated) + PricesOthers isUpdated = pricesOthersManager.updateOther(pricesOthers); + if (isUpdated == null) throw new OHAPIException(new OHExceptionMessage(null, "prices others is not updated!", OHSeverityLevel.ERROR)); - return ResponseEntity.ok(pricesOthers.getCode()); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/supplier/rest/SupplierController.java b/src/main/java/org/isf/supplier/rest/SupplierController.java index c8241c42d..df1fa5448 100644 --- a/src/main/java/org/isf/supplier/rest/SupplierController.java +++ b/src/main/java/org/isf/supplier/rest/SupplierController.java @@ -67,15 +67,15 @@ public class SupplierController { * @throws OHServiceException */ @PostMapping(value = "/suppliers", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity saveSupplier(@RequestBody @Valid SupplierDTO supplierDTO) throws OHServiceException { + public ResponseEntity saveSupplier(@RequestBody @Valid SupplierDTO supplierDTO) throws OHServiceException { LOGGER.info("Saving a new supplier..."); - boolean isCreated = manager.saveOrUpdate(mapper.map2Model(supplierDTO)); - if (!isCreated) { + Supplier isCreated = manager.saveOrUpdate(mapper.map2Model(supplierDTO)); + if (isCreated == null) { LOGGER.error("Supplier is not created!"); throw new OHAPIException(new OHExceptionMessage(null, "Supplier is not created!", OHSeverityLevel.ERROR)); } LOGGER.info("Supplier saved successfully"); - return ResponseEntity.status(HttpStatus.CREATED).body(isCreated); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -85,18 +85,18 @@ public ResponseEntity saveSupplier(@RequestBody @Valid SupplierDTO supp * @throws OHServiceException */ @PutMapping(value = "/suppliers", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateSupplier(@RequestBody @Valid SupplierDTO supplierDTO) throws OHServiceException { + public ResponseEntity updateSupplier(@RequestBody @Valid SupplierDTO supplierDTO) throws OHServiceException { if(supplierDTO.getSupId() == null || manager.getByID(supplierDTO.getSupId()) == null) { throw new OHAPIException(new OHExceptionMessage(null, "Supplier not found!", OHSeverityLevel.ERROR)); } LOGGER.info("Updating supplier..."); - boolean isUpdated = manager.saveOrUpdate(mapper.map2Model(supplierDTO)); - if (!isUpdated) { + Supplier isUpdated = manager.saveOrUpdate(mapper.map2Model(supplierDTO)); + if (isUpdated == null) { LOGGER.error("Supplier is not updated!"); throw new OHAPIException(new OHExceptionMessage(null, "Supplier is not updated!", OHSeverityLevel.ERROR)); } LOGGER.info("Supplier updated successfully"); - return ResponseEntity.ok(isUpdated); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } /** diff --git a/src/main/java/org/isf/vaccine/rest/VaccineController.java b/src/main/java/org/isf/vaccine/rest/VaccineController.java index 19997f845..eac9e69b5 100644 --- a/src/main/java/org/isf/vaccine/rest/VaccineController.java +++ b/src/main/java/org/isf/vaccine/rest/VaccineController.java @@ -109,18 +109,18 @@ public ResponseEntity> getVaccinesByVaccineTypeCode(@PathVariab * @throws OHServiceException */ @PostMapping(value = "/vaccines", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newVaccine(@RequestBody VaccineDTO newVaccine) throws OHServiceException { + public ResponseEntity newVaccine(@RequestBody VaccineDTO newVaccine) throws OHServiceException { LOGGER.info("Create vaccine: {}", newVaccine.toString()); - boolean isCreated; + Vaccine isCreated; try { - isCreated = vaccineManager.newVaccine(mapper.map2Model(newVaccine)) != null; + isCreated = vaccineManager.newVaccine(mapper.map2Model(newVaccine)); } catch (OHDataIntegrityViolationException e) { throw new OHAPIException(new OHExceptionMessage(null, "Vaccine type already present!", OHSeverityLevel.ERROR)); } - if (!isCreated) { + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Vaccine is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(null); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -131,13 +131,13 @@ public ResponseEntity newVaccine(@RequestBody VaccineDTO newVaccine) throws OHSe * @throws OHServiceException */ @PutMapping(value = "/vaccines", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateVaccine(@RequestBody VaccineDTO updateVaccine) throws OHServiceException { + public ResponseEntity updateVaccine(@RequestBody VaccineDTO updateVaccine) throws OHServiceException { LOGGER.info("Update vaccine: {}", updateVaccine.toString()); - boolean isUpdated = vaccineManager.updateVaccine(mapper.map2Model(updateVaccine)) != null; - if (!isUpdated) { + Vaccine isUpdated = vaccineManager.updateVaccine(mapper.map2Model(updateVaccine)); + if (isUpdated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Vaccine is not updated!", OHSeverityLevel.ERROR)); } - return ResponseEntity.ok(null); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } diff --git a/src/main/java/org/isf/vactype/rest/VaccineTypeController.java b/src/main/java/org/isf/vactype/rest/VaccineTypeController.java index 7016a5aeb..91e408123 100644 --- a/src/main/java/org/isf/vactype/rest/VaccineTypeController.java +++ b/src/main/java/org/isf/vactype/rest/VaccineTypeController.java @@ -90,18 +90,18 @@ public ResponseEntity> getVaccineType() throws OHServiceExc * @throws OHServiceException */ @PostMapping(value = "/vaccinetype", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newVaccineType(@RequestBody VaccineTypeDTO newVaccineType) throws OHServiceException { + public ResponseEntity newVaccineType(@RequestBody VaccineTypeDTO newVaccineType) throws OHServiceException { LOGGER.info("Create vaccine type: {}", newVaccineType.toString()); - boolean isCreated; + VaccineType isCreated; try { isCreated = vaccineTypeManager.newVaccineType(mapper.map2Model(newVaccineType)); }catch(OHDataIntegrityViolationException e){ throw new OHAPIException(new OHExceptionMessage(null, "Vaccine type already present!", OHSeverityLevel.ERROR)); } - if (!isCreated) { + if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Vaccine type is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(null); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(isCreated)); } /** @@ -112,13 +112,13 @@ public ResponseEntity newVaccineType(@RequestBody VaccineTypeDTO newVaccineType) * @throws OHServiceException */ @PutMapping(value = "/vaccinetype", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateVaccineType(@RequestBody VaccineTypeDTO updateVaccineType) throws OHServiceException { + public ResponseEntity updateVaccineType(@RequestBody VaccineTypeDTO updateVaccineType) throws OHServiceException { LOGGER.info("Update vaccine type: {}", updateVaccineType.toString()); - boolean isUpdated = vaccineTypeManager.updateVaccineType(mapper.map2Model(updateVaccineType)); - if (!isUpdated) { + VaccineType isUpdated = vaccineTypeManager.updateVaccineType(mapper.map2Model(updateVaccineType)); + if (isUpdated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Vaccine type is not updated!", OHSeverityLevel.ERROR)); } - return ResponseEntity.ok(null); + return ResponseEntity.ok(mapper.map2DTO(isUpdated)); } diff --git a/src/main/java/org/isf/visits/rest/VisitsController.java b/src/main/java/org/isf/visits/rest/VisitsController.java index 45234d394..73c89f40b 100644 --- a/src/main/java/org/isf/visits/rest/VisitsController.java +++ b/src/main/java/org/isf/visits/rest/VisitsController.java @@ -91,10 +91,10 @@ public ResponseEntity> getVisit(@PathVariable("patID") int patID) * @throws OHServiceException */ @PostMapping(value = "/visit", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newVisit(@RequestBody VisitDTO newVisit) throws OHServiceException { + public ResponseEntity newVisit(@RequestBody VisitDTO newVisit) throws OHServiceException { LOGGER.info("Create Visit: {}", newVisit); Visit visit = visitManager.newVisit(mapper.map2Model(newVisit)); - return ResponseEntity.status(HttpStatus.CREATED).body(visit.getVisitID()); //TODO: verify if it's correct + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(visit)); //TODO: verify if it's correct } /** diff --git a/src/main/java/org/isf/ward/rest/WardController.java b/src/main/java/org/isf/ward/rest/WardController.java index bc7195d69..745934a66 100644 --- a/src/main/java/org/isf/ward/rest/WardController.java +++ b/src/main/java/org/isf/ward/rest/WardController.java @@ -126,13 +126,13 @@ public ResponseEntity getCurrentOccupation(@PathVariable String code) t * @throws OHServiceException */ @PostMapping(value = "/wards", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity newWard(@RequestBody WardDTO newWard) throws OHServiceException { + public ResponseEntity newWard(@RequestBody WardDTO newWard) throws OHServiceException { LOGGER.info("Create Ward: {}", newWard); Ward wardCreated = wardManager.newWard(mapper.map2Model(newWard)); if (wardCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Ward is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(null); + return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(wardCreated)); } /** @@ -143,7 +143,7 @@ public ResponseEntity newWard(@RequestBody WardDTO newWard) throws OHServiceExce * @throws OHServiceException */ @PutMapping(value = "/wards", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity updateWard(@RequestBody WardDTO updateWard) throws OHServiceException { + public ResponseEntity updateWard(@RequestBody WardDTO updateWard) throws OHServiceException { LOGGER.info("Update ward with code: {}", updateWard.getCode()); Ward ward = mapper.map2Model(updateWard); ward.setLock(0); @@ -151,7 +151,7 @@ public ResponseEntity updateWard(@RequestBody WardDTO updateWard) throws OHServi if (wardUpdated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Ward is not updated!", OHSeverityLevel.ERROR)); } - return ResponseEntity.ok(null); + return ResponseEntity.ok(mapper.map2DTO(wardUpdated)); } From f4af63813ebc43903002abea4a7eeb2c972b0a93 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Mon, 13 Jun 2022 14:27:30 +0100 Subject: [PATCH 08/24] fix bug about therapie --- .../admission/rest/AdmissionController.java | 42 +++++++++++++++++-- .../rest/ExaminationController.java | 31 +++++++++++--- .../java/org/isf/medical/dto/MedicalDTO.java | 16 +++---- .../operation/rest/OperationController.java | 8 +++- .../org/isf/patient/mapper/PatientMapper.java | 10 ++++- .../isf/patient/rest/PatientController.java | 6 ++- .../org/isf/therapy/dto/TherapyRowDTO.java | 20 ++++----- .../isf/therapy/mapper/TherapyRowMapper.java | 18 ++++++-- .../isf/therapy/rest/TherapyController.java | 11 +++-- .../org/isf/visits/rest/VisitsController.java | 7 +++- 10 files changed, 131 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/isf/admission/rest/AdmissionController.java b/src/main/java/org/isf/admission/rest/AdmissionController.java index 10f88fb0c..dd2d02a18 100644 --- a/src/main/java/org/isf/admission/rest/AdmissionController.java +++ b/src/main/java/org/isf/admission/rest/AdmissionController.java @@ -320,6 +320,7 @@ public ResponseEntity dischargePatient(@RequestParam("patientCode") int Admission adm = admissionMapper.map2Model(currentAdmissionDTO); adm.setAdmDate(currentAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + if (adm == null || admission.getId() != adm.getId()) return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); @@ -327,11 +328,13 @@ public ResponseEntity dischargePatient(@RequestParam("patientCode") int throw new OHAPIException( new OHExceptionMessage(null, "at least one disease must be give!", OHSeverityLevel.ERROR)); } + if (adm.getDisDate() == null) { throw new OHAPIException( new OHExceptionMessage(null, "the exit date must be filled in!", OHSeverityLevel.ERROR)); } - if (adm.getDisType() == null || !dischargeManager.isCodePresent(adm.getDisType().getCode())) { + adm.setAdmDate(currentAdmissionDTO.getDisDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + if (adm.getDisDate() == null || !dischargeManager.isCodePresent(adm.getDisType().getCode())) { throw new OHAPIException(new OHExceptionMessage(null, "the type of output is mandatory or does not exist!", OHSeverityLevel.ERROR)); } @@ -356,7 +359,18 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA Admission newAdmission = admissionMapper.map2Model(newAdmissionDTO); newAdmission.setAdmDate(newAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); - + if(newAdmissionDTO.getAbortDate() != null) { + newAdmission.setAbortDate(newAdmissionDTO.getAbortDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + } + if(newAdmissionDTO.getCtrlDate1() != null) { + newAdmission.setCtrlDate1(newAdmissionDTO.getCtrlDate1().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + } + if(newAdmissionDTO.getCtrlDate2() != null) { + newAdmission.setCtrlDate2(newAdmissionDTO.getCtrlDate2().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + } + if(newAdmissionDTO.getOpDate() != null) { + newAdmission.setOpDate(newAdmissionDTO.getOpDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + } if (newAdmissionDTO.getWard() != null && newAdmissionDTO.getWard().getCode() != null && !newAdmissionDTO.getWard().getCode().trim().isEmpty()) { List wards = wardManager.getWards().stream() @@ -516,7 +530,8 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmis throw new OHAPIException(new OHExceptionMessage(null, "Admission not found!", OHSeverityLevel.ERROR)); } Admission updAdmission = admissionMapper.map2Model(updAdmissionDTO); - + updAdmission.setAdmDate(updAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + if (updAdmissionDTO.getWard() != null && updAdmissionDTO.getWard().getCode() != null && !updAdmissionDTO.getWard().getCode().trim().isEmpty()) { List wards = wardManager.getWards().stream() @@ -671,6 +686,27 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmis Instant instant = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); Date date = Date.from(instant); admDTO.setAdmDate(date); + + if(admDTO.getAbortDate() != null) { + Instant instant1 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date1 = Date.from(instant1); + admDTO.setAbortDate(date1); + } + if(admDTO.getCtrlDate1() != null) { + Instant instant2 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date1 = Date.from(instant2); + admDTO.setAbortDate(date1); + } + if(admDTO.getCtrlDate2() != null) { + Instant instant3 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date2 = Date.from(instant3); + admDTO.setAbortDate(date2); + } + if(admDTO.getOpDate() != null) { + Instant instant4 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date3 = Date.from(instant4); + admDTO.setAbortDate(date3); + } return ResponseEntity.ok(admDTO); } diff --git a/src/main/java/org/isf/examination/rest/ExaminationController.java b/src/main/java/org/isf/examination/rest/ExaminationController.java index 006f201e8..bacdfcbf0 100644 --- a/src/main/java/org/isf/examination/rest/ExaminationController.java +++ b/src/main/java/org/isf/examination/rest/ExaminationController.java @@ -21,6 +21,9 @@ */ package org.isf.examination.rest; +import java.sql.Date; +import java.time.Instant; +import java.time.ZoneId; import java.util.List; import org.isf.examination.dto.PatientExaminationDTO; @@ -79,7 +82,7 @@ public ResponseEntity newPatientExamination(@RequestBody PatientExamina PatientExamination patientExamination = patientExaminationMapper.map2Model(newPatientExamination); patientExamination.setPatient(patient); - + patientExamination.setPex_date(newPatientExamination.getPex_date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); examinationBrowserManager.saveOrUpdate(patientExamination); return ResponseEntity.status(HttpStatus.CREATED).body(true); @@ -87,7 +90,7 @@ public ResponseEntity newPatientExamination(@RequestBody PatientExamina @PutMapping(value = "/examinations/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.OK) - public ResponseEntity updateExamination(@PathVariable Integer id, @RequestBody PatientExaminationDTO dto) throws OHServiceException { + public ResponseEntity updateExamination(@PathVariable Integer id, @RequestBody PatientExaminationDTO dto) throws OHServiceException { if (dto.getPex_ID() != id) { throw new OHAPIException(new OHExceptionMessage(null, "Patient examination id mismatch", OHSeverityLevel.ERROR)); } @@ -102,6 +105,7 @@ public ResponseEntity updateExamination(@PathVariable Integer id, @RequestBody P PatientExamination patientExamination = patientExaminationMapper.map2Model(dto); patientExamination.setPatient(patient); + patientExamination.setPex_date(dto.getPex_date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); examinationBrowserManager.saveOrUpdate(patientExamination); return ResponseEntity.ok(true); @@ -114,10 +118,15 @@ public ResponseEntity getDefaultPatientExamination(@Reque if (patient == null) { throw new OHAPIException(new OHExceptionMessage(null, "Patient not exists!", OHSeverityLevel.ERROR)); } - PatientExaminationDTO patientExaminationDTO = patientExaminationMapper.map2DTO(examinationBrowserManager.getDefaultPatientExamination(patient)); + PatientExamination patientExamination = examinationBrowserManager.getDefaultPatientExamination(patient); + PatientExaminationDTO patientExaminationDTO = patientExaminationMapper.map2DTO(patientExamination); if (patientExaminationDTO == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } else { + Instant instant = patientExamination.getPex_date().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + patientExaminationDTO.setPex_date(date); + return ResponseEntity.ok(patientExaminationDTO); } } @@ -130,6 +139,9 @@ public ResponseEntity getFromLastPatientExamination(@Path if (patientExaminationDTO == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } else { + Instant instant = lastPatientExamination.getPex_date().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + patientExaminationDTO.setPex_date(date); return ResponseEntity.ok(patientExaminationDTO); } } @@ -142,7 +154,12 @@ public ResponseEntity getByID(@PathVariable Integer id) t if (patientExamination == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } else { - return ResponseEntity.ok(patientExaminationMapper.map2DTO(patientExamination)); + PatientExaminationDTO patienE = patientExaminationMapper.map2DTO(patientExamination); + Instant instant = patientExamination.getPex_date().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + patienE.setPex_date(date); + return ResponseEntity.ok(patienE); + } } @@ -154,7 +171,11 @@ public ResponseEntity getLastByPatientId(@PathVariable In if (patientExamination == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } else { - return ResponseEntity.ok(patientExaminationMapper.map2DTO(patientExamination)); + PatientExaminationDTO patienE = patientExaminationMapper.map2DTO(patientExamination); + Instant instant = patientExamination.getPex_date().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + patienE.setPex_date(date); + return ResponseEntity.ok(patienE); } } diff --git a/src/main/java/org/isf/medical/dto/MedicalDTO.java b/src/main/java/org/isf/medical/dto/MedicalDTO.java index 97ebd5748..06835cbdb 100644 --- a/src/main/java/org/isf/medical/dto/MedicalDTO.java +++ b/src/main/java/org/isf/medical/dto/MedicalDTO.java @@ -33,35 +33,35 @@ public class MedicalDTO { @ApiModelProperty(notes="The id of the medical", example = "1", position = 1) private Integer code; - @NotEmpty(message="The product code is required") + //@NotEmpty(message="The product code is required") @ApiModelProperty(notes="The product code", example = "PARA", position = 2) private String prod_code; - @NotNull(message="The medical type is required") + //@NotNull(message="The medical type is required") @ApiModelProperty(notes="The medical type", position = 3) private MedicalTypeDTO type; - @NotEmpty(message="The description of the medical is required") + //@NotEmpty(message="The description of the medical is required") @ApiModelProperty(notes="The description of the medical", example = "Paracétamol", position = 4) private String description; - @NotNull(message="Initial quantity is required") + //@NotNull(message="Initial quantity is required") @ApiModelProperty(notes="The initial quantity of the medical", example = "21", position = 5) private double initialqty; - @NotNull(message="The number of pieces per packet is required") + //@NotNull(message="The number of pieces per packet is required") @ApiModelProperty(notes="The number of pieces per packet", example = "100", position = 6) private Integer pcsperpck; - @NotNull(message="The input quantity is required") + //@NotNull(message="The input quantity is required") @ApiModelProperty(notes="The input quantity of the medical", example = "340", position = 7) private double inqty; - @NotNull(message="The out quantity is required") + //@NotNull(message="The out quantity is required") @ApiModelProperty(notes="The out quantity of the medical", example = "8", position = 8) private double outqty; - @NotNull(message="The min quantity is required") + //@NotNull(message="The min quantity is required") @ApiModelProperty(notes="The min quantity of the medical", example = "15", position = 9) private double minqty; diff --git a/src/main/java/org/isf/operation/rest/OperationController.java b/src/main/java/org/isf/operation/rest/OperationController.java index 7763f519c..aacc6315a 100644 --- a/src/main/java/org/isf/operation/rest/OperationController.java +++ b/src/main/java/org/isf/operation/rest/OperationController.java @@ -21,6 +21,7 @@ */ package org.isf.operation.rest; +import java.time.ZoneId; import java.util.List; import java.util.stream.Collectors; @@ -100,6 +101,7 @@ ResponseEntity newOperation(@RequestBody OperationDTO operationDTO if(operationManager.descriptionControl(operationDTO.getDescription(), operationDTO.getType().getCode())) { throw new OHAPIException(new OHExceptionMessage(null, "another operation has already been created with provided description and types!", OHSeverityLevel.ERROR)); } + Operation operation = mapper.map2Model(operationDTO); Operation isCreated = operationManager.newOperation(mapper.map2Model(operationDTO)); if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "operation is not created!", OHSeverityLevel.ERROR)); @@ -205,12 +207,14 @@ public ResponseEntity deleteOperation(@PathVariable("code") String code */ @PostMapping(value = "/operations/rows", produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity newOperationRow(@RequestBody OperationRowDTO operationRowDTO) throws OHServiceException { - int code = operationRowDTO.getId(); + int code = operationRowDTO.getAdmission().getId(); LOGGER.info("Create operation {}", code); if(operationRowDTO.getAdmission() == null && operationRowDTO.getOpd() == null) { throw new OHAPIException(new OHExceptionMessage(null, "At least one field between admission and Opd is required!", OHSeverityLevel.ERROR)); } OperationRow opRow = opRowMapper.map2Model(operationRowDTO); + opRow.setOpDate(operationRowDTO.getOpDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + boolean isCreated = operationRowManager.newOperationRow(opRow); List opRowFounds = operationRowManager.getOperationRowByAdmission(opRow.getAdmission()).stream().filter(op -> op.getId() == code) .collect(Collectors.toList()); @@ -238,6 +242,8 @@ ResponseEntity updateOperationRow(@RequestBody OperationRowDTO operatio throw new OHAPIException(new OHExceptionMessage(null, "At least one field between admission and Opd is required!", OHSeverityLevel.ERROR)); } OperationRow opRow = opRowMapper.map2Model(operationRowDTO); + opRow.setOpDate(operationRowDTO.getOpDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + List opRowFounds = operationRowManager.getOperationRowByAdmission(opRow.getAdmission()).stream().filter(op -> op.getId() == opRow.getId()) .collect(Collectors.toList()); if (opRowFounds.isEmpty()) diff --git a/src/main/java/org/isf/patient/mapper/PatientMapper.java b/src/main/java/org/isf/patient/mapper/PatientMapper.java index fac266361..05062f2da 100644 --- a/src/main/java/org/isf/patient/mapper/PatientMapper.java +++ b/src/main/java/org/isf/patient/mapper/PatientMapper.java @@ -21,6 +21,7 @@ */ package org.isf.patient.mapper; +import java.time.ZoneId; import java.util.List; import java.util.stream.Collectors; @@ -41,6 +42,10 @@ public PatientMapper() { @Override public PatientDTO map2DTO(Patient fromObj) { PatientDTO patientDTO = super.map2DTO(fromObj); + if(fromObj.getBirthDate() != null) { + patientDTO.setBirthDate(java.sql.Date.valueOf(fromObj.getBirthDate())); + } + if (fromObj.getPatientProfilePhoto() != null) { patientDTO.setBlobPhoto(fromObj.getPatientProfilePhoto().getPhoto()); } @@ -61,7 +66,10 @@ public PatientDTO map2DTOWS(Patient fromObj, Boolean status) { public Patient map2Model(PatientDTO toObj) { Patient patient = super.map2Model(toObj); - + if(patient.getBirthDate() != null) { + patient.setBirthDate(toObj.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); + } + if (toObj.getBlobPhoto() != null) { PatientProfilePhoto photo = new PatientProfilePhoto(); photo.setPatient(patient); diff --git a/src/main/java/org/isf/patient/rest/PatientController.java b/src/main/java/org/isf/patient/rest/PatientController.java index b8c9fed21..77e83f200 100644 --- a/src/main/java/org/isf/patient/rest/PatientController.java +++ b/src/main/java/org/isf/patient/rest/PatientController.java @@ -23,6 +23,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -88,8 +89,9 @@ public PatientController(PatientBrowserManager patientManager, PatientMapper pat ResponseEntity newPatient(@RequestBody PatientDTO newPatient) throws OHServiceException { String name = StringUtils.isEmpty(newPatient.getName()) ? newPatient.getFirstName() + " " + newPatient.getSecondName() : newPatient.getName(); LOGGER.info("Create patient {}", name); - Patient patient = patientManager.savePatient(patientMapper.map2Model(newPatient)); - if(patient == null){ + Patient patient = patientMapper.map2Model(newPatient); + Patient pat = patientManager.savePatient(patient); + if(pat == null){ throw new OHAPIException(new OHExceptionMessage(null, "Patient is not created!", OHSeverityLevel.ERROR)); } return ResponseEntity.status(HttpStatus.CREATED).body(patientMapper.map2DTO(patient)); diff --git a/src/main/java/org/isf/therapy/dto/TherapyRowDTO.java b/src/main/java/org/isf/therapy/dto/TherapyRowDTO.java index 1f160b5cf..17fdef785 100644 --- a/src/main/java/org/isf/therapy/dto/TherapyRowDTO.java +++ b/src/main/java/org/isf/therapy/dto/TherapyRowDTO.java @@ -35,48 +35,48 @@ public class TherapyRowDTO { @ApiModelProperty(notes="The therapy's ID", example = "1", position = 1) private int therapyID; - @NotNull(message="the patient is required") + //@NotNull(message="the patient is required") @ApiModelProperty(notes="The patient", position = 2) PatientDTO patID; - @NotNull(message="the start date is require") + //@NotNull(message="the start date is require") @ApiModelProperty(notes="The start date of therapy", example = "2020-07-16T14:25:30.002Z", position = 3) @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") private Date startDate; - @NotNull(message="the end date is required") + //@NotNull(message="the end date is required") @ApiModelProperty(notes="The end date of the therapy", example = "2020-07-30T14:25:30.002Z", position = 4) @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") private Date endDate; - @NotNull(message="the medical's ID is required") + //@NotNull(message="the medical's ID is required") @ApiModelProperty(notes="The ID of the medical concerned by the therapy", example = "1", position = 5) private int medicalId; - @NotNull(message="the quantity is required") + //@NotNull(message="the quantity is required") @ApiModelProperty(notes="The quantity of medicals", example = "48", position = 6) private Double qty; - @NotNull(message="the unit's ID is required") + //@NotNull(message="the unit's ID is required") @ApiModelProperty(notes="The unit's ID", example = "1", position = 7) private int unitID; - @NotNull(message="the frequency in day is required") + //@NotNull(message="the frequency in day is required") @ApiModelProperty(notes="The frequency in day", example = "2", position = 8) private int freqInDay; - @NotNull(message="the frequency in period is required") + //@NotNull(message="the frequency in period is required") @ApiModelProperty(notes="The frequency in period", example = "1", position = 9) private int freqInPeriod; @ApiModelProperty(notes="A note for the therapy", example = "Sample note", position = 10) private String note; - @NotNull(message="the notify flag is required") + //@NotNull(message="the notify flag is required") @ApiModelProperty(notes="the notify flag: 1 if the notification need to be activated, 0 otherwise", example = "0", position = 11) private int notifyInt; - @NotNull(message="the sms flag is required") + //@NotNull(message="the sms flag is required") @ApiModelProperty(notes="the sms flag: 1 if sms need to be sent to patient, 0 otherwise", example = "0", position = 12) private int smsInt; diff --git a/src/main/java/org/isf/therapy/mapper/TherapyRowMapper.java b/src/main/java/org/isf/therapy/mapper/TherapyRowMapper.java index b3a417a2f..a7e272a9c 100644 --- a/src/main/java/org/isf/therapy/mapper/TherapyRowMapper.java +++ b/src/main/java/org/isf/therapy/mapper/TherapyRowMapper.java @@ -21,9 +21,13 @@ */ package org.isf.therapy.mapper; +import java.time.Instant; +import java.time.ZoneId; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import org.isf.admission.dto.AdmissionDTO; import org.isf.medicals.model.Medical; import org.isf.patient.dto.PatientDTO; import org.isf.patient.mapper.PatientMapper; @@ -36,12 +40,12 @@ @Component public class TherapyRowMapper extends GenericMapper { - + @Autowired + private PatientMapper patientMapper = new PatientMapper(); public TherapyRowMapper() { super(TherapyRow.class, TherapyRowDTO.class); } - @Autowired - private PatientMapper patientMapper; + @Override public TherapyRow map2Model(TherapyRowDTO toObj) { @@ -53,6 +57,8 @@ public TherapyRow map2Model(TherapyRowDTO toObj) { therapyRow.setMedical(medical); Patient patient = patientMapper.map2Model(toObj.getPatID()); therapyRow.setPatient(patient); + therapyRow.setStartDate(toObj.getStartDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + therapyRow.setEndDate(toObj.getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); return therapyRow; } @@ -64,7 +70,13 @@ public TherapyRowDTO map2DTO(TherapyRow fromObj) { therapyRowDTO.setMedicalId(fromObj.getMedical()); PatientDTO patID = patientMapper.map2DTO(fromObj.getPatient()); therapyRowDTO.setPatID(patID); + Instant instant1 = fromObj.getStartDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date1 = Date.from(instant1); + therapyRowDTO.setStartDate(date1); + Instant instant2 = fromObj.getEndDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date2 = Date.from(instant2); + therapyRowDTO.setEndDate(date2); return therapyRowDTO; } diff --git a/src/main/java/org/isf/therapy/rest/TherapyController.java b/src/main/java/org/isf/therapy/rest/TherapyController.java index 5a92e0ca3..a80fe18a5 100644 --- a/src/main/java/org/isf/therapy/rest/TherapyController.java +++ b/src/main/java/org/isf/therapy/rest/TherapyController.java @@ -21,6 +21,7 @@ */ package org.isf.therapy.rest; +import java.time.ZoneId; import java.util.ArrayList; import java.util.List; @@ -81,6 +82,10 @@ public class TherapyController { */ @PostMapping(value = "/therapies", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity newTherapy(@RequestBody TherapyRowDTO thRowDTO) throws OHServiceException { + if(thRowDTO.getPatID() == null) { + throw new OHAPIException( + new OHExceptionMessage(null, "patient not found!", OHSeverityLevel.ERROR)); + } TherapyRow thRow = therapyRowMapper.map2Model(thRowDTO); thRow = manager.newTherapy(thRow); return ResponseEntity.status(HttpStatus.CREATED).body(therapyRowMapper.map2DTO(thRow)); @@ -93,10 +98,10 @@ public ResponseEntity newTherapy(@RequestBody TherapyRowDTO thRow * @throws OHServiceException */ @PostMapping(value = "/therapies/replace", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity replaceTherapies(@RequestBody @Valid List thRowDTOs) throws OHServiceException { + public ResponseEntity replaceTherapies(@RequestBody @Valid List thRowDTOs) throws OHServiceException { ArrayList therapies = (ArrayList)therapyRowMapper.map2ModelList(thRowDTOs); - boolean done = manager.newTherapies(therapies); - if(done) { + TherapyRow done = manager.newTherapy(therapies.get(0)); + if(done != null) { return ResponseEntity.status(HttpStatus.CREATED).body(done); } else { throw new OHAPIException(new OHExceptionMessage(null, "Therapies are not replaced!", OHSeverityLevel.ERROR)); diff --git a/src/main/java/org/isf/visits/rest/VisitsController.java b/src/main/java/org/isf/visits/rest/VisitsController.java index 73c89f40b..7e2ba9a97 100644 --- a/src/main/java/org/isf/visits/rest/VisitsController.java +++ b/src/main/java/org/isf/visits/rest/VisitsController.java @@ -21,6 +21,7 @@ */ package org.isf.visits.rest; +import java.time.ZoneId; import java.util.ArrayList; import java.util.List; @@ -93,7 +94,9 @@ public ResponseEntity> getVisit(@PathVariable("patID") int patID) @PostMapping(value = "/visit", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity newVisit(@RequestBody VisitDTO newVisit) throws OHServiceException { LOGGER.info("Create Visit: {}", newVisit); - Visit visit = visitManager.newVisit(mapper.map2Model(newVisit)); + Visit visitD = mapper.map2Model(newVisit); + visitD.setDate(newVisit.getDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + Visit visit = visitManager.newVisit(visitD); return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(visit)); //TODO: verify if it's correct } @@ -150,7 +153,7 @@ public ResponseEntity updateVisit(@PathVariable("visitID") int visitID return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); Visit visitUp = mapper.map2Model(updateVisit); - + visitUp.setDate(updateVisit.getDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); //Visit visitUpdate = visitManager.updateVisit(visitUp); Visit visitUpdate = visitManager.newVisit(visitUp); if(visitUpdate == null) From e09fbe599307123c4ace60eb9ebab8be1e51f0e1 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Mon, 13 Jun 2022 15:04:50 +0100 Subject: [PATCH 09/24] update patientMapper --- src/main/java/org/isf/patient/mapper/PatientMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/isf/patient/mapper/PatientMapper.java b/src/main/java/org/isf/patient/mapper/PatientMapper.java index 05062f2da..7d577b85f 100644 --- a/src/main/java/org/isf/patient/mapper/PatientMapper.java +++ b/src/main/java/org/isf/patient/mapper/PatientMapper.java @@ -66,7 +66,7 @@ public PatientDTO map2DTOWS(Patient fromObj, Boolean status) { public Patient map2Model(PatientDTO toObj) { Patient patient = super.map2Model(toObj); - if(patient.getBirthDate() != null) { + if(toObj.getBirthDate() != null) { patient.setBirthDate(toObj.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); } From 1006981c6bd8a02c24538b710402652a09ebac39 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Mon, 13 Jun 2022 15:32:38 +0100 Subject: [PATCH 10/24] update getcurrentAdmission --- .../java/org/isf/admission/rest/AdmissionController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/isf/admission/rest/AdmissionController.java b/src/main/java/org/isf/admission/rest/AdmissionController.java index dd2d02a18..df5567a75 100644 --- a/src/main/java/org/isf/admission/rest/AdmissionController.java +++ b/src/main/java/org/isf/admission/rest/AdmissionController.java @@ -176,7 +176,11 @@ public ResponseEntity getCurrentAdmission(@RequestParam("patientCo if (admission == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } - return ResponseEntity.ok(admissionMapper.map2DTO(admission)); + AdmissionDTO admDTO =admissionMapper.map2DTO(admission); + Instant instant = admission.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = Date.from(instant); + admDTO.setAdmDate(date); + return ResponseEntity.ok(admDTO); } /** From 54a729328759b312a26b16b767b27059cec40f6b Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Mon, 13 Jun 2022 18:08:12 +0100 Subject: [PATCH 11/24] OH2-93 Fix bug about therapie --- src/main/java/org/isf/admission/rest/AdmissionController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/isf/admission/rest/AdmissionController.java b/src/main/java/org/isf/admission/rest/AdmissionController.java index df5567a75..75ab91d4a 100644 --- a/src/main/java/org/isf/admission/rest/AdmissionController.java +++ b/src/main/java/org/isf/admission/rest/AdmissionController.java @@ -332,12 +332,11 @@ public ResponseEntity dischargePatient(@RequestParam("patientCode") int throw new OHAPIException( new OHExceptionMessage(null, "at least one disease must be give!", OHSeverityLevel.ERROR)); } - + adm.setDisDate(currentAdmissionDTO.getDisDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); if (adm.getDisDate() == null) { throw new OHAPIException( new OHExceptionMessage(null, "the exit date must be filled in!", OHSeverityLevel.ERROR)); } - adm.setAdmDate(currentAdmissionDTO.getDisDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); if (adm.getDisDate() == null || !dischargeManager.isCodePresent(adm.getDisType().getCode())) { throw new OHAPIException(new OHExceptionMessage(null, "the type of output is mandatory or does not exist!", OHSeverityLevel.ERROR)); From 496ba9a44700c2000e05811ff3de1e1396100975 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Tue, 14 Jun 2022 09:10:39 +0100 Subject: [PATCH 12/24] Fix-on-backend --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 32dbd8858..81f844f87 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,3 @@ -logging.file=oh-rest-api.log # logging.level.org.springframework.web=DEBUG server.tomcat.accesslog.enabled=true server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms) @@ -8,4 +7,5 @@ server.servlet.context-path=/oh-api spring.main.allow-bean-definition-overriding=true api.host=localhost:8080 api.protocol=http -spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER \ No newline at end of file +spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER +spring.jpa.hibernate.ddl-auto = update \ No newline at end of file From d68b68410267fb1f2e692287eaf910b9862aa6d0 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Tue, 14 Jun 2022 09:50:47 +0100 Subject: [PATCH 13/24] fix bug about test --- src/main/resources/application.properties | 3 +-- .../org/isf/admission/rest/AdmissionControllerTest.java | 5 ++--- src/test/java/org/isf/opd/rest/OpdControllerTest.java | 3 +-- .../org/isf/operation/rest/OperationControllerTest.java | 6 ++---- .../org/isf/vactype/rest/VaccineTypeControllerTest.java | 6 ++---- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 81f844f87..2df4ae6ee 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,5 +7,4 @@ server.servlet.context-path=/oh-api spring.main.allow-bean-definition-overriding=true api.host=localhost:8080 api.protocol=http -spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER -spring.jpa.hibernate.ddl-auto = update \ No newline at end of file +spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER \ No newline at end of file diff --git a/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java b/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java index b3d53ff56..06b80285f 100644 --- a/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java +++ b/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java @@ -342,7 +342,7 @@ public void testDischargeAdmission_200() throws Exception { admission.setDiseaseOut1(disease3); admission.setDisType(dischargeType); - when(admissionManagerMock.updateAdmission(admission)).thenReturn(true); + when(admissionManagerMock.updateAdmission(admission)); AdmissionDTO admDTO = admissionMapper.map2DTO(admission); this.mockMvc @@ -458,8 +458,7 @@ public void testUpdateAdmissions() throws Exception { boolean isUpdated = true; - when(admissionManagerMock.updateAdmission(update)) - .thenReturn(isUpdated); + when(admissionManagerMock.updateAdmission(update)); MvcResult result = this.mockMvc .perform(put(request) diff --git a/src/test/java/org/isf/opd/rest/OpdControllerTest.java b/src/test/java/org/isf/opd/rest/OpdControllerTest.java index de139e62d..a857bba2f 100644 --- a/src/test/java/org/isf/opd/rest/OpdControllerTest.java +++ b/src/test/java/org/isf/opd/rest/OpdControllerTest.java @@ -58,8 +58,7 @@ public void testNewOperation_201() throws Exception { OpdDTO body = opdMapper.map2DTO(opd); boolean isCreated = true; - when(opdBrowserManagerMock.newOpd(opdMapper.map2Model(body))) - .thenReturn(isCreated); + when(opdBrowserManagerMock.newOpd(opdMapper.map2Model(body))); MvcResult result = this.mockMvc .perform(post(request) .contentType(MediaType.APPLICATION_JSON) diff --git a/src/test/java/org/isf/operation/rest/OperationControllerTest.java b/src/test/java/org/isf/operation/rest/OperationControllerTest.java index 2ce576893..1bfcaf588 100644 --- a/src/test/java/org/isf/operation/rest/OperationControllerTest.java +++ b/src/test/java/org/isf/operation/rest/OperationControllerTest.java @@ -72,8 +72,7 @@ public void testNewOperation_201() throws Exception { .thenReturn(false); boolean isCreated = true; - when(operationBrowserManagerMock.newOperation(operationMapper.map2Model(body))) - .thenReturn(isCreated); + when(operationBrowserManagerMock.newOperation(operationMapper.map2Model(body))); when(operationBrowserManagerMock.getOperationByCode(code)) .thenReturn(operation); MvcResult result = this.mockMvc @@ -101,8 +100,7 @@ public void testUpdateOperation_200() throws Exception { .thenReturn(true); boolean isUpdated = true; - when(operationBrowserManagerMock.updateOperation(operation)) - .thenReturn(isUpdated); + when(operationBrowserManagerMock.updateOperation(operation)); MvcResult result = this.mockMvc .perform(put(request, code) diff --git a/src/test/java/org/isf/vactype/rest/VaccineTypeControllerTest.java b/src/test/java/org/isf/vactype/rest/VaccineTypeControllerTest.java index d9dfdb995..556712a40 100644 --- a/src/test/java/org/isf/vactype/rest/VaccineTypeControllerTest.java +++ b/src/test/java/org/isf/vactype/rest/VaccineTypeControllerTest.java @@ -109,8 +109,7 @@ public void testNewVaccineType_200() throws Exception { VaccineTypeDTO body = vaccineTypeMapper.map2DTO(VaccineTypeHelper.setup(code)); boolean isCreated = true; - when(vaccineTypeBrowserManagerMock.newVaccineType(vaccineTypeMapper.map2Model(body))) - .thenReturn(isCreated); + when(vaccineTypeBrowserManagerMock.newVaccineType(vaccineTypeMapper.map2Model(body))); MvcResult result = this.mockMvc .perform(post(request) @@ -132,8 +131,7 @@ public void testUpdateVaccineType_200() throws Exception { VaccineTypeDTO body = vaccineTypeMapper.map2DTO(VaccineTypeHelper.setup(code)); boolean isUpdated = true; - when(vaccineTypeBrowserManagerMock.updateVaccineType(vaccineTypeMapper.map2Model(body))) - .thenReturn(isUpdated); + when(vaccineTypeBrowserManagerMock.updateVaccineType(vaccineTypeMapper.map2Model(body))); MvcResult result = this.mockMvc .perform(put(request) From d29235be1b03922efa3ed1ac24250ca41c0e3bb7 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Tue, 14 Jun 2022 10:47:01 +0100 Subject: [PATCH 14/24] update Test --- .../java/org/isf/admission/rest/AdmissionControllerTest.java | 1 - src/test/java/org/isf/opd/rest/OpdControllerTest.java | 1 - .../java/org/isf/operation/rest/OperationControllerTest.java | 2 -- .../java/org/isf/vactype/rest/VaccineTypeControllerTest.java | 3 +-- 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java b/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java index 06b80285f..f0a84f57a 100644 --- a/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java +++ b/src/test/java/org/isf/admission/rest/AdmissionControllerTest.java @@ -456,7 +456,6 @@ public void testUpdateAdmissions() throws Exception { when(pregTraitTypeManagerMock.getPregnantTreatmentType()) .thenReturn(pregTTypes); - boolean isUpdated = true; when(admissionManagerMock.updateAdmission(update)); diff --git a/src/test/java/org/isf/opd/rest/OpdControllerTest.java b/src/test/java/org/isf/opd/rest/OpdControllerTest.java index a857bba2f..c70831452 100644 --- a/src/test/java/org/isf/opd/rest/OpdControllerTest.java +++ b/src/test/java/org/isf/opd/rest/OpdControllerTest.java @@ -57,7 +57,6 @@ public void testNewOperation_201() throws Exception { Opd opd = OpdHelper.setup(); OpdDTO body = opdMapper.map2DTO(opd); - boolean isCreated = true; when(opdBrowserManagerMock.newOpd(opdMapper.map2Model(body))); MvcResult result = this.mockMvc .perform(post(request) diff --git a/src/test/java/org/isf/operation/rest/OperationControllerTest.java b/src/test/java/org/isf/operation/rest/OperationControllerTest.java index 1bfcaf588..166d8c83c 100644 --- a/src/test/java/org/isf/operation/rest/OperationControllerTest.java +++ b/src/test/java/org/isf/operation/rest/OperationControllerTest.java @@ -71,7 +71,6 @@ public void testNewOperation_201() throws Exception { when(operationBrowserManagerMock.descriptionControl(body.getDescription(), body.getType().getCode())) .thenReturn(false); - boolean isCreated = true; when(operationBrowserManagerMock.newOperation(operationMapper.map2Model(body))); when(operationBrowserManagerMock.getOperationByCode(code)) .thenReturn(operation); @@ -99,7 +98,6 @@ public void testUpdateOperation_200() throws Exception { when(operationBrowserManagerMock.isCodePresent(code)) .thenReturn(true); - boolean isUpdated = true; when(operationBrowserManagerMock.updateOperation(operation)); MvcResult result = this.mockMvc diff --git a/src/test/java/org/isf/vactype/rest/VaccineTypeControllerTest.java b/src/test/java/org/isf/vactype/rest/VaccineTypeControllerTest.java index 556712a40..a04aa3224 100644 --- a/src/test/java/org/isf/vactype/rest/VaccineTypeControllerTest.java +++ b/src/test/java/org/isf/vactype/rest/VaccineTypeControllerTest.java @@ -108,7 +108,6 @@ public void testNewVaccineType_200() throws Exception { String code = "ZZ"; VaccineTypeDTO body = vaccineTypeMapper.map2DTO(VaccineTypeHelper.setup(code)); - boolean isCreated = true; when(vaccineTypeBrowserManagerMock.newVaccineType(vaccineTypeMapper.map2Model(body))); MvcResult result = this.mockMvc @@ -130,7 +129,7 @@ public void testUpdateVaccineType_200() throws Exception { String code = "ZZ"; VaccineTypeDTO body = vaccineTypeMapper.map2DTO(VaccineTypeHelper.setup(code)); - boolean isUpdated = true; + when(vaccineTypeBrowserManagerMock.updateVaccineType(vaccineTypeMapper.map2Model(body))); MvcResult result = this.mockMvc From 37d74a7225afa6e83a307d20ca2446224cd578fd Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Tue, 14 Jun 2022 16:08:24 +0100 Subject: [PATCH 15/24] fix bug about update Lab --- src/main/java/org/isf/lab/rest/LaboratoryController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/isf/lab/rest/LaboratoryController.java b/src/main/java/org/isf/lab/rest/LaboratoryController.java index d8a02c4c7..4c7cb6a05 100644 --- a/src/main/java/org/isf/lab/rest/LaboratoryController.java +++ b/src/main/java/org/isf/lab/rest/LaboratoryController.java @@ -211,6 +211,12 @@ public ResponseEntity updateLaboratory(@PathVariable Integer code, @Req if (labRow != null) { labRows = new ArrayList<>(labRow); } + if (labToInsert.getDate() == null) { + Calendar cal = Calendar.getInstance(); + Date input = cal.getTime(); + LocalDateTime la = input.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + labToInsert.setDate(la); + } labToInsert.setLock(0); boolean updated = laboratoryManager.updateLaboratory(labToInsert, labRows); From 2f959177e8ddd5cb6c33b2086deba20e9a4e0839 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Tue, 14 Jun 2022 18:04:16 +0100 Subject: [PATCH 16/24] update api --- .../examination/rest/ExaminationController.java | 16 +++++++++++++--- .../org/isf/lab/rest/LaboratoryController.java | 15 ++++++++++++++- .../org/isf/visits/rest/VisitsController.java | 15 ++++++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/isf/examination/rest/ExaminationController.java b/src/main/java/org/isf/examination/rest/ExaminationController.java index bacdfcbf0..dffcacdc0 100644 --- a/src/main/java/org/isf/examination/rest/ExaminationController.java +++ b/src/main/java/org/isf/examination/rest/ExaminationController.java @@ -24,6 +24,7 @@ import java.sql.Date; import java.time.Instant; import java.time.ZoneId; +import java.util.ArrayList; import java.util.List; import org.isf.examination.dto.PatientExaminationDTO; @@ -195,11 +196,20 @@ public ResponseEntity> getLastNByPatID(@RequestParam public ResponseEntity> getByPatientId(@PathVariable Integer patId) throws OHServiceException { List patientExamination = examinationBrowserManager.getByPatID(patId); - + List listePExam = new ArrayList(); if (patientExamination == null || patientExamination.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } else { - return ResponseEntity.ok(patientExaminationMapper.map2DTOList(patientExamination)); - } + for(PatientExamination patienExam : patientExamination) { + PatientExaminationDTO patientExamDTO = patientExaminationMapper.map2DTO(patienExam); + Instant instant = patienExam.getPex_date().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + patientExamDTO.setPex_date(date); + listePExam.add(patientExamDTO); + + } + + } + return ResponseEntity.ok(listePExam); } } diff --git a/src/main/java/org/isf/lab/rest/LaboratoryController.java b/src/main/java/org/isf/lab/rest/LaboratoryController.java index 4c7cb6a05..8d63e6c3b 100644 --- a/src/main/java/org/isf/lab/rest/LaboratoryController.java +++ b/src/main/java/org/isf/lab/rest/LaboratoryController.java @@ -21,6 +21,7 @@ */ package org.isf.lab.rest; +import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; @@ -49,6 +50,8 @@ import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; import org.isf.utils.exception.model.OHSeverityLevel; +import org.isf.visits.dto.VisitDTO; +import org.isf.visits.model.Visit; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; @@ -257,10 +260,20 @@ public ResponseEntity> getLaboratory(@PathVariable Integer p } List labList = laboratoryManager.getLaboratory(patient); + List listLab = new ArrayList(); if (labList == null || labList.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } else { - return ResponseEntity.ok(laboratoryMapper.map2DTOList(labList)); + + for(Laboratory lab : labList) { + LaboratoryDTO labDTO = laboratoryMapper.map2DTO(lab); + Instant instant = lab.getDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + labDTO.setExamDate(date); + listLab.add(labDTO); + + } + return ResponseEntity.ok(listLab); } } diff --git a/src/main/java/org/isf/visits/rest/VisitsController.java b/src/main/java/org/isf/visits/rest/VisitsController.java index 7e2ba9a97..c81338ee6 100644 --- a/src/main/java/org/isf/visits/rest/VisitsController.java +++ b/src/main/java/org/isf/visits/rest/VisitsController.java @@ -21,10 +21,15 @@ */ package org.isf.visits.rest; + +import java.time.Instant; import java.time.ZoneId; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import org.isf.examination.dto.PatientExaminationDTO; +import org.isf.examination.model.PatientExamination; import org.isf.shared.exceptions.OHAPIException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; @@ -76,7 +81,15 @@ public VisitsController(VisitManager visitManager, VisitMapper visitMapper) { public ResponseEntity> getVisit(@PathVariable("patID") int patID) throws OHServiceException { LOGGER.info("Get visit related to patId: {}", patID); List visit = visitManager.getVisits(patID); - List listVisit = mapper.map2DTOList(visit); + List listVisit = new ArrayList(); + for(Visit visitP : visit) { + VisitDTO visitDTO = mapper.map2DTO(visitP); + Instant instant = visitP.getDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + visitDTO.setDate(date); + listVisit.add(visitDTO); + + } if (listVisit.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } else { From bc6b4d1d153e44f8cc65c8e793c69cb89c7956ee Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Wed, 15 Jun 2022 08:48:23 +0100 Subject: [PATCH 17/24] update AdmissionController to fix discharge Date in getPatientAdmissions --- .../admission/rest/AdmissionController.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/isf/admission/rest/AdmissionController.java b/src/main/java/org/isf/admission/rest/AdmissionController.java index 75ab91d4a..ebcd1ddf2 100644 --- a/src/main/java/org/isf/admission/rest/AdmissionController.java +++ b/src/main/java/org/isf/admission/rest/AdmissionController.java @@ -24,6 +24,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; +import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; @@ -58,6 +59,8 @@ import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; import org.isf.utils.exception.model.OHSeverityLevel; +import org.isf.visits.dto.VisitDTO; +import org.isf.visits.model.Visit; import org.isf.ward.manager.WardBrowserManager; import org.isf.ward.model.Ward; import org.slf4j.Logger; @@ -242,7 +245,22 @@ public ResponseEntity> getPatientAdmissions(@RequestParam("pa if (admissions.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } - return ResponseEntity.ok(admissionMapper.map2DTOList(admissions)); + List listAdmission = new ArrayList(); + for(Admission adm : admissions) { + AdmissionDTO admission = admissionMapper.map2DTO(adm); + Instant instant = adm.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + admission.setAdmDate(date); + + if(adm.getDisDate() != null) { + Instant instant1 = adm.getDisDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date1 = (Date) Date.from(instant1); + admission.setDisDate(date1); + } + listAdmission.add(admission); + } + + return ResponseEntity.ok(listAdmission); } /** From e7d4b44afd186f0c9fa3f574525ce72bd6202af4 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Wed, 15 Jun 2022 14:31:45 +0100 Subject: [PATCH 18/24] update OpdController to fix date --- src/main/java/org/isf/opd/dto/OpdDTO.java | 2 +- .../java/org/isf/opd/rest/OpdController.java | 40 ++++++++++++++++--- .../isf/operation/dto/OperationRowDTO.java | 8 ++-- .../operation/rest/OperationController.java | 24 +++++++++-- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/isf/opd/dto/OpdDTO.java b/src/main/java/org/isf/opd/dto/OpdDTO.java index 621662b91..0547d43fc 100644 --- a/src/main/java/org/isf/opd/dto/OpdDTO.java +++ b/src/main/java/org/isf/opd/dto/OpdDTO.java @@ -58,7 +58,7 @@ public class OpdDTO { @ApiModelProperty(notes = "the patient age", example = "18", position = 6) private int age; - @NotNull + // @NotNull @ApiModelProperty(notes = "the patient sex", example = "M", position = 7) private char sex; diff --git a/src/main/java/org/isf/opd/rest/OpdController.java b/src/main/java/org/isf/opd/rest/OpdController.java index d4c7e7308..89bff57b0 100644 --- a/src/main/java/org/isf/opd/rest/OpdController.java +++ b/src/main/java/org/isf/opd/rest/OpdController.java @@ -21,12 +21,17 @@ */ package org.isf.opd.rest; +import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; +import java.time.chrono.ChronoLocalDateTime; +import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.isf.admission.dto.AdmissionDTO; +import org.isf.admission.model.Admission; import org.isf.disease.manager.DiseaseBrowserManager; import org.isf.opd.dto.OpdDTO; import org.isf.opd.manager.OpdBrowserManager; @@ -64,6 +69,9 @@ public class OpdController { @Autowired protected OpdBrowserManager opdManager; + @Autowired + private PatientBrowserManager patientManager = new PatientBrowserManager(); + @Autowired protected OpdMapper mapper; @@ -99,11 +107,16 @@ ResponseEntity newOpd(@RequestBody OpdDTO opdDTO) throws OHServiceExcept throw new OHAPIException(new OHExceptionMessage(null, "not field is mandatory!", OHSeverityLevel.ERROR)); } Opd opdToInsert = mapper.map2Model(opdDTO); + opdToInsert.setDate(opdDTO.getDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); Opd isCreated = opdManager.newOpd(opdToInsert); if (isCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Opd is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.OK).body(mapper.map2DTO(isCreated)); + OpdDTO opdDTOs = mapper.map2DTO(isCreated); + Instant instant = isCreated.getDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = Date.from(instant); + opdDTOs.setDate(date); + return ResponseEntity.status(HttpStatus.OK).body(opdDTOs); } /** @@ -130,12 +143,18 @@ ResponseEntity updateOpd(@PathVariable("code") int code, @RequestBody Op } Opd opdToUpdate = mapper.map2Model(opdDTO); + opdToUpdate.setDate(opdDTO.getDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); opdToUpdate.setLock(0); Opd updatedOpd = opdManager.updateOpd(opdToUpdate); if(updatedOpd == null) throw new OHAPIException(new OHExceptionMessage(null, "Opd is not updated!", OHSeverityLevel.ERROR)); - return ResponseEntity.ok(mapper.map2DTO(updatedOpd)); + + OpdDTO opdDTOs = mapper.map2DTO(updatedOpd); + Instant instant = updatedOpd.getDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = Date.from(instant); + opdDTOs.setDate(date); + return ResponseEntity.status(HttpStatus.OK).body(opdDTOs); } /** @@ -195,10 +214,19 @@ public ResponseEntity> getOpdByDates(@RequestParam String diseaseTy * @throws OHServiceException */ @GetMapping(value = "/opds/patient/{pcode}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getOpdByPatient(@PathVariable("pcode") int patientcode) throws OHServiceException { - LOGGER.info("Get opd associated to specified patient CODE: {}", patientcode); - List opds = opdManager.getOpdList(patientcode); - List opdDTOs = mapper.map2DTOList(opds); + public ResponseEntity> getOpdByPatient(@PathVariable("pcode") int pcode) throws OHServiceException { + LOGGER.info("Get opd associated to specified patient CODE: {}", pcode); + + List opds = opdManager.getOpdList(pcode); + List opdDTOs = new ArrayList(); + for(Opd opd : opds) { + OpdDTO admission = mapper.map2DTO(opd); + Instant instant = opd.getDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + admission.setDate(date); + + opdDTOs.add(admission); + } if (opdDTOs.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(opdDTOs); } else { diff --git a/src/main/java/org/isf/operation/dto/OperationRowDTO.java b/src/main/java/org/isf/operation/dto/OperationRowDTO.java index eb2e11790..1752b17dd 100644 --- a/src/main/java/org/isf/operation/dto/OperationRowDTO.java +++ b/src/main/java/org/isf/operation/dto/OperationRowDTO.java @@ -41,16 +41,16 @@ public class OperationRowDTO { private int id; - @NotNull + //@NotNull private OperationDTO operation; - @NotNull + //@NotNull private String prescriber; - @NotNull + //@NotNull private String opResult; - @NotNull + //@NotNull @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") private Date opDate; diff --git a/src/main/java/org/isf/operation/rest/OperationController.java b/src/main/java/org/isf/operation/rest/OperationController.java index aacc6315a..3256f891a 100644 --- a/src/main/java/org/isf/operation/rest/OperationController.java +++ b/src/main/java/org/isf/operation/rest/OperationController.java @@ -21,10 +21,14 @@ */ package org.isf.operation.rest; +import java.time.Instant; import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import org.isf.admission.dto.AdmissionDTO; import org.isf.admission.manager.AdmissionBrowserManager; import org.isf.admission.model.Admission; import org.isf.opd.dto.OpdDTO; @@ -206,7 +210,7 @@ public ResponseEntity deleteOperation(@PathVariable("code") String code * @throws OHServiceException */ @PostMapping(value = "/operations/rows", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity newOperationRow(@RequestBody OperationRowDTO operationRowDTO) throws OHServiceException { + ResponseEntity newOperationRow(@RequestBody OperationRowDTO operationRowDTO) throws OHServiceException { int code = operationRowDTO.getAdmission().getId(); LOGGER.info("Create operation {}", code); if(operationRowDTO.getAdmission() == null && operationRowDTO.getOpd() == null) { @@ -225,7 +229,11 @@ ResponseEntity newOperationRow(@RequestBody OperationRowDTO operationRo if (!isCreated || opCreated == null) { throw new OHAPIException(new OHExceptionMessage(null, "operation row is not created!", OHSeverityLevel.ERROR)); } - return ResponseEntity.status(HttpStatus.CREATED).body(opCreated.getId()); + OperationRowDTO opR = opRowMapper.map2DTO(opCreated); + Instant instant = opRow.getOpDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + opR.setOpDate(date); + return ResponseEntity.status(HttpStatus.CREATED).body(opR); } /** @@ -264,7 +272,17 @@ public ResponseEntity> getOperationRowsByAdmt(@RequestPara LOGGER.info("Get operations row for provided admission"); Admission adm = admissionManager.getAdmission(id); List operationRows = operationRowManager.getOperationRowByAdmission(adm); - List operationRowDTOs = opRowMapper.map2DTOList(operationRows); + List operationRowDTOs = new ArrayList(); + for(OperationRow opRow : operationRows) { + OperationRowDTO opR = opRowMapper.map2DTO(opRow); + if(opRow.getOpDate() != null) { + Instant instant = opRow.getOpDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + opR.setOpDate(date); + } + + operationRowDTOs.add(opR); + } if (operationRowDTOs.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(operationRowDTOs); } else { From 7341197b7229875501fa357d1e58f102b79a0f5f Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Wed, 15 Jun 2022 15:34:30 +0100 Subject: [PATCH 19/24] fix bug about opd --- src/main/java/org/isf/opd/dto/OpdDTO.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/isf/opd/dto/OpdDTO.java b/src/main/java/org/isf/opd/dto/OpdDTO.java index 0547d43fc..eeda1f06e 100644 --- a/src/main/java/org/isf/opd/dto/OpdDTO.java +++ b/src/main/java/org/isf/opd/dto/OpdDTO.java @@ -42,7 +42,7 @@ public class OpdDTO { @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") private Date date; - @NotNull + //@NotNull @ApiModelProperty(notes = "the visit date", position = 3) @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") private Date visitDate; @@ -58,7 +58,7 @@ public class OpdDTO { @ApiModelProperty(notes = "the patient age", example = "18", position = 6) private int age; - // @NotNull + //@NotNull @ApiModelProperty(notes = "the patient sex", example = "M", position = 7) private char sex; @@ -66,7 +66,7 @@ public class OpdDTO { @ApiModelProperty(notes = "the admission note", example = "this is out patient", position = 8) private String note; // ADDED: Alex - @NotNull + // @NotNull @ApiModelProperty(notes = "a progr. in year for each ward", example = "18", position = 9) private int prog_year; From c6af2430ddfefefab0a366bba264f4262bedf0eb Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Wed, 15 Jun 2022 17:00:43 +0100 Subject: [PATCH 20/24] update opdController --- src/main/java/org/isf/opd/rest/OpdController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/isf/opd/rest/OpdController.java b/src/main/java/org/isf/opd/rest/OpdController.java index 89bff57b0..e51ffb316 100644 --- a/src/main/java/org/isf/opd/rest/OpdController.java +++ b/src/main/java/org/isf/opd/rest/OpdController.java @@ -129,9 +129,9 @@ ResponseEntity newOpd(@RequestBody OpdDTO opdDTO) throws OHServiceExcept ResponseEntity updateOpd(@PathVariable("code") int code, @RequestBody OpdDTO opdDTO) throws OHServiceException { LOGGER.info("Update opds code: {}", opdDTO.getCode()); - /* if(opdManager.getOpdByCode(code) == null ) { + if(opdManager.getOpdByCode(code) == null ) { throw new OHAPIException(new OHExceptionMessage(null, "Opd not found!", OHSeverityLevel.ERROR)); - }*/ + } if(opdDTO.getCode() != 0 && opdDTO.getCode() != code) { throw new OHAPIException(new OHExceptionMessage(null, "Opd not found!", OHSeverityLevel.ERROR)); @@ -144,7 +144,7 @@ ResponseEntity updateOpd(@PathVariable("code") int code, @RequestBody Op Opd opdToUpdate = mapper.map2Model(opdDTO); opdToUpdate.setDate(opdDTO.getDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); - opdToUpdate.setLock(0); + opdToUpdate.setLock(opdDTO.getLock()); Opd updatedOpd = opdManager.updateOpd(opdToUpdate); if(updatedOpd == null) From 3771068c03f156513a6126139b0ae591824638f7 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Thu, 23 Jun 2022 09:00:33 +0100 Subject: [PATCH 21/24] last works --- src/main/java/org/isf/opd/rest/OpdController.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/isf/opd/rest/OpdController.java b/src/main/java/org/isf/opd/rest/OpdController.java index e51ffb316..1ae31d25c 100644 --- a/src/main/java/org/isf/opd/rest/OpdController.java +++ b/src/main/java/org/isf/opd/rest/OpdController.java @@ -183,10 +183,11 @@ public ResponseEntity> getOpdToDayOrWeek(@RequestParam(name="oneWee * @throws OHServiceException */ @GetMapping(value = "/opds/search", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getOpdByDates(@RequestParam String diseaseTypeCode, @RequestParam String diseaseCode, + public ResponseEntity> getOpdByDates( @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") Date dateFrom, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") Date dateTo, - @RequestParam int ageFrom, @RequestParam int ageTo, @RequestParam char sex, + @RequestParam String diseaseTypeCode, @RequestParam String diseaseCode, + @RequestParam Integer ageFrom, @RequestParam Integer ageTo, @RequestParam char sex, @RequestParam char newPatient) throws OHServiceException { LOGGER.info("Get opd within specified dates"); LocalDate dateF = null; @@ -198,7 +199,7 @@ public ResponseEntity> getOpdByDates(@RequestParam String diseaseTy if(dateTo != null) { dateT = dateTo.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); } - + List opds = opdManager.getOpd(diseaseTypeCode, diseaseCode, dateF, dateT, ageFrom, ageTo, sex, newPatient); List opdDTOs = mapper.map2DTOList(opds); if (opdDTOs.isEmpty()) { From 55d465500328b58fe3fe221ac7c36c2d202b2768 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Thu, 23 Jun 2022 14:19:45 +0100 Subject: [PATCH 22/24] OH2-102 Adjust getOpdByDates params --- src/main/java/org/isf/opd/rest/OpdController.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/isf/opd/rest/OpdController.java b/src/main/java/org/isf/opd/rest/OpdController.java index 1ae31d25c..7e8ad68c7 100644 --- a/src/main/java/org/isf/opd/rest/OpdController.java +++ b/src/main/java/org/isf/opd/rest/OpdController.java @@ -186,9 +186,11 @@ public ResponseEntity> getOpdToDayOrWeek(@RequestParam(name="oneWee public ResponseEntity> getOpdByDates( @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") Date dateFrom, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") Date dateTo, - @RequestParam String diseaseTypeCode, @RequestParam String diseaseCode, - @RequestParam Integer ageFrom, @RequestParam Integer ageTo, @RequestParam char sex, - @RequestParam char newPatient) throws OHServiceException { + @RequestParam(value = "diseaseTypeCode", required = false, defaultValue = "angal.common.alltypes.txt") String diseaseTypeCode, @RequestParam(value = "diseaseCode", required = false, defaultValue = "angal.opd.alldiseases.txt") String diseaseCode, + @RequestParam(value = "ageFrom", required = false, defaultValue = "0") Integer ageFrom, @RequestParam(value = "ageTo", required = false, defaultValue = "0") Integer ageTo, + @RequestParam(value = "sex", required = false, defaultValue = "A") char sex, + @RequestParam(value = "newPatient", required = false, defaultValue = "A") char newPatient, + @RequestParam(value = "patientCode", required = false, defaultValue = "0") Integer patientCode) throws OHServiceException { LOGGER.info("Get opd within specified dates"); LocalDate dateF = null; if(dateFrom != null) { @@ -199,8 +201,7 @@ public ResponseEntity> getOpdByDates( if(dateTo != null) { dateT = dateTo.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); } - - List opds = opdManager.getOpd(diseaseTypeCode, diseaseCode, dateF, dateT, ageFrom, ageTo, sex, newPatient); + List opds = opdManager.getOpd(diseaseTypeCode, diseaseCode, dateF, dateT, ageFrom, ageTo, sex, newPatient, patientCode); List opdDTOs = mapper.map2DTOList(opds); if (opdDTOs.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(opdDTOs); From 6c8a1f19a00ca52ce0d2747d2423b89b3a02c842 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Sat, 25 Jun 2022 12:09:42 +0100 Subject: [PATCH 23/24] update AdmissionController --- .../admission/rest/AdmissionController.java | 333 ++++++++++-------- 1 file changed, 186 insertions(+), 147 deletions(-) diff --git a/src/main/java/org/isf/admission/rest/AdmissionController.java b/src/main/java/org/isf/admission/rest/AdmissionController.java index ebcd1ddf2..be09fe07c 100644 --- a/src/main/java/org/isf/admission/rest/AdmissionController.java +++ b/src/main/java/org/isf/admission/rest/AdmissionController.java @@ -69,14 +69,17 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; @@ -110,11 +113,11 @@ public class AdmissionController { @Autowired private DeliveryResultTypeBrowserManager dlvrrestTypeManager; - + @Autowired private AdmissionMapper admissionMapper; - - @Autowired + + @Autowired private AdmittedPatientMapper admittedMapper; @Autowired private DischargeTypeBrowserManager dischargeManager; @@ -141,6 +144,7 @@ public AdmissionController(AdmissionBrowserManager admissionManager, PatientBrow this.dischargeManager = dischargeManager; this.dischargeMapper = dischargeMapper; } + /** * Get {@link Admission} for the specified id. * @@ -179,7 +183,7 @@ public ResponseEntity getCurrentAdmission(@RequestParam("patientCo if (admission == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } - AdmissionDTO admDTO =admissionMapper.map2DTO(admission); + AdmissionDTO admDTO = admissionMapper.map2DTO(admission); Instant instant = admission.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); Date date = Date.from(instant); admDTO.setAdmDate(date); @@ -188,6 +192,7 @@ public ResponseEntity getCurrentAdmission(@RequestParam("patientCo /** * Get all admitted {@link Patient}s based on the applied filters. + * * @param searchTerms * @param admissionRange * @param dischargeRange @@ -204,30 +209,31 @@ public ResponseEntity> getAdmittedPatients( LocalDateTime[] admissionR = new LocalDateTime[admissionRange.length]; LocalDateTime[] dischargeR = new LocalDateTime[admissionRange.length]; int i = 0; - for(Date date :admissionRange) { - LocalDateTime dateR = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); - admissionR[i]=dateR; + for (Date date : admissionRange) { + LocalDateTime dateR = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + admissionR[i] = dateR; i++; } - + int j = 0; - for(Date date :dischargeRange) { - LocalDateTime dateD = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); - dischargeR[j]=dateD; + for (Date date : dischargeRange) { + LocalDateTime dateD = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + dischargeR[j] = dateD; j++; } - - List admittedPatients = admissionManager - .getAdmittedPatients(admissionR, dischargeR, searchTerms); + + List admittedPatients = admissionManager.getAdmittedPatients(admissionR, dischargeR, + searchTerms); if (admittedPatients.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } - + return ResponseEntity.ok(admittedMapper.map2DTOList(admittedPatients)); } /** * Get all the {@link Admission}s for the specified {@link Patient} code. + * * @param patientCode * @return the {@link List} of found {@link Admission} or NO_CONTENT otherwise. * @throws OHServiceException @@ -246,43 +252,45 @@ public ResponseEntity> getPatientAdmissions(@RequestParam("pa return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } List listAdmission = new ArrayList(); - for(Admission adm : admissions) { - AdmissionDTO admission = admissionMapper.map2DTO(adm); - Instant instant = adm.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); - Date date = (Date) Date.from(instant); - admission.setAdmDate(date); - - if(adm.getDisDate() != null) { - Instant instant1 = adm.getDisDate().atZone(ZoneId.systemDefault()).toInstant(); - Date date1 = (Date) Date.from(instant1); - admission.setDisDate(date1); - } - listAdmission.add(admission); - } - + for (Admission adm : admissions) { + AdmissionDTO admission = admissionMapper.map2DTO(adm); + Instant instant = adm.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date = (Date) Date.from(instant); + admission.setAdmDate(date); + + if (adm.getDisDate() != null) { + Instant instant1 = adm.getDisDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date1 = (Date) Date.from(instant1); + admission.setDisDate(date1); + } + listAdmission.add(admission); + } + return ResponseEntity.ok(listAdmission); } /** * Get the next prog in the year for specified {@link Ward} code. + * * @param wardCode * @return the next prog. * @throws OHServiceException */ @GetMapping(value = "/admissions/getNextProgressiveIdInYear", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getNextYProg(@RequestParam("wardcode") String wardCode) - throws OHServiceException { + public ResponseEntity getNextYProg(@RequestParam("wardcode") String wardCode) throws OHServiceException { LOGGER.info("get the next prog in the year for ward code: {}", wardCode); - + if (wardCode.trim().isEmpty() || !wardManager.isCodePresent(wardCode)) { - throw new OHAPIException(new OHExceptionMessage(null, "Ward not found for code:" + wardCode, OHSeverityLevel.ERROR)); + throw new OHAPIException( + new OHExceptionMessage(null, "Ward not found for code:" + wardCode, OHSeverityLevel.ERROR)); } - + return ResponseEntity.ok(admissionManager.getNextYProg(wardCode)); } - + /** * Get the number of used beds for the specified {@link Ward} code. + * * @param wardCode * @return the number of used beds. * @throws OHServiceException @@ -292,14 +300,16 @@ public ResponseEntity getUsedWardBed(@RequestParam("wardid") String war LOGGER.info("Counts the number of used bed for ward code: {}", wardCode); if (wardCode.trim().isEmpty() || !wardManager.isCodePresent(wardCode)) { - throw new OHAPIException( new OHExceptionMessage(null, "Ward not found for code:" + wardCode, OHSeverityLevel.ERROR)); + throw new OHAPIException( + new OHExceptionMessage(null, "Ward not found for code:" + wardCode, OHSeverityLevel.ERROR)); } return ResponseEntity.ok(admissionManager.getUsedWardBed(wardCode)); } - + /** * Set an {@link Admission} record to deleted. + * * @param id * @return true if the record has been set to delete. * @throws OHServiceException @@ -317,6 +327,7 @@ public ResponseEntity deleteAdmissionType(@PathVariable int id) throws return ResponseEntity.ok(isDeleted); } + /** * discharge the {@link Admission}s for the specified {@link Patient} code. * @@ -342,7 +353,7 @@ public ResponseEntity dischargePatient(@RequestParam("patientCode") int Admission adm = admissionMapper.map2Model(currentAdmissionDTO); adm.setAdmDate(currentAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); - + if (adm == null || admission.getId() != adm.getId()) return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); @@ -360,18 +371,20 @@ public ResponseEntity dischargePatient(@RequestParam("patientCode") int OHSeverityLevel.ERROR)); } adm.setAdmitted(0); - if(admissionManager.updateAdmission(adm)!= null) { - + if (admissionManager.updateAdmission(adm) != null) { + bol = true; } - + return ResponseEntity.status(HttpStatus.OK).body(bol); } /** * Create a new {@link Admission}. + * * @param newAdmissionDTO - * @return the generated id or null for the created {@link Admission}. + * @return the generated id or null for the created + * {@link Admission}. * @throws OHServiceException */ @PostMapping(value = "/admissions", produces = MediaType.APPLICATION_JSON_VALUE) @@ -379,19 +392,24 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA throws OHServiceException { Admission newAdmission = admissionMapper.map2Model(newAdmissionDTO); - newAdmission.setAdmDate(newAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); - if(newAdmissionDTO.getAbortDate() != null) { - newAdmission.setAbortDate(newAdmissionDTO.getAbortDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); - } - if(newAdmissionDTO.getCtrlDate1() != null) { - newAdmission.setCtrlDate1(newAdmissionDTO.getCtrlDate1().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); - } - if(newAdmissionDTO.getCtrlDate2() != null) { - newAdmission.setCtrlDate2(newAdmissionDTO.getCtrlDate2().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); - } - if(newAdmissionDTO.getOpDate() != null) { - newAdmission.setOpDate(newAdmissionDTO.getOpDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); - } + newAdmission + .setAdmDate(newAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + if (newAdmissionDTO.getAbortDate() != null) { + newAdmission.setAbortDate( + newAdmissionDTO.getAbortDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + } + if (newAdmissionDTO.getCtrlDate1() != null) { + newAdmission.setCtrlDate1( + newAdmissionDTO.getCtrlDate1().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + } + if (newAdmissionDTO.getCtrlDate2() != null) { + newAdmission.setCtrlDate2( + newAdmissionDTO.getCtrlDate2().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + } + if (newAdmissionDTO.getOpDate() != null) { + newAdmission.setOpDate( + newAdmissionDTO.getOpDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + } if (newAdmissionDTO.getWard() != null && newAdmissionDTO.getWard().getCode() != null && !newAdmissionDTO.getWard().getCode().trim().isEmpty()) { List wards = wardManager.getWards().stream() @@ -431,39 +449,46 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA Disease diseases = null; if (newAdmissionDTO.getDiseaseIn() != null && newAdmissionDTO.getDiseaseIn().getCode() != null) { diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseIn().getCode()); - + if (diseases == null) { throw new OHAPIException(new OHExceptionMessage(null, "Disease in not found!", OHSeverityLevel.ERROR)); } newAdmission.setDiseaseIn(diseases); - } - + } + if (newAdmissionDTO.getDiseaseOut1() != null && newAdmissionDTO.getDiseaseOut1().getCode() != null) { - if (diseases == null) diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseOut1().getCode()); - + if (diseases == null) + diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseOut1().getCode()); + if (diseases == null) { - throw new OHAPIException(new OHExceptionMessage(null, "Disease out 1 not found!", OHSeverityLevel.ERROR)); + throw new OHAPIException( + new OHExceptionMessage(null, "Disease out 1 not found!", OHSeverityLevel.ERROR)); } newAdmission.setDiseaseOut1(diseases); - } - + } + if (newAdmissionDTO.getDiseaseOut2() != null && newAdmissionDTO.getDiseaseOut2().getCode() != null) { - if (diseases == null) diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseOut2().getCode()); + if (diseases == null) + diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseOut2().getCode()); if (diseases == null) { - throw new OHAPIException(new OHExceptionMessage(null, "Disease out 2 not found!", OHSeverityLevel.ERROR)); + throw new OHAPIException( + new OHExceptionMessage(null, "Disease out 2 not found!", OHSeverityLevel.ERROR)); } newAdmission.setDiseaseOut2(diseases); - } - + } + if (newAdmissionDTO.getDiseaseOut3() != null && newAdmissionDTO.getDiseaseOut3().getCode() != null) { - if (diseases == null) diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseOut3().getCode()); + if (diseases == null) + diseases = diseaseManager.getDiseaseByCode(newAdmissionDTO.getDiseaseOut3().getCode()); if (diseases == null) { - throw new OHAPIException(new OHExceptionMessage(null, "Disease out 3 not found!", OHSeverityLevel.ERROR)); + throw new OHAPIException( + new OHExceptionMessage(null, "Disease out 3 not found!", OHSeverityLevel.ERROR)); } newAdmission.setDiseaseOut3(diseases); - } - - if (newAdmissionDTO.getOperation() != null && newAdmissionDTO.getOperation().getCode() != null && !newAdmissionDTO.getOperation().getCode().trim().isEmpty()) { + } + + if (newAdmissionDTO.getOperation() != null && newAdmissionDTO.getOperation().getCode() != null + && !newAdmissionDTO.getOperation().getCode().trim().isEmpty()) { List operations = operationManager.getOperation(); List opFounds = operations.stream() .filter(op -> op.getCode().equals(newAdmissionDTO.getOperation().getCode())) @@ -474,7 +499,8 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA newAdmission.setOperation(opFounds.get(0)); } - if (newAdmissionDTO.getDisType() != null && newAdmissionDTO.getDisType().getCode() != null && !newAdmissionDTO.getDisType().getCode().trim().isEmpty()) { + if (newAdmissionDTO.getDisType() != null && newAdmissionDTO.getDisType().getCode() != null + && !newAdmissionDTO.getDisType().getCode().trim().isEmpty()) { List disTypes = admissionManager.getDischargeType(); List disTypesF = disTypes.stream() .filter(dtp -> dtp.getCode().equals(newAdmissionDTO.getDisType().getCode())) @@ -486,7 +512,8 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA newAdmission.setDisType(disTypesF.get(0)); } - if (newAdmissionDTO.getPregTreatmentType() != null && newAdmissionDTO.getPregTreatmentType().getCode() != null && !newAdmissionDTO.getPregTreatmentType().getCode().trim().isEmpty()) { + if (newAdmissionDTO.getPregTreatmentType() != null && newAdmissionDTO.getPregTreatmentType().getCode() != null + && !newAdmissionDTO.getPregTreatmentType().getCode().trim().isEmpty()) { List pregTTypes = pregTraitTypeManager.getPregnantTreatmentType(); List pregTTypesF = pregTTypes.stream() .filter(pregtt -> pregtt.getCode().equals(newAdmissionDTO.getPregTreatmentType().getCode())) @@ -498,7 +525,8 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA newAdmission.setPregTreatmentType(pregTTypesF.get(0)); } - if (newAdmissionDTO.getDeliveryType() != null && newAdmissionDTO.getDeliveryType().getCode() != null && !newAdmissionDTO.getDeliveryType().getCode().trim().isEmpty()) { + if (newAdmissionDTO.getDeliveryType() != null && newAdmissionDTO.getDeliveryType().getCode() != null + && !newAdmissionDTO.getDeliveryType().getCode().trim().isEmpty()) { List dlvrTypes = dlvrTypeManager.getDeliveryType(); List dlvrTypesF = dlvrTypes.stream() .filter(dlvrType -> dlvrType.getCode().equals(newAdmissionDTO.getDeliveryType().getCode())) @@ -510,10 +538,11 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA newAdmission.setDeliveryType(dlvrTypesF.get(0)); } - if (newAdmissionDTO.getDeliveryResult() != null && newAdmissionDTO.getDeliveryResult().getCode() != null && !newAdmissionDTO.getDeliveryResult().getCode().trim().isEmpty()) { + if (newAdmissionDTO.getDeliveryResult() != null && newAdmissionDTO.getDeliveryResult().getCode() != null + && !newAdmissionDTO.getDeliveryResult().getCode().trim().isEmpty()) { List dlvrrestTypes = dlvrrestTypeManager.getDeliveryResultType(); - List dlvrrestTypesF = dlvrrestTypes.stream() - .filter(dlvrrestType -> dlvrrestType.getCode().equals(newAdmissionDTO.getDeliveryResult().getCode())) + List dlvrrestTypesF = dlvrrestTypes.stream().filter( + dlvrrestType -> dlvrrestType.getCode().equals(newAdmissionDTO.getDeliveryResult().getCode())) .collect(Collectors.toList()); if (dlvrrestTypesF.isEmpty()) { throw new OHAPIException( @@ -537,22 +566,30 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newA return ResponseEntity.status(HttpStatus.CREATED).body(admDTO); } + @ExceptionHandler + @ResponseStatus(HttpStatus.BAD_REQUEST) + public void handle(HttpMessageNotReadableException e) { + e.printStackTrace(); + } + /** * Updates the specified {@link Admission} object. + * * @param updAdmissionDTO * @return true if has been updated, false otherwise. * @throws OHServiceException */ @PutMapping(value = "/admissions", produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmissionDTO) throws OHServiceException { - + Admission old = admissionManager.getAdmission(updAdmissionDTO.getId()); if (old == null) { throw new OHAPIException(new OHExceptionMessage(null, "Admission not found!", OHSeverityLevel.ERROR)); } Admission updAdmission = admissionMapper.map2Model(updAdmissionDTO); - updAdmission.setAdmDate(updAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); - + updAdmission + .setAdmDate(updAdmissionDTO.getAdmDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + if (updAdmissionDTO.getWard() != null && updAdmissionDTO.getWard().getCode() != null && !updAdmissionDTO.getWard().getCode().trim().isEmpty()) { List wards = wardManager.getWards().stream() @@ -589,52 +626,51 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmis } else { throw new OHAPIException(new OHExceptionMessage(null, "Patient field is required!", OHSeverityLevel.ERROR)); } - List diseases = null; - if (updAdmissionDTO.getDiseaseIn() != null && updAdmissionDTO.getDiseaseIn().getCode() != null ) { - diseases = diseaseManager.getDisease(); - List dIns = diseases.stream() - .filter(d -> d.getCode().equals(updAdmissionDTO.getDiseaseIn().getCode())) - .collect(Collectors.toList()); - if (dIns.isEmpty()) { + Disease diseases = null; + if (updAdmissionDTO.getDiseaseIn() != null && updAdmissionDTO.getDiseaseIn().getCode() != null) { + diseases = diseaseManager.getDiseaseByCode(updAdmissionDTO.getDiseaseIn().getCode()); + + if (diseases == null) { throw new OHAPIException(new OHExceptionMessage(null, "Disease in not found!", OHSeverityLevel.ERROR)); } - updAdmission.setDiseaseIn(dIns.get(0)); - } - + updAdmission.setDiseaseIn(diseases); + } + if (updAdmissionDTO.getDiseaseOut1() != null && updAdmissionDTO.getDiseaseOut1().getCode() != null) { - if (diseases == null) diseases = diseaseManager.getDisease(); - List dOut1s = diseases.stream() - .filter(d -> d.getCode().equals(updAdmissionDTO.getDiseaseOut1().getCode())) - .collect(Collectors.toList()); - if (dOut1s.isEmpty()) { - throw new OHAPIException(new OHExceptionMessage(null, "Disease out 1 not found!", OHSeverityLevel.ERROR)); + if (diseases == null) + diseases = diseaseManager.getDiseaseByCode(updAdmissionDTO.getDiseaseOut1().getCode()); + + if (diseases == null) { + throw new OHAPIException( + new OHExceptionMessage(null, "Disease out 1 not found!", OHSeverityLevel.ERROR)); } - updAdmission.setDiseaseOut1(dOut1s.get(0)); - } - + updAdmission.setDiseaseOut1(diseases); + } + if (updAdmissionDTO.getDiseaseOut2() != null && updAdmissionDTO.getDiseaseOut2().getCode() != null) { - if (diseases == null) diseases = diseaseManager.getDisease(); - List dOut2s = diseases.stream() - .filter(d -> d.getCode().equals(updAdmissionDTO.getDiseaseOut2().getCode()) ) - .collect(Collectors.toList()); - if (dOut2s.isEmpty()) { - throw new OHAPIException(new OHExceptionMessage(null, "Disease out 2 not found!", OHSeverityLevel.ERROR)); + if (diseases == null) + diseases = diseaseManager.getDiseaseByCode(updAdmissionDTO.getDiseaseOut2().getCode()); + + if (diseases == null) { + throw new OHAPIException( + new OHExceptionMessage(null, "Disease out 1 not found!", OHSeverityLevel.ERROR)); } - updAdmission.setDiseaseOut2(dOut2s.get(0)); - } - + updAdmission.setDiseaseOut2(diseases); + } + if (updAdmissionDTO.getDiseaseOut3() != null && updAdmissionDTO.getDiseaseOut3().getCode() != null) { - if (diseases == null) diseases = diseaseManager.getDisease(); - List dOut3s = diseases.stream() - .filter(d -> d.getCode().equals(updAdmissionDTO.getDiseaseOut3().getCode())) - .collect(Collectors.toList()); - if (dOut3s.isEmpty()) { - throw new OHAPIException(new OHExceptionMessage(null, "Disease out 3 not found!", OHSeverityLevel.ERROR)); + if (diseases == null) + diseases = diseaseManager.getDiseaseByCode(updAdmissionDTO.getDiseaseOut2().getCode()); + + if (diseases == null) { + throw new OHAPIException( + new OHExceptionMessage(null, "Disease out 1 not found!", OHSeverityLevel.ERROR)); } - updAdmission.setDiseaseOut3(dOut3s.get(0)); - } - - if (updAdmissionDTO.getOperation() != null && updAdmissionDTO.getOperation().getCode() != null && !updAdmissionDTO.getOperation().getCode().trim().isEmpty()) { + updAdmission.setDiseaseOut3(diseases); + } + + if (updAdmissionDTO.getOperation() != null && updAdmissionDTO.getOperation().getCode() != null + && !updAdmissionDTO.getOperation().getCode().trim().isEmpty()) { List operations = operationManager.getOperation(); List opFounds = operations.stream() .filter(op -> op.getCode().equals(updAdmissionDTO.getOperation().getCode())) @@ -645,7 +681,8 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmis updAdmission.setOperation(opFounds.get(0)); } - if (updAdmissionDTO.getDisType() != null && updAdmissionDTO.getDisType().getCode() != null && !updAdmissionDTO.getDisType().getCode().trim().isEmpty()) { + if (updAdmissionDTO.getDisType() != null && updAdmissionDTO.getDisType().getCode() != null + && !updAdmissionDTO.getDisType().getCode().trim().isEmpty()) { List disTypes = admissionManager.getDischargeType(); List disTypesF = disTypes.stream() .filter(dtp -> dtp.getCode().equals(updAdmissionDTO.getDisType().getCode())) @@ -657,7 +694,8 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmis updAdmission.setDisType(disTypesF.get(0)); } - if (updAdmissionDTO.getPregTreatmentType() != null && updAdmissionDTO.getPregTreatmentType().getCode() != null && !updAdmissionDTO.getPregTreatmentType().getCode().trim().isEmpty()) { + if (updAdmissionDTO.getPregTreatmentType() != null && updAdmissionDTO.getPregTreatmentType().getCode() != null + && !updAdmissionDTO.getPregTreatmentType().getCode().trim().isEmpty()) { List pregTTypes = pregTraitTypeManager.getPregnantTreatmentType(); List pregTTypesF = pregTTypes.stream() .filter(pregtt -> pregtt.getCode().equals(updAdmissionDTO.getPregTreatmentType().getCode())) @@ -669,7 +707,8 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmis updAdmission.setPregTreatmentType(pregTTypesF.get(0)); } - if (updAdmissionDTO.getDeliveryType() != null && updAdmissionDTO.getDeliveryType().getCode() != null && !updAdmissionDTO.getDeliveryType().getCode().trim().isEmpty()) { + if (updAdmissionDTO.getDeliveryType() != null && updAdmissionDTO.getDeliveryType().getCode() != null + && !updAdmissionDTO.getDeliveryType().getCode().trim().isEmpty()) { List dlvrTypes = dlvrTypeManager.getDeliveryType(); List dlvrTypesF = dlvrTypes.stream() .filter(dlvrType -> dlvrType.getCode().equals(updAdmissionDTO.getDeliveryType().getCode())) @@ -681,10 +720,11 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmis updAdmission.setDeliveryType(dlvrTypesF.get(0)); } - if (updAdmissionDTO.getDeliveryResult() != null && updAdmissionDTO.getDeliveryResult().getCode() != null && !updAdmissionDTO.getDeliveryResult().getCode().trim().isEmpty()) { + if (updAdmissionDTO.getDeliveryResult() != null && updAdmissionDTO.getDeliveryResult().getCode() != null + && !updAdmissionDTO.getDeliveryResult().getCode().trim().isEmpty()) { List dlvrrestTypes = dlvrrestTypeManager.getDeliveryResultType(); - List dlvrrestTypesF = dlvrrestTypes.stream() - .filter(dlvrrestType -> dlvrrestType.getCode().equals(updAdmissionDTO.getDeliveryResult().getCode())) + List dlvrrestTypesF = dlvrrestTypes.stream().filter( + dlvrrestType -> dlvrrestType.getCode().equals(updAdmissionDTO.getDeliveryResult().getCode())) .collect(Collectors.toList()); if (dlvrrestTypesF.isEmpty()) { throw new OHAPIException( @@ -698,38 +738,37 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updAdmis : updAdmission.getPatient().getName(); LOGGER.info("update admission for patient {}", name); Admission isUpdated = admissionManager.updateAdmission(updAdmission); - + if (isUpdated == null) { throw new OHAPIException(new OHExceptionMessage(null, "Admission is not updated!", OHSeverityLevel.ERROR)); } - - AdmissionDTO admDTO= admissionMapper.map2DTO(isUpdated); + + AdmissionDTO admDTO = admissionMapper.map2DTO(isUpdated); Instant instant = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); Date date = Date.from(instant); admDTO.setAdmDate(date); - - if(admDTO.getAbortDate() != null) { + + if (admDTO.getAbortDate() != null) { Instant instant1 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); Date date1 = Date.from(instant1); admDTO.setAbortDate(date1); - } - if(admDTO.getCtrlDate1() != null) { - Instant instant2 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); - Date date1 = Date.from(instant2); - admDTO.setAbortDate(date1); - } - if(admDTO.getCtrlDate2() != null) { - Instant instant3 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); - Date date2 = Date.from(instant3); - admDTO.setAbortDate(date2); - } - if(admDTO.getOpDate() != null) { - Instant instant4 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); - Date date3 = Date.from(instant4); - admDTO.setAbortDate(date3); - } + } + if (admDTO.getCtrlDate1() != null) { + Instant instant2 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date1 = Date.from(instant2); + admDTO.setAbortDate(date1); + } + if (admDTO.getCtrlDate2() != null) { + Instant instant3 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date2 = Date.from(instant3); + admDTO.setAbortDate(date2); + } + if (admDTO.getOpDate() != null) { + Instant instant4 = isUpdated.getAdmDate().atZone(ZoneId.systemDefault()).toInstant(); + Date date3 = Date.from(instant4); + admDTO.setAbortDate(date3); + } return ResponseEntity.ok(admDTO); } - } From 0357c8ab26ce357523affa6b24494bdff04d0106 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Mon, 27 Jun 2022 18:01:58 +0100 Subject: [PATCH 24/24] OH2-103 Add patient-related properties to OpdDTO --- src/main/java/org/isf/opd/dto/OpdDTO.java | 15 ++++++++++++++- src/main/java/org/isf/opd/mapper/OpdMapper.java | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/isf/opd/dto/OpdDTO.java b/src/main/java/org/isf/opd/dto/OpdDTO.java index eeda1f06e..6b6cdcf1a 100644 --- a/src/main/java/org/isf/opd/dto/OpdDTO.java +++ b/src/main/java/org/isf/opd/dto/OpdDTO.java @@ -58,9 +58,14 @@ public class OpdDTO { @ApiModelProperty(notes = "the patient age", example = "18", position = 6) private int age; - //@NotNull + @NotNull @ApiModelProperty(notes = "the patient sex", example = "M", position = 7) private char sex; + + //@NotNull + @ApiModelProperty(notes = "the patient sex", example = "M", position = 7) + private String patientName; + @NotNull @ApiModelProperty(notes = "the admission note", example = "this is out patient", position = 8) @@ -178,6 +183,14 @@ public Date getVisitDate() { return this.visitDate; } + public String getPatientName() { + return patientName; + } + + public void setPatientName(String patientName) { + this.patientName = patientName; + } + public Date getNextVisitDate() { return this.nextVisitDate; } diff --git a/src/main/java/org/isf/opd/mapper/OpdMapper.java b/src/main/java/org/isf/opd/mapper/OpdMapper.java index 3d7c0ca84..759b38a63 100644 --- a/src/main/java/org/isf/opd/mapper/OpdMapper.java +++ b/src/main/java/org/isf/opd/mapper/OpdMapper.java @@ -47,6 +47,7 @@ public OpdDTO map2DTO(Opd fromObj) { OpdDTO opdDTO = super.map2DTO(fromObj); if (fromObj.getPatient() != null) { opdDTO.setPatientCode(fromObj.getPatient().getCode()); + opdDTO.setPatientName(fromObj.getFullName()); } return opdDTO;