From 8cf782bcaa805e67358115cbff4d0cece72b8ff9 Mon Sep 17 00:00:00 2001 From: ruhanga Date: Wed, 6 Dec 2023 15:08:30 +0300 Subject: [PATCH] [#257] Provide for updating consepts to Numeric datatype --- .../api/c/ConceptNumericLineProcessor.java | 7 ++++++- .../c/ConceptNumericLineProcessorTest.java | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessor.java b/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessor.java index da25b8025..25ac69fc4 100644 --- a/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessor.java +++ b/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessor.java @@ -42,10 +42,15 @@ public Concept fill(Concept instance, CsvLine line) throws IllegalArgumentExcept return instance; } - ConceptNumeric cn = new ConceptNumeric(instance); + ConceptNumeric cn = null; if (instance.getId() != null) { // below overrides any other processors work, so this one should be called first cn = conceptService.getConceptNumeric(instance.getId()); } + + if (cn == null) { + cn = new ConceptNumeric(instance); + } + cn.setDatatype(conceptService.getConceptDatatypeByName(DATATYPE_NUMERIC)); cn.setHiAbsolute(line.getDouble(HEADER_AH)); diff --git a/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessorTest.java b/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessorTest.java index 8eb2da7e1..63fbd313c 100644 --- a/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessorTest.java +++ b/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessorTest.java @@ -1,7 +1,9 @@ package org.openmrs.module.initializer.api.c; import static org.mockito.Matchers.any; +import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.junit.Assert; @@ -89,4 +91,22 @@ public void fill_shouldFailWhenCannotParse() { ConceptNumericLineProcessor p = new ConceptNumericLineProcessor(cs); p.fill(new Concept(), new CsvLine(headerLine, line)); } + + @Test + public void fill_shouldOverrideProvidedDataType() { + + // Setup + when(cs.getConceptNumeric(any(Integer.class))).thenReturn(null); + String[] headerLine = { "Data type", "Absolute low" }; + String[] line = { "Numeric", "11.11" }; + + // Replay + ConceptNumericLineProcessor p = new ConceptNumericLineProcessor(cs); + ConceptNumeric cn = (ConceptNumeric) p.fill(new Concept(1), new CsvLine(headerLine, line)); + + // Verify + verify(cs, atLeast(1)).getConceptNumeric(any(Integer.class)); + Assert.assertEquals(ConceptNumericLineProcessor.DATATYPE_NUMERIC, cn.getDatatype().getName()); + Assert.assertEquals(0, cn.getLowAbsolute().compareTo(11.11)); + } }