private void open() { OrderSpecimenVoCollection potentialSpecimens = form.getGlobalContext().OCRR.getMyOrderPotentialSpecimens(); // Sort potential specimens potentialSpecimens.sort(); // Build alternative containers hash map HashMap<OrderSpecimenVo, HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection>> alternativeContainers = buildHashMapOfAlternativeContainers(potentialSpecimens); // Check for alternative options if (!choicesAvailable(alternativeContainers)) { engine.close(DialogResult.CANCEL); return; } populateSpecimensWithAlternateContainers(potentialSpecimens, alternativeContainers); }
private void initialise() { if (form.getGlobalContext().OCRR.getSpecimenContainers() == null) return; for (PathSpecimenContainerDetailVo container : form.getGlobalContext().OCRR.getSpecimenContainers()) { StringBuffer containerName = new StringBuffer(); containerName.append(container.getName()); containerName.append(" ( Cap: "); if (container.getVolume() != null) { containerName.append(container.getVolume()); containerName.append(" )"); } else { containerName.append("N/A )"); } form.cmbContainer().newRow(container, containerName.toString()); } }
private void populateSpecimensWithAlternateContainers(OrderSpecimenVoCollection potentialSpecimens, HashMap<OrderSpecimenVo, HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection>> alternativeContainers) { // Clear grid form.grdItems().getRows().clear(); if (potentialSpecimens == null) return; for (OrderSpecimenVo specimen : potentialSpecimens) { HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection> specimenAlternateContainers = alternativeContainers.get(specimen); if (specimenHasOptions(specimenAlternateContainers)) { // Create Specimen parent row grdItemsRow specimenRow = form.grdItems().getRows().newRow(); // Add investigation rows float totalRequiredVolume = addInvestigationsWithAlternates(specimen.getInvestigations(), specimenRow, specimenAlternateContainers); // Set specimen text specimenRow.setColText(getSpecimenDisplayText(specimen, totalRequiredVolume)); // Expand Specimen parent row specimenRow.setExpanded(true); } } }
private boolean choicesAvailable(HashMap<OrderSpecimenVo, HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection>> alternativeContainers) { Collection<HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection>> specimenMaps = alternativeContainers.values(); for (HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection> specimenMap : specimenMaps) { if (specimenHasOptions(specimenMap)) return true; } return false; }
private boolean specimenHasOptions(HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection> specimenAlternateContainers) { Set<PathSpecimenContainerDetailVo> keys = specimenAlternateContainers.keySet(); for (PathSpecimenContainerDetailVo specimenContainer : keys) { OrderInvestigationVoCollection values = specimenAlternateContainers.get(specimenContainer); if (values != null && values.size() > 1) { for (OrderInvestigationVo investigation : values) { PathInvDetailsVo pathologyDetails = null; if (investigation.getInvestigation().getParentInvestigationPathDetails() != null) { pathologyDetails = investigation.getInvestigation().getParentInvestigationPathDetails(); } else { pathologyDetails = investigation.getInvestigation().getPathInvDetails(); } SpecimenVo specimenVo = pathologyDetails.getSpecimens().get(0); if (specimenVo.getAlternativePaediatricContainers() != null) { for (SpecimenContainerVo container : specimenVo.getAlternativePaediatricContainers()) { if (container.getSpecContainer().equals(specimenContainer)) return true; } } } } } return false; }
private float addInvestigationsWithAlternates(OrderInvestigationRefVoCollection investigations, grdItemsRow specimenRow, HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection> alternativeContainers) { if (investigations == null || investigations.size() == 0) throw new CodingRuntimeException("Logical Error - can't choose alternative containers for specimens without investigations"); float totalRequiedVolume = 0; for (OrderInvestigationRefVo investigationRef : investigations) { // Upcast - possible error, but done due to performance consideration OrderInvestigationVo investigation = (OrderInvestigationVo) investigationRef; // Get investigation pathology details // Favor parent investigation Pathology Details - this might indicate an add-on investigation PathInvDetailsVo pathologyDetails = null; if (investigation.getInvestigation().getParentInvestigationPathDetails() != null) { pathologyDetails = investigation.getInvestigation().getParentInvestigationPathDetails(); } else { pathologyDetails = investigation.getInvestigation().getPathInvDetails(); } // Create child row for OrderInvestigationVo grdItemsRow investigationRow = specimenRow.getRows().newRow(); // Set investigation name and value to row investigationRow.setColText(getInvestigationDisplayText(investigation, pathologyDetails)); investigationRow.setValue(investigation); boolean isPaed = isUsePaedContainer(); if (isPaed) { // Get specimen from pathology details - implementation only for Simple Investigation // Revise code when implementing Complex investigations SpecimenVo specimen = pathologyDetails.getSpecimens().get(0); // Pediatric container - alternate containers can only be configured for investigations with // only one pediatric container; any investigation must contain at least one pediatric container SpecimenContainerVo paediatricContainer = specimen.getPaediatricContainers().get(0); investigationRow.getColContainer().newRow(paediatricContainer, paediatricContainer.getSpecContainer().getName()); investigationRow.getColContainer().setValue(paediatricContainer); totalRequiedVolume += pathologyDetails.getSpecimens().get(0).getPaediatricContainers().get(0).getVolume(); if (specimen.getAlternativePaediatricContainers() != null) { int addedAlternatives = 0; for (SpecimenContainerVo alternatePaedContainer : specimen.getAlternativePaediatricContainers()) { OrderInvestigationVoCollection orderInvestigations = alternativeContainers.get(alternatePaedContainer.getSpecContainer()); if (orderInvestigations != null && orderInvestigations.size() > 1 && orderInvestigations.contains(investigation)) { alternatePaedContainer.getSpecContainer().setAlternativeVol(alternatePaedContainer.getVolume()); investigationRow.getColContainer().newRow(alternatePaedContainer, alternatePaedContainer.getSpecContainer().getName()); addedAlternatives++; } } investigationRow.setColContainerReadOnly(addedAlternatives == 0); } } } return totalRequiedVolume; }
/** * Build a hash map with OderSpecimen as key, configured SpecimenContainer as secondary key, and OrderInvestigation collection as values * * Instead of comparing every specimen container from every investigation with every specimen from other investigations, build a hash map with OrderSpecimen primary key, * SpecimenContainer secondary key and add all investigations from an OrderSpecimen that have SpecimenContainer configured. If there are more than one investigation * in the collection, then that SpecimenContainer is common to more than one investigation for the OrderSpecimen */ private HashMap<OrderSpecimenVo, HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection>> buildHashMapOfAlternativeContainers(OrderSpecimenVoCollection myOrderPotentialSpecimens) { if (myOrderPotentialSpecimens == null || myOrderPotentialSpecimens.size() == 0) return null; HashMap<OrderSpecimenVo, HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection>> generalAlternativeContainers = new HashMap<OrderSpecimenVo, HashMap<PathSpecimenContainerDetailVo,OrderInvestigationVoCollection>>(); for (OrderSpecimenVo specimen : myOrderPotentialSpecimens) { HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection> specimenAlternativeContainers = new HashMap<PathSpecimenContainerDetailVo, OrderInvestigationVoCollection>(); for (int i = 0; i < specimen.getInvestigations().size(); i++) { OrderInvestigationVo investigation = (OrderInvestigationVo) specimen.getInvestigations().get(i); // Unsafe upcast due to performance reasons PathInvDetailsVo pathologyDetails = null; if (investigation.getInvestigation().getParentInvestigationPathDetails() != null) { pathologyDetails = investigation.getInvestigation().getParentInvestigationPathDetails(); } else { pathologyDetails = investigation.getInvestigation().getPathInvDetails(); } SpecimenVo specimenVo = pathologyDetails.getSpecimens().get(0); PathSpecimenContainerDetailVo pediatricContainer = specimenVo.getPaediatricContainers().get(0).getSpecContainer(); addSpecimenInvestigationToMap(specimenAlternativeContainers, investigation, pediatricContainer); for (SpecimenContainerVo containers : specimenVo.getAlternativePaediatricContainers()) { addSpecimenInvestigationToMap(specimenAlternativeContainers, investigation, containers.getSpecContainer()); } } generalAlternativeContainers.put(specimen, specimenAlternativeContainers); } return generalAlternativeContainers; }