/** * @param viewProviderAndName null indicates we should use the default view for request, otherwise * this should be "providerName:viewName" * @param request * @return * @should get a view from the requested provider * @should get a view from any provider if none is specified * @should fail if an invalid provider name is specified */ PageView getView(String viewProviderAndName, PageRequest request) { String providerName; String viewName; if (viewProviderAndName == null) { providerName = request.getMappedProviderName(); viewName = request.getMappedPageName(); } else { String[] temp = viewProviderAndName.split(":"); if (temp.length != 2) { throw new UiFrameworkException( "Expected \"providerName:viewName\" but was \"" + viewProviderAndName + "\""); } providerName = temp[0]; viewName = temp[1]; } if ("*".equals(providerName)) { for (PageViewProvider p : viewProviders.values()) { PageView ret = p.getView(viewName); if (ret != null) { return ret; } } // pages are required to have views, so we throw an exception if we couldn't find one throw new UiFrameworkException( "Could not find page view '" + viewName + "' in any of the view providers (" + OpenmrsUtil.join(viewProviders.keySet(), ", ") + ")"); } else { PageViewProvider provider = viewProviders.get(providerName); if (provider == null) { throw new UiFrameworkException("No viewProvider named " + providerName); } PageView ret = provider.getView(viewName); if (ret == null) { // pages are required to have views, so we throw an exception if we couldn't find one throw new UiFrameworkException( "viewProvider " + providerName + " does not have a view named " + viewName); } return ret; } }
/** * Adds the column headers and column data to the DataSet * * @param dataSet * @param encounters * @param patientIdentifierTypes * @param optionalColumns * @param columnDisplayFormat * @param maxColumnHeaderWidth * @param allColumns * @param fieldMap * @return */ public DataSet addData( SimpleDataSet dataSet, List<Encounter> encounters, List<PatientIdentifierType> patientIdentifierTypes, List<EncounterAndObsDataSetDefinition.ObsOptionalColumn> optionalColumns, List<EncounterAndObsDataSetDefinition.ColumnDisplayFormat> columnDisplayFormat, Integer maxColumnHeaderWidth, Set<ObsColumnDescriptor> allColumns, Map<Encounter, Map<ObsColumnDescriptor, Obs>> fieldMap) { for (Encounter encounter : encounters) { DataSetRow row = new DataSetRow(); List<String> providerNames = new ArrayList<String>(); for (EncounterProvider ep : encounter.getEncounterProviders()) { providerNames.add(ep.getProvider().getName()); } // Add the standard columns for encounters DataSetColumn c1 = new DataSetColumn( ObjectUtil.trimStringIfNeeded("ENCOUNTER_ID", maxColumnHeaderWidth), ObjectUtil.trimStringIfNeeded("ENCOUNTER_ID", maxColumnHeaderWidth), Integer.class); row.addColumnValue(c1, encounter.getEncounterId()); DataSetColumn c2 = new DataSetColumn( ObjectUtil.trimStringIfNeeded("ENCOUNTER_DATETIME", maxColumnHeaderWidth), ObjectUtil.trimStringIfNeeded("ENCOUNTER_DATETIME", maxColumnHeaderWidth), String.class); row.addColumnValue(c2, encounter.getEncounterDatetime().toString()); DataSetColumn c3 = new DataSetColumn( ObjectUtil.trimStringIfNeeded("LOCATION", maxColumnHeaderWidth), ObjectUtil.trimStringIfNeeded("LOCATION", maxColumnHeaderWidth), String.class); row.addColumnValue( c3, (encounter.getLocation() != null) ? encounter.getLocation().getName() : EMPTY); DataSetColumn c4 = new DataSetColumn( ObjectUtil.trimStringIfNeeded("PROVIDER", maxColumnHeaderWidth), ObjectUtil.trimStringIfNeeded("PROVIDER", maxColumnHeaderWidth), String.class); row.addColumnValue(c4, OpenmrsUtil.join(providerNames, ", ")); DataSetColumn c5 = new DataSetColumn( ObjectUtil.trimStringIfNeeded("INTERNAL_PATIENT_ID", maxColumnHeaderWidth), ObjectUtil.trimStringIfNeeded("INTERNAL_PATIENT_ID", maxColumnHeaderWidth), Integer.class); row.addColumnValue( c5, encounter.getPatient() != null ? encounter.getPatient().getPatientId() : EMPTY); if (patientIdentifierTypes != null) { for (PatientIdentifierType pit : patientIdentifierTypes) { List<PatientIdentifier> patientIdentifiers = encounter.getPatient().getPatientIdentifiers(pit); StringBuffer sbPatientIdentifiers = new StringBuffer(); int count = 0; for (PatientIdentifier patientIdentifier : patientIdentifiers) { if (count > 0) { sbPatientIdentifiers.append(", "); } sbPatientIdentifiers.append(patientIdentifier.toString()); count++; } DataSetColumn c6 = new DataSetColumn( pit.getName(), ObjectUtil.trimStringIfNeeded(pit.getName(), maxColumnHeaderWidth), String.class); row.addColumnValue(c6, sbPatientIdentifiers.toString()); } } Map<ObsColumnDescriptor, Obs> obsInEncounter = fieldMap.get(encounter); // Look up all obs for a given encounter based on column headers for all encounters for (ObsColumnDescriptor columnKey : allColumns) { Obs obs = obsInEncounter.get(columnKey); String columnName = columnKey.format(columnDisplayFormat, maxColumnHeaderWidth); DataSetColumn obsDsc = new DataSetColumn(columnName, columnName, String.class); StringBuffer columnValue = new StringBuffer(); if (obs != null && obs.getValueCoded() != null) { if (columnDisplayFormat.contains( EncounterAndObsDataSetDefinition.ColumnDisplayFormat.ID)) { columnValue.append(obs.getValueCoded()); } if (columnDisplayFormat.contains(EncounterAndObsDataSetDefinition.ColumnDisplayFormat.ID) && columnDisplayFormat.contains( EncounterAndObsDataSetDefinition.ColumnDisplayFormat.BEST_SHORT_NAME)) { columnValue.append("_"); } if (columnDisplayFormat.contains( EncounterAndObsDataSetDefinition.ColumnDisplayFormat.BEST_SHORT_NAME)) { String conceptName = obs.getValueAsString(Context.getLocale()); columnValue.append( maxColumnHeaderWidth != null && conceptName.length() > maxColumnHeaderWidth - columnValue.length() ? conceptName.substring(0, maxColumnHeaderWidth - columnValue.length() - 1) : conceptName); } row.addColumnValue(obsDsc, (obs != null) ? columnValue.toString() : EMPTY); } else { row.addColumnValue( obsDsc, (obs != null) ? obs.getValueAsString(Context.getLocale()) : EMPTY); } String dateColumnName = columnKey.format( columnDisplayFormat, maxColumnHeaderWidth != null ? maxColumnHeaderWidth - 5 : null); DataSetColumn obsDscDate = new DataSetColumn(dateColumnName + "_DATE", dateColumnName + "_DATE", String.class); row.addColumnValue(obsDscDate, (obs != null) ? obs.getObsDatetime().toString() : EMPTY); String parentColumnName = columnKey.format( columnDisplayFormat, maxColumnHeaderWidth != null ? maxColumnHeaderWidth - 7 : null); DataSetColumn obsDscParent = new DataSetColumn( parentColumnName + "_PARENT", parentColumnName + "_PARENT", String.class); row.addColumnValue( obsDscParent, (obs != null && obs.getObsGroup() != null) ? obs.getObsGroup().getId() : EMPTY); if (optionalColumns != null) { if (optionalColumns.contains( EncounterAndObsDataSetDefinition.ObsOptionalColumn.VALUE_MODIFIER)) { String valModColumnName = columnKey.format( columnDisplayFormat, maxColumnHeaderWidth != null ? maxColumnHeaderWidth - 10 : null); DataSetColumn obsDscValueModifier = new DataSetColumn( valModColumnName + "_VALUE_MOD", valModColumnName + "_VALUE_MOD", String.class); row.addColumnValue(obsDscValueModifier, (obs != null) ? obs.getValueModifier() : EMPTY); } if (optionalColumns.contains( EncounterAndObsDataSetDefinition.ObsOptionalColumn.ACCESSION_NUMBER)) { String accessionNumColumnName = columnKey.format( columnDisplayFormat, maxColumnHeaderWidth != null ? maxColumnHeaderWidth - 14 : null); DataSetColumn obsDscAccessionNumber = new DataSetColumn( accessionNumColumnName + "_ACCESSION_NUM", accessionNumColumnName + "_ACCESSION_NUM", String.class); row.addColumnValue( obsDscAccessionNumber, (obs != null) ? obs.getAccessionNumber() : EMPTY); } if (optionalColumns.contains( EncounterAndObsDataSetDefinition.ObsOptionalColumn.COMMENT)) { String commentColumnName = columnKey.format( columnDisplayFormat, maxColumnHeaderWidth != null ? maxColumnHeaderWidth - 8 : null); DataSetColumn obsDscComment = new DataSetColumn( commentColumnName + "_COMMENT", commentColumnName + "_COMMENT", String.class); row.addColumnValue(obsDscComment, (obs != null) ? obs.getComment() : EMPTY); } } } dataSet.addRow(row); } return dataSet; }