@Test public void convert_shouldConvertString() { Regimen regimen1 = converter.convert("C$84309AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA|300|mg|OD"); Assert.assertEquals(1, regimen1.getComponents().size()); Assert.assertEquals(new Integer(84309), regimen1.getComponents().get(0).getDrugRef().getConcept().getConceptId()); Assert.assertEquals(new Double(300.0), regimen1.getComponents().get(0).getDose()); Assert.assertEquals("mg", regimen1.getComponents().get(0).getUnits()); Assert.assertEquals("OD", regimen1.getComponents().get(0).getFrequency()); Regimen regimen2 = converter.convert("C$84309AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA|300|mg|OD|D$97810e6b-cfcf-44fa-b63c-5d3e12cbe8d7|150|ml|BD"); Assert.assertEquals(2, regimen2.getComponents().size()); Assert.assertEquals(new Integer(84309), regimen2.getComponents().get(0).getDrugRef().getConcept().getConceptId()); Assert.assertEquals(new Double(300.0), regimen2.getComponents().get(0).getDose()); Assert.assertEquals("mg", regimen2.getComponents().get(0).getUnits()); Assert.assertEquals("OD", regimen2.getComponents().get(0).getFrequency()); Assert.assertEquals(new Integer(200004), regimen2.getComponents().get(1).getDrugRef().getDrug().getDrugId()); Assert.assertEquals(new Double(150.0), regimen2.getComponents().get(1).getDose()); Assert.assertEquals("ml", regimen2.getComponents().get(1).getUnits()); Assert.assertEquals("BD", regimen2.getComponents().get(1).getFrequency()); Regimen regimen3 = converter.convert("C$84309AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA||mg|"); Assert.assertEquals(1, regimen3.getComponents().size()); Assert.assertEquals(new Integer(84309), regimen3.getComponents().get(0).getDrugRef().getConcept().getConceptId()); Assert.assertNull(regimen3.getComponents().get(0).getDose()); Assert.assertEquals("mg", regimen3.getComponents().get(0).getUnits()); Assert.assertNull(regimen3.getComponents().get(0).getFrequency()); Regimen regimen4 = converter.convert("C$84309AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA| |mg| "); Assert.assertEquals(1, regimen4.getComponents().size()); Assert.assertEquals(new Integer(84309), regimen4.getComponents().get(0).getDrugRef().getConcept().getConceptId()); Assert.assertNull(regimen4.getComponents().get(0).getDose()); Assert.assertEquals("mg", regimen4.getComponents().get(0).getUnits()); Assert.assertNull(regimen4.getComponents().get(0).getFrequency()); }
@Override public Regimen convert(String source) { String[] tokens = source.split("\\|", -1); Queue<String> tokenQueue = new LinkedList<String>(Arrays.asList(tokens)); Regimen regimen = new Regimen(); while (tokenQueue.size() >= 4) { String drugRefStr = tokenQueue.remove().trim(); String doseStr = tokenQueue.remove().trim(); String units = tokenQueue.remove().trim(); String frequency = tokenQueue.remove().trim(); DrugReference drugRef = StringUtils.isNotEmpty(drugRefStr) ? drugReferenceConverter.convert(drugRefStr) : null; Double dose = StringUtils.isNotEmpty(doseStr) ? Double.parseDouble(doseStr) : null; units = StringUtils.isNotEmpty(units) ? units : null; frequency = StringUtils.isNotEmpty(frequency) ? frequency : null; regimen.getComponents().add(new RegimenComponent(drugRef, dose, units, frequency)); } return regimen; }
StringToRegimenConverter implements Converter<String, Regimen> { @Override public Regimen convert(String source) { String[] tokens = source.split("\\|", -1); Queue<String> tokenQueue = new LinkedList<String>(Arrays.asList(tokens)); Regimen regimen = new Regimen(); while (tokenQueue.size() >= 4) { String drugRefStr = tokenQueue.remove().trim(); String doseStr = tokenQueue.remove().trim(); String units = tokenQueue.remove().trim(); String frequency = tokenQueue.remove().trim(); DrugReference drugRef = StringUtils.isNotEmpty(drugRefStr) ? drugReferenceConverter.convert(drugRefStr) : null; Double dose = StringUtils.isNotEmpty(doseStr) ? Double.parseDouble(doseStr) : null; units = StringUtils.isNotEmpty(units) ? units : null; frequency = StringUtils.isNotEmpty(frequency) ? frequency : null; regimen.getComponents().add(new RegimenComponent(drugRef, dose, units, frequency)); } return regimen; } }
StringToRegimenConverter implements Converter<String, Regimen> { @Override public Regimen convert(String source) { String[] tokens = source.split("\\|", -1); Queue<String> tokenQueue = new LinkedList<String>(Arrays.asList(tokens)); Regimen regimen = new Regimen(); while (tokenQueue.size() >= 4) { String drugRefStr = tokenQueue.remove().trim(); String doseStr = tokenQueue.remove().trim(); String units = tokenQueue.remove().trim(); String frequency = tokenQueue.remove().trim(); DrugReference drugRef = StringUtils.isNotEmpty(drugRefStr) ? drugReferenceConverter.convert(drugRefStr) : null; Double dose = StringUtils.isNotEmpty(doseStr) ? Double.parseDouble(doseStr) : null; units = StringUtils.isNotEmpty(units) ? units : null; frequency = StringUtils.isNotEmpty(frequency) ? frequency : null; regimen.getComponents().add(new RegimenComponent(drugRef, dose, units, frequency)); } return regimen; }  }
StringToRegimenConverter implements Converter<String, Regimen> { @Override public Regimen convert(String source) { String[] tokens = source.split("\\|", -1); Queue<String> tokenQueue = new LinkedList<String>(Arrays.asList(tokens)); Regimen regimen = new Regimen(); while (tokenQueue.size() >= 4) { String drugRefStr = tokenQueue.remove().trim(); String doseStr = tokenQueue.remove().trim(); String units = tokenQueue.remove().trim(); String frequency = tokenQueue.remove().trim(); DrugReference drugRef = StringUtils.isNotEmpty(drugRefStr) ? drugReferenceConverter.convert(drugRefStr) : null; Double dose = StringUtils.isNotEmpty(doseStr) ? Double.parseDouble(doseStr) : null; units = StringUtils.isNotEmpty(units) ? units : null; frequency = StringUtils.isNotEmpty(frequency) ? frequency : null; regimen.getComponents().add(new RegimenComponent(drugRef, dose, units, frequency)); } return regimen; }  @Override Regimen convert(String source); }
StringToRegimenConverter implements Converter<String, Regimen> { @Override public Regimen convert(String source) { String[] tokens = source.split("\\|", -1); Queue<String> tokenQueue = new LinkedList<String>(Arrays.asList(tokens)); Regimen regimen = new Regimen(); while (tokenQueue.size() >= 4) { String drugRefStr = tokenQueue.remove().trim(); String doseStr = tokenQueue.remove().trim(); String units = tokenQueue.remove().trim(); String frequency = tokenQueue.remove().trim(); DrugReference drugRef = StringUtils.isNotEmpty(drugRefStr) ? drugReferenceConverter.convert(drugRefStr) : null; Double dose = StringUtils.isNotEmpty(doseStr) ? Double.parseDouble(doseStr) : null; units = StringUtils.isNotEmpty(units) ? units : null; frequency = StringUtils.isNotEmpty(frequency) ? frequency : null; regimen.getComponents().add(new RegimenComponent(drugRef, dose, units, frequency)); } return regimen; }  @Override Regimen convert(String source);  }