@Test public void findDefinitions_shouldFindDefinitionsForRegimen() { DrugOrder lamivudine = new DrugOrder(); lamivudine.setConcept(Context.getConceptService().getConcept(78643)); lamivudine.setDose(150d); lamivudine.setUnits("mg"); lamivudine.setFrequency("BD"); DrugOrder stavudine = new DrugOrder(); stavudine.setConcept(Context.getConceptService().getConcept(84309)); stavudine.setDose(30d); stavudine.setUnits("mg"); stavudine.setFrequency("OD"); RegimenOrder regimen = new RegimenOrder(new HashSet<DrugOrder>(Arrays.asList(lamivudine, stavudine))); List<RegimenDefinition> defsExact = regimenManager.findDefinitions("category1", regimen, true); Assert.assertEquals(1, defsExact.size()); Assert.assertEquals("regimen2", defsExact.get(0).getName()); List<RegimenDefinition> defsNonExact = regimenManager.findDefinitions("category1", regimen, false); Assert.assertEquals(2, defsNonExact.size()); Assert.assertEquals("regimen2", defsNonExact.get(0).getName()); Assert.assertEquals("regimen3", defsNonExact.get(1).getName()); }
public List<RegimenDefinition> findDefinitions(String category, RegimenOrder regimenOrder, boolean exact) { List<RegimenDefinitionGroup> groups = regimenGroups.get(category); if (groups == null) { throw new IllegalArgumentException("No such category: " + category); } List<RegimenDefinition> matches = new ArrayList<RegimenDefinition>(); for (RegimenDefinitionGroup group : groups) { outer: for (RegimenDefinition definition : group.getRegimens()) { List<RegimenComponent> regimen = definition.getComponents(); Set<DrugOrder> orders = regimenOrder.getDrugOrders(); if (regimen.size() != orders.size()) { continue; } for (RegimenComponent component : regimen) { boolean regimenHasComponent = false; for (DrugOrder order : orders) { DrugReference componentDrugRef = component.getDrugRef(); DrugReference orderDrugRef = DrugReference.fromDrugOrder(order); if (componentDrugRef.equals(orderDrugRef)) { if (!exact || (ObjectUtils.equals(order.getDose(), component.getDose()) && StringUtils.equals(order.getUnits(), component.getUnits()) && StringUtils.equals(order.getFrequency(), component.getFrequency()))) { regimenHasComponent = true; break; } } } if (!regimenHasComponent) { continue outer; } } matches.add(definition); } } return matches; }
RegimenManager implements ContentManager { public List<RegimenDefinition> findDefinitions(String category, RegimenOrder regimenOrder, boolean exact) { List<RegimenDefinitionGroup> groups = regimenGroups.get(category); if (groups == null) { throw new IllegalArgumentException("No such category: " + category); } List<RegimenDefinition> matches = new ArrayList<RegimenDefinition>(); for (RegimenDefinitionGroup group : groups) { outer: for (RegimenDefinition definition : group.getRegimens()) { List<RegimenComponent> regimen = definition.getComponents(); Set<DrugOrder> orders = regimenOrder.getDrugOrders(); if (regimen.size() != orders.size()) { continue; } for (RegimenComponent component : regimen) { boolean regimenHasComponent = false; for (DrugOrder order : orders) { DrugReference componentDrugRef = component.getDrugRef(); DrugReference orderDrugRef = DrugReference.fromDrugOrder(order); if (componentDrugRef.equals(orderDrugRef)) { if (!exact || (ObjectUtils.equals(order.getDose(), component.getDose()) && StringUtils.equals(order.getUnits(), component.getUnits()) && StringUtils.equals(order.getFrequency(), component.getFrequency()))) { regimenHasComponent = true; break; } } } if (!regimenHasComponent) { continue outer; } } matches.add(definition); } } return matches; } }
RegimenManager implements ContentManager { public List<RegimenDefinition> findDefinitions(String category, RegimenOrder regimenOrder, boolean exact) { List<RegimenDefinitionGroup> groups = regimenGroups.get(category); if (groups == null) { throw new IllegalArgumentException("No such category: " + category); } List<RegimenDefinition> matches = new ArrayList<RegimenDefinition>(); for (RegimenDefinitionGroup group : groups) { outer: for (RegimenDefinition definition : group.getRegimens()) { List<RegimenComponent> regimen = definition.getComponents(); Set<DrugOrder> orders = regimenOrder.getDrugOrders(); if (regimen.size() != orders.size()) { continue; } for (RegimenComponent component : regimen) { boolean regimenHasComponent = false; for (DrugOrder order : orders) { DrugReference componentDrugRef = component.getDrugRef(); DrugReference orderDrugRef = DrugReference.fromDrugOrder(order); if (componentDrugRef.equals(orderDrugRef)) { if (!exact || (ObjectUtils.equals(order.getDose(), component.getDose()) && StringUtils.equals(order.getUnits(), component.getUnits()) && StringUtils.equals(order.getFrequency(), component.getFrequency()))) { regimenHasComponent = true; break; } } } if (!regimenHasComponent) { continue outer; } } matches.add(definition); } } return matches; }  }
RegimenManager implements ContentManager { public List<RegimenDefinition> findDefinitions(String category, RegimenOrder regimenOrder, boolean exact) { List<RegimenDefinitionGroup> groups = regimenGroups.get(category); if (groups == null) { throw new IllegalArgumentException("No such category: " + category); } List<RegimenDefinition> matches = new ArrayList<RegimenDefinition>(); for (RegimenDefinitionGroup group : groups) { outer: for (RegimenDefinition definition : group.getRegimens()) { List<RegimenComponent> regimen = definition.getComponents(); Set<DrugOrder> orders = regimenOrder.getDrugOrders(); if (regimen.size() != orders.size()) { continue; } for (RegimenComponent component : regimen) { boolean regimenHasComponent = false; for (DrugOrder order : orders) { DrugReference componentDrugRef = component.getDrugRef(); DrugReference orderDrugRef = DrugReference.fromDrugOrder(order); if (componentDrugRef.equals(orderDrugRef)) { if (!exact || (ObjectUtils.equals(order.getDose(), component.getDose()) && StringUtils.equals(order.getUnits(), component.getUnits()) && StringUtils.equals(order.getFrequency(), component.getFrequency()))) { regimenHasComponent = true; break; } } } if (!regimenHasComponent) { continue outer; } } matches.add(definition); } } return matches; }  @Override int getPriority(); @Override synchronized void refresh(); Set<String> getCategoryCodes(); Concept getMasterSetConcept(String category); Collection<DrugReference> getDrugs(String category); List<RegimenDefinitionGroup> getRegimenGroups(String category); List<RegimenDefinition> findDefinitions(String category, RegimenOrder regimenOrder, boolean exact); void loadDefinitionsFromXML(InputStream stream); }
RegimenManager implements ContentManager { public List<RegimenDefinition> findDefinitions(String category, RegimenOrder regimenOrder, boolean exact) { List<RegimenDefinitionGroup> groups = regimenGroups.get(category); if (groups == null) { throw new IllegalArgumentException("No such category: " + category); } List<RegimenDefinition> matches = new ArrayList<RegimenDefinition>(); for (RegimenDefinitionGroup group : groups) { outer: for (RegimenDefinition definition : group.getRegimens()) { List<RegimenComponent> regimen = definition.getComponents(); Set<DrugOrder> orders = regimenOrder.getDrugOrders(); if (regimen.size() != orders.size()) { continue; } for (RegimenComponent component : regimen) { boolean regimenHasComponent = false; for (DrugOrder order : orders) { DrugReference componentDrugRef = component.getDrugRef(); DrugReference orderDrugRef = DrugReference.fromDrugOrder(order); if (componentDrugRef.equals(orderDrugRef)) { if (!exact || (ObjectUtils.equals(order.getDose(), component.getDose()) && StringUtils.equals(order.getUnits(), component.getUnits()) && StringUtils.equals(order.getFrequency(), component.getFrequency()))) { regimenHasComponent = true; break; } } } if (!regimenHasComponent) { continue outer; } } matches.add(definition); } } return matches; }  @Override int getPriority(); @Override synchronized void refresh(); Set<String> getCategoryCodes(); Concept getMasterSetConcept(String category); Collection<DrugReference> getDrugs(String category); List<RegimenDefinitionGroup> getRegimenGroups(String category); List<RegimenDefinition> findDefinitions(String category, RegimenOrder regimenOrder, boolean exact); void loadDefinitionsFromXML(InputStream stream);  }