Skip to content

Commit

Permalink
[#257] Provide for updating consepts to Numeric datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruhanga committed Dec 7, 2023
1 parent 65e4661 commit 8cf782b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 8cf782b

Please sign in to comment.