From 11fb4d18fceca0e0f82b0eedce34b83c9ca80707 Mon Sep 17 00:00:00 2001 From: SilverD3 Date: Fri, 1 Nov 2024 15:53:40 +0100 Subject: [PATCH] chore: OH2-415 | Add endpoint to update age types --- openapi/oh.yaml | 816 +++++++++--------- .../isf/agetype/rest/AgeTypeController.java | 39 +- .../agetype/rest/AgeTypeControllerTest.java | 33 +- 3 files changed, 455 insertions(+), 433 deletions(-) diff --git a/openapi/oh.yaml b/openapi/oh.yaml index 40afbffe..e5b6940b 100644 --- a/openapi/oh.yaml +++ b/openapi/oh.yaml @@ -1904,7 +1904,9 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/AgeTypeDTO" + type: array + items: + $ref: "#/components/schemas/AgeTypeDTO" required: true responses: "200": @@ -1912,7 +1914,9 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/AgeTypeDTO" + type: array + items: + $ref: "#/components/schemas/AgeTypeDTO" security: - bearerAuth: [] /admissiontypes: @@ -6235,13 +6239,13 @@ components: description: lock format: int32 example: 0 - opd: + pharmacy: type: boolean male: type: boolean female: type: boolean - pharmacy: + opd: type: boolean PatientDTO: required: @@ -6953,11 +6957,11 @@ components: type: string description: "Flag record deleted, values are 'Y' OR 'N' " example: "N" + fhu: + type: string yprog: type: integer format: int32 - fhu: - type: string description: The admission AdmissionTypeDTO: required: @@ -8000,10 +8004,10 @@ components: $ref: "#/components/schemas/PatientProfilePhoto" patientConsensus: $ref: "#/components/schemas/PatientConsensus" - informations: - type: string searchString: type: string + informations: + type: string PatientConsensus: type: object properties: @@ -8082,163 +8086,6 @@ components: transparency: type: integer format: int32 - clipBounds: - type: object - properties: - x: - type: number - format: double - "y": - type: number - format: double - width: - type: number - format: double - height: - type: number - format: double - empty: - type: boolean - location: - type: object - properties: - x: - type: number - format: double - "y": - type: number - format: double - size: - type: object - properties: - width: - type: number - format: double - height: - type: number - format: double - bounds2D: - type: object - properties: - empty: - type: boolean - width: - type: number - format: double - height: - type: number - format: double - maxX: - type: number - format: double - maxY: - type: number - format: double - centerX: - type: number - format: double - centerY: - type: number - format: double - minX: - type: number - format: double - minY: - type: number - format: double - "y": - type: number - format: double - x: - type: number - format: double - rect: - type: object - properties: - empty: - type: boolean - width: - type: number - format: double - height: - type: number - format: double - maxX: - type: number - format: double - maxY: - type: number - format: double - centerX: - type: number - format: double - centerY: - type: number - format: double - minX: - type: number - format: double - minY: - type: number - format: double - "y": - type: number - format: double - x: - type: number - format: double - writeOnly: true - maxX: - type: number - format: double - maxY: - type: number - format: double - centerX: - type: number - format: double - centerY: - type: number - format: double - minX: - type: number - format: double - minY: - type: number - format: double - xormode: - type: object - properties: - red: - type: integer - format: int32 - green: - type: integer - format: int32 - blue: - type: integer - format: int32 - alpha: - type: integer - format: int32 - colorSpace: - type: object - properties: - type: - type: integer - format: int32 - numComponents: - type: integer - format: int32 - cs_sRGB: - type: boolean - rgb: - type: integer - format: int32 - transparency: - type: integer - format: int32 - writeOnly: true font: type: object properties: @@ -8258,6 +8105,8 @@ components: type: string plain: type: boolean + fontName: + type: string transform: type: object properties: @@ -8284,6 +8133,9 @@ components: format: int32 identity: type: boolean + determinant: + type: number + format: double toRotation: type: number format: double @@ -8292,11 +8144,6 @@ components: type: integer format: int32 writeOnly: true - determinant: - type: number - format: double - fontName: - type: string bold: type: boolean italic: @@ -8321,71 +8168,373 @@ components: type: array items: type: object - clip: + fontMetrics: type: object properties: - bounds: + font: type: object properties: - x: - type: number - format: double - "y": - type: number - format: double - width: - type: number - format: double - height: - type: number - format: double - empty: + name: + type: string + style: + type: integer + format: int32 + size: + type: integer + format: int32 + attributes: + type: object + additionalProperties: + type: object + family: + type: string + plain: type: boolean - location: + fontName: + type: string + transform: type: object properties: - x: - type: number - format: double - "y": + scaleX: type: number format: double - size: - type: object - properties: - width: + shearY: type: number format: double - height: + shearX: type: number format: double - bounds2D: - type: object - properties: - empty: - type: boolean - width: + scaleY: type: number format: double - height: + translateX: type: number format: double - maxX: + translateY: type: number format: double - maxY: + type: + type: integer + format: int32 + identity: + type: boolean + determinant: type: number format: double - centerX: + toRotation: type: number format: double - centerY: - type: number + writeOnly: true + toQuadrantRotation: + type: integer + format: int32 + writeOnly: true + bold: + type: boolean + italic: + type: boolean + numGlyphs: + type: integer + format: int32 + missingGlyphCode: + type: integer + format: int32 + italicAngle: + type: number + format: float + transformed: + type: boolean + psname: + type: string + size2D: + type: number + format: float + availableAttributes: + type: array + items: + type: object + ascent: + type: integer + format: int32 + descent: + type: integer + format: int32 + leading: + type: integer + format: int32 + maxDescent: + type: integer + format: int32 + widths: + type: array + items: + type: integer + format: int32 + fontRenderContext: + type: object + properties: + antiAliased: + type: boolean + transformType: + type: integer + format: int32 + transform: + type: object + properties: + scaleX: + type: number format: double - minX: + shearY: + type: number + format: double + shearX: + type: number + format: double + scaleY: + type: number + format: double + translateX: + type: number + format: double + translateY: + type: number + format: double + type: + type: integer + format: int32 + identity: + type: boolean + determinant: + type: number + format: double + toRotation: + type: number + format: double + writeOnly: true + toQuadrantRotation: + type: integer + format: int32 + writeOnly: true + antiAliasingHint: + type: object + fractionalMetricsHint: + type: object + transformed: + type: boolean + maxAscent: + type: integer + format: int32 + maxDecent: + type: integer + format: int32 + deprecated: true + maxAdvance: + type: integer + format: int32 + height: + type: integer + format: int32 + clipBounds: + type: object + properties: + x: + type: number + format: double + "y": + type: number + format: double + width: + type: number + format: double + height: + type: number + format: double + empty: + type: boolean + location: + type: object + properties: + x: + type: number + format: double + "y": + type: number + format: double + size: + type: object + properties: + width: + type: number + format: double + height: + type: number + format: double + bounds2D: + type: object + properties: + empty: + type: boolean + width: + type: number + format: double + "y": + type: number + format: double + x: + type: number + format: double + maxX: + type: number + format: double + maxY: + type: number + format: double + centerX: + type: number + format: double + centerY: + type: number + format: double + height: + type: number + format: double + minX: + type: number + format: double + minY: + type: number + format: double + rect: + type: object + properties: + empty: + type: boolean + width: + type: number + format: double + "y": + type: number + format: double + x: + type: number + format: double + maxX: + type: number + format: double + maxY: + type: number + format: double + centerX: + type: number + format: double + centerY: + type: number + format: double + height: + type: number + format: double + minX: + type: number + format: double + minY: + type: number + format: double + writeOnly: true + maxX: + type: number + format: double + maxY: + type: number + format: double + centerX: + type: number + format: double + centerY: + type: number + format: double + minX: + type: number + format: double + minY: + type: number + format: double + xormode: + type: object + properties: + red: + type: integer + format: int32 + green: + type: integer + format: int32 + blue: + type: integer + format: int32 + alpha: + type: integer + format: int32 + colorSpace: + type: object + properties: + type: + type: integer + format: int32 + numComponents: + type: integer + format: int32 + cs_sRGB: + type: boolean + rgb: + type: integer + format: int32 + transparency: + type: integer + format: int32 + writeOnly: true + clip: + type: object + properties: + bounds: + type: object + properties: + x: + type: number + format: double + "y": + type: number + format: double + width: + type: number + format: double + height: + type: number + format: double + empty: + type: boolean + location: + type: object + properties: + x: + type: number + format: double + "y": + type: number + format: double + size: + type: object + properties: + width: + type: number + format: double + height: type: number format: double - minY: + bounds2D: + type: object + properties: + empty: + type: boolean + width: type: number format: double "y": @@ -8394,6 +8543,27 @@ components: x: type: number format: double + maxX: + type: number + format: double + maxY: + type: number + format: double + centerX: + type: number + format: double + centerY: + type: number + format: double + height: + type: number + format: double + minX: + type: number + format: double + minY: + type: number + format: double rect: type: object properties: @@ -8402,7 +8572,10 @@ components: width: type: number format: double - height: + "y": + type: number + format: double + x: type: number format: double maxX: @@ -8417,16 +8590,13 @@ components: centerY: type: number format: double - minX: - type: number - format: double - minY: + height: type: number format: double - "y": + minX: type: number format: double - x: + minY: type: number format: double writeOnly: true @@ -8456,7 +8626,10 @@ components: width: type: number format: double - height: + "y": + type: number + format: double + x: type: number format: double maxX: @@ -8471,16 +8644,13 @@ components: centerY: type: number format: double - minX: - type: number - format: double - minY: + height: type: number format: double - "y": + minX: type: number format: double - x: + minY: type: number format: double clipRect: @@ -8526,7 +8696,10 @@ components: width: type: number format: double - height: + "y": + type: number + format: double + x: type: number format: double maxX: @@ -8541,16 +8714,13 @@ components: centerY: type: number format: double - minX: - type: number - format: double - minY: + height: type: number format: double - "y": + minX: type: number format: double - x: + minY: type: number format: double rect: @@ -8561,7 +8731,10 @@ components: width: type: number format: double - height: + "y": + type: number + format: double + x: type: number format: double maxX: @@ -8576,16 +8749,13 @@ components: centerY: type: number format: double - minX: - type: number - format: double - minY: + height: type: number format: double - "y": + minX: type: number format: double - x: + minY: type: number format: double writeOnly: true @@ -8608,172 +8778,6 @@ components: type: number format: double deprecated: true - fontMetrics: - type: object - properties: - font: - type: object - properties: - name: - type: string - style: - type: integer - format: int32 - size: - type: integer - format: int32 - attributes: - type: object - additionalProperties: - type: object - family: - type: string - plain: - type: boolean - transform: - type: object - properties: - scaleX: - type: number - format: double - shearY: - type: number - format: double - shearX: - type: number - format: double - scaleY: - type: number - format: double - translateX: - type: number - format: double - translateY: - type: number - format: double - type: - type: integer - format: int32 - identity: - type: boolean - toRotation: - type: number - format: double - writeOnly: true - toQuadrantRotation: - type: integer - format: int32 - writeOnly: true - determinant: - type: number - format: double - fontName: - type: string - bold: - type: boolean - italic: - type: boolean - numGlyphs: - type: integer - format: int32 - missingGlyphCode: - type: integer - format: int32 - italicAngle: - type: number - format: float - transformed: - type: boolean - psname: - type: string - size2D: - type: number - format: float - availableAttributes: - type: array - items: - type: object - height: - type: integer - format: int32 - ascent: - type: integer - format: int32 - descent: - type: integer - format: int32 - leading: - type: integer - format: int32 - maxDescent: - type: integer - format: int32 - widths: - type: array - items: - type: integer - format: int32 - fontRenderContext: - type: object - properties: - antiAliased: - type: boolean - transformType: - type: integer - format: int32 - transform: - type: object - properties: - scaleX: - type: number - format: double - shearY: - type: number - format: double - shearX: - type: number - format: double - scaleY: - type: number - format: double - translateX: - type: number - format: double - translateY: - type: number - format: double - type: - type: integer - format: int32 - identity: - type: boolean - toRotation: - type: number - format: double - writeOnly: true - toQuadrantRotation: - type: integer - format: int32 - writeOnly: true - determinant: - type: number - format: double - antiAliasingHint: - type: object - fractionalMetricsHint: - type: object - transformed: - type: boolean - maxAscent: - type: integer - format: int32 - maxDecent: - type: integer - format: int32 - deprecated: true - maxAdvance: - type: integer - format: int32 TherapyRow: required: - endDate @@ -8835,13 +8839,13 @@ components: smsInt: type: integer format: int32 - medical: - type: integer - format: int32 notify: type: boolean sms: type: boolean + medical: + type: integer + format: int32 TherapyDTO: type: object properties: diff --git a/src/main/java/org/isf/agetype/rest/AgeTypeController.java b/src/main/java/org/isf/agetype/rest/AgeTypeController.java index 9d0f96d1..01aea84f 100644 --- a/src/main/java/org/isf/agetype/rest/AgeTypeController.java +++ b/src/main/java/org/isf/agetype/rest/AgeTypeController.java @@ -89,24 +89,37 @@ public ResponseEntity> getAllAgeTypes() throws OHServiceExcepti /** * Update an age type - * @param ageTypeDTO - the age type to be updated + * @param ageTypeDTOs - the list of age types to be updated * @return {@link AgeTypeDTO} the updated age type - * @throws OHServiceException + * @throws OHServiceException When failed to update age type */ @PutMapping(value = "/agetypes", produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity updateAgeType(@Valid @RequestBody AgeTypeDTO ageTypeDTO) throws OHServiceException { - if (ageTypeDTO.getCode() == null || ageTypeDTO.getCode().trim().isEmpty()) { - throw new OHAPIException(new OHExceptionMessage("The age type is not valid.")); - } - LOGGER.info("Update age type"); - AgeType ageType = mapper.map2Model(ageTypeDTO); - List ageTypes = new ArrayList<>(); - ageTypes.add(ageType); + public List updateAgeType(@Valid @RequestBody List ageTypeDTOs) throws OHServiceException { + + ageTypeDTOs.forEach(ageTypeDTO -> { + try { + if (ageTypeDTO.getCode() == null || ageTypeDTO.getCode().trim().isEmpty() || ageTypeManager.getTypeByCode(ageTypeDTO.getCode()) == null) { + try { + throw new OHAPIException(new OHExceptionMessage("The age type with code "+ageTypeDTO.getCode()+" is not valid.")); + } catch (OHAPIException e) { + throw new RuntimeException(e); + } + } + } catch (OHServiceException e) { + throw new RuntimeException(e); + } + }); + + LOGGER.info("Updating age types"); + List ageTypes = mapper.map2ModelList(ageTypeDTOs); + try { - ageTypeManager.updateAgeType(ageTypes); - return ResponseEntity.ok(ageTypeDTO); + return mapper.map2DTOList(ageTypeManager.updateAgeType(ageTypes)); } catch (OHServiceException ex) { - throw new OHAPIException(new OHExceptionMessage("The age type is not updated."), HttpStatus.INTERNAL_SERVER_ERROR); + throw new OHAPIException( + new OHExceptionMessage("Unable to update age types. Please check that you've correctly set values"), + HttpStatus.INTERNAL_SERVER_ERROR + ); } } diff --git a/src/test/java/org/isf/agetype/rest/AgeTypeControllerTest.java b/src/test/java/org/isf/agetype/rest/AgeTypeControllerTest.java index 448ed7d9..8826a6d5 100644 --- a/src/test/java/org/isf/agetype/rest/AgeTypeControllerTest.java +++ b/src/test/java/org/isf/agetype/rest/AgeTypeControllerTest.java @@ -22,6 +22,8 @@ package org.isf.agetype.rest; import static org.hamcrest.Matchers.containsString; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; 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.put; @@ -55,6 +57,8 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import com.fasterxml.jackson.databind.ObjectMapper; + public class AgeTypeControllerTest { private static final Logger LOGGER = LoggerFactory.getLogger(AgeTypeControllerTest.class); @@ -64,6 +68,8 @@ public class AgeTypeControllerTest { private final AgeTypeMapper ageTypeMapper = new AgeTypeMapper(); + private final ObjectMapper objectMapper = new ObjectMapper(); + private MockMvc mockMvc; private AutoCloseable closeable; @@ -110,23 +116,22 @@ public void testGetAllAgeTypes_200() throws Exception { @Test public void testUpdateAgeType_200() throws Exception { String request = "/agetypes"; - AgeTypeDTO body = ageTypeMapper.map2DTO(AgeTypeHelper.setup()); + List ageTypes = AgeTypeHelper.genList(5); + List body = ageTypeMapper.map2DTOList(ageTypes); - List ageTypes = new ArrayList<>(); - ageTypes.add(AgeTypeHelper.setup()); - - when(ageTypeManagerMock.updateAgeType(ageTypes)) - .thenReturn(ageTypes); + when(ageTypeManagerMock.getTypeByCode(anyString())).thenReturn(ageTypes.get(0)); + when(ageTypeManagerMock.getTypeByCode(anyInt())).thenReturn(ageTypes.get(0)); + when(ageTypeManagerMock.updateAgeType(ageTypes)).thenReturn(ageTypes); MvcResult result = this.mockMvc - .perform(put(request) - .contentType(MediaType.APPLICATION_JSON) - .content(Objects.requireNonNull(AgeTypeHelper.asJsonString(body))) - ) - .andDo(log()) - .andExpect(status().is2xxSuccessful()) - .andExpect(status().isOk()) - .andReturn(); + .perform(put(request) + .contentType(MediaType.APPLICATION_JSON) + .content(Objects.requireNonNull(objectMapper.writeValueAsString(body))) + ) + .andDo(log()) + .andExpect(status().isOk()) + .andExpect(content().string(containsString(objectMapper.writeValueAsString(body)))) + .andReturn(); LOGGER.debug("result: {}", result); }