=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java 2012-02-03 08:17:56 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java 2012-02-06 02:56:02 +0000 @@ -44,6 +44,8 @@ OptionSet getOptionSet( String uid ); + OptionSet getOptionSetByName( String name ); + void deleteOptionSet( OptionSet optionSet ); Collection getAllOptionSets(); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java 2012-02-03 08:17:56 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java 2012-02-06 02:56:02 +0000 @@ -66,6 +66,11 @@ return optionSetStore.getByUid( uid ); } + public OptionSet getOptionSetByName( String name ) + { + return optionSetStore.getByName( name ); + } + public void deleteOptionSet( OptionSet optionSet ) { optionSetStore.delete( optionSet ); === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2012-01-11 06:17:35 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2012-02-06 02:56:02 +0000 @@ -56,7 +56,7 @@ private static final String UNKNOW_CLINIC = "unknow_clinic"; private static final String NOTAVAILABLE = "not_available"; - + private static final String OTHER_FACILITY = "other_facility"; private static final String DATA_ELEMENT_DOES_NOT_EXIST = "[ Data element does not exist ]"; @@ -133,9 +133,6 @@ result = populateCustomDataEntryForBoolean( result, dataValues, disabled, i18n, programStage, programStageInstance, organisationUnit, mapDataValue ); - result = populateCustomDataEntryForCombo( result, dataValues, disabled, i18n, programStage, - programStageInstance, organisationUnit, mapDataValue ); - result = populateI18nStrings( result, i18n ); return result; @@ -145,7 +142,7 @@ { String result = populateCustomDataEntryForDate( htmlCode ); - result = populateCustomDataEntryForOption( result ); + result = populateCustomDataEntryForBoolean( result ); result = populateCustomDataEntryForTextBox( result ); @@ -225,7 +222,7 @@ return (sb.toString().isEmpty()) ? htmlCode : sb.toString(); } - private String populateCustomDataEntryForOption( String htmlCode ) + private String populateCustomDataEntryForBoolean( String htmlCode ) { // --------------------------------------------------------------------- // Metadata code to add to HTML before outputting @@ -265,7 +262,7 @@ int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) ); DataElement dataElement = dataElementService.getDataElement( dataElementId ); - if ( dataElement != null && !DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) ) + if ( dataElement != null && !DataElement.VALUE_TYPE_BOOL.equals( dataElement.getType() ) ) { continue; } @@ -360,234 +357,6 @@ return (sb.toString().isEmpty()) ? htmlCode : sb.toString(); } - private String populateCustomDataEntryForTextBox( String dataEntryFormCode, - Collection dataValues, String disabled, I18n i18n, ProgramStage programStage, - ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit, - Map> mapDataValue ) - { - // --------------------------------------------------------------------- - // Inline Javascript to add to HTML before outputting - // --------------------------------------------------------------------- - - final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID, $OPTIONCOMBOID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE', provided:'$PROVIDED'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\" "; - - StringBuffer sb = new StringBuffer(); - - // --------------------------------------------------------------------- - // Pattern to match data elements in the HTML code - // --------------------------------------------------------------------- - - Pattern INPUT_PATTERN = Pattern.compile( "(", Pattern.DOTALL ); - Matcher dataElementMatcher = INPUT_PATTERN.matcher( dataEntryFormCode ); - - // --------------------------------------------------------------------- - // Iterate through all matching data element fields - // --------------------------------------------------------------------- - - Map dataElementMap = getDataElementMap( programStage ); - - while ( dataElementMatcher.find() ) - { - // ----------------------------------------------------------------- - // Get HTML input field code - // ----------------------------------------------------------------- - - String compulsory = "null"; - String dataElementCode = dataElementMatcher.group( 1 ); - - Matcher identifierMatcher = IDENTIFIER_PATTERN_TEXTBOX.matcher( dataElementCode ); - - if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 ) - { - // ------------------------------------------------------------- - // Get data element ID of data element - // ------------------------------------------------------------- - - int programStageId = Integer.parseInt( identifierMatcher.group( 1 ) ); - - int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) ); - - int optionComboId = Integer.parseInt( identifierMatcher.group( 3 ) ); - - DataElement dataElement = null; - - String programStageName = programStage.getName(); - - if ( programStageId != programStage.getId() ) - { - dataElement = dataElementService.getDataElement( dataElementId ); - - ProgramStage otherProgramStage = programStageService.getProgramStage( programStageId ); - programStageName = otherProgramStage != null ? otherProgramStage.getName() : "N/A"; - } - else - { - dataElement = dataElementMap.get( dataElementId ); - if ( dataElement == null ) - { - return i18n.getString( "some_data_element_not_exist" ); - } - - ProgramStageDataElement psde = programStageDataElementService.get( programStage, dataElement ); - - compulsory = BooleanUtils.toStringTrueFalse( psde.isCompulsory() ); - } - - if ( dataElement == null ) - { - continue; - } - - if ( !DataElement.VALUE_TYPE_INT.equals( dataElement.getType() ) - && !DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) ) - { - continue; - } - - // ------------------------------------------------------------- - // Find type of data element - // ------------------------------------------------------------- - - String dataElementType = dataElement.getDetailedNumberType(); - - // ------------------------------------------------------------- - // Find existing value of data element in data set - // ------------------------------------------------------------- - - PatientDataValue patientDataValue = null; - - String dataElementValue = EMPTY; - - if ( programStageId != programStage.getId() ) - { - Collection patientDataValues = mapDataValue.get( programStageId ); - - if ( patientDataValues == null ) - { - ProgramStage otherProgramStage = programStageService.getProgramStage( programStageId ); - ProgramStageInstance otherProgramStageInstance = programStageInstanceService - .getProgramStageInstance( programStageInstance.getProgramInstance(), otherProgramStage ); - patientDataValues = patientDataValueService.getPatientDataValues( otherProgramStageInstance ); - mapDataValue.put( programStageId, patientDataValues ); - } - - patientDataValue = getValue( patientDataValues, dataElementId, optionComboId ); - - dataElementValue = patientDataValue != null ? patientDataValue.getValue() : dataElementValue; - } - else - { - patientDataValue = getValue( dataValues, dataElementId ); - - dataElementValue = patientDataValue != null ? patientDataValue.getValue() : dataElementValue; - } - - // ------------------------------------------------------------- - // Insert value of data element in output code - // ------------------------------------------------------------- - - if ( dataElementCode.contains( "value=\"\"" ) ) - { - dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"" + dataElementValue + "\"" ); - } - else - { - dataElementCode += "value=\"" + dataElementValue + "\""; - } - - // ------------------------------------------------------------- - // Insert title information - Data element id, name, type, min, - // max - // ------------------------------------------------------------- - DataElementCategoryOptionCombo optionCombo = categoryService - .getDataElementCategoryOptionCombo( optionComboId ); - - if ( dataElementCode.contains( "title=\"\"" ) ) - { - dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"" + dataElement.getId() + "." - + dataElement.getName() + "-" + optionComboId + optionCombo.getName() + "-" + dataElementType - + "\" " ); - } - else - { - dataElementCode += "title=\"" + dataElement.getId() + "." + dataElement.getName() + "-" - + optionComboId + optionCombo.getName() + "-" + dataElementType + "\" "; - } - - // ------------------------------------------------------------- - // Append Javascript code and meta data (type/min/max) for - // persisting to output code, and insert value and type for - // fields - // ------------------------------------------------------------- - - String appendCode = dataElementCode; - - appendCode += jsCodeForInputs; - - appendCode += " />"; - - // ----------------------------------------------------------- - // Check if this dataElement is from another programStage then - // disable - // If programStagsInstance is completed then disabled it - // ----------------------------------------------------------- - - disabled = ""; - if ( programStageId == programStage.getId() && !programStageInstance.isCompleted() ) - { - // ----------------------------------------------------------- - // Add ProvidedByOtherFacility checkbox - // ----------------------------------------------------------- - - appendCode = addProvidedByOtherFacilityCheckbox( appendCode, patientDataValue, programStage ); - } - else - { - disabled = "disabled=\"\""; - } - - // ----------------------------------------------------------- - // - // ----------------------------------------------------------- - - String orgUnitName = i18n.getString( NOTAVAILABLE ); - String provided = ""; - - if ( patientDataValue != null ) - { - if ( patientDataValue.isProvidedByAnotherFacility() ) - { - orgUnitName = i18n.getString( UNKNOW_CLINIC ); - provided = i18n.getString( OTHER_FACILITY ); - } - else - { - orgUnitName = patientDataValue.getOrganisationUnit().getName(); - provided = patientDataValue.getOrganisationUnit().getName(); - } - } - - appendCode = appendCode.replace( "$DATAELEMENTID", String.valueOf( dataElementId ) ); - appendCode = appendCode.replace( "$PROGRAMSTAGEID", String.valueOf( programStageId ) ); - appendCode = appendCode.replace( "$PROGRAMSTAGENAME", programStageName ); - appendCode = appendCode.replace( "$ORGUNITNAME", orgUnitName ); - appendCode = appendCode.replace( "$OPTIONCOMBOID", String.valueOf( optionComboId ) ); - appendCode = appendCode.replace( "$DATAELEMENTNAME", dataElement.getName() ); - appendCode = appendCode.replace( "$DATAELEMENTTYPE", dataElementType ); - appendCode = appendCode.replace( "$DISABLED", disabled ); - appendCode = appendCode.replace( "$COMPULSORY", compulsory ); - appendCode = appendCode.replace( "$SAVEMODE", "false" ); - appendCode = appendCode.replace( "$PROVIDED", provided ); - - dataElementMatcher.appendReplacement( sb, appendCode ); - } - } - - dataElementMatcher.appendTail( sb ); - - return sb.toString(); - } - private String populateCustomDataEntryForBoolean( String dataEntryFormCode, Collection dataValues, String disabled, I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit, @@ -778,7 +547,8 @@ // ----------------------------------------------------------- String orgUnitName = i18n.getString( NOTAVAILABLE ); - String provided = i18n.getString( NOTAVAILABLE );; + String provided = i18n.getString( NOTAVAILABLE ); + ; if ( patientDataValue != null ) { if ( patientDataValue.isProvidedByAnotherFacility() ) @@ -806,8 +576,6 @@ appendCode = appendCode.replace( "i18n_select_value", i18n.getString( "select_value" ) ); appendCode = appendCode.replace( "$SAVEMODE", "false" ); - - appendCode = appendCode.replace( "$PROVIDED", provided ); appendCode = appendCode.replaceAll( "\\$", "\\\\\\$" ); @@ -821,16 +589,16 @@ return sb.toString(); } - private String populateCustomDataEntryForCombo( String dataEntryFormCode, Collection dataValues, - String disabled, I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance, - OrganisationUnit organisationUnit, Map> mapDataValue ) + private String populateCustomDataEntryForTextBox( String dataEntryFormCode, + Collection dataValues, String disabled, I18n i18n, ProgramStage programStage, + ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit, + Map> mapDataValue ) { - // --------------------------------------------------------------------- // Inline Javascript to add to HTML before outputting // --------------------------------------------------------------------- - final String jsCodeForCombo = " name=\"entryselect\" $DISABLED data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', provided:'$PROVIDED'}\" onchange=\"saveOpt( $DATAELEMENTID )\" style=\" text-align:center;\" "; + final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID, $OPTIONCOMBOID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE', provided:'$PROVIDED'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\" "; StringBuffer sb = new StringBuffer(); @@ -838,6 +606,7 @@ // Pattern to match data elements in the HTML code // --------------------------------------------------------------------- + Pattern INPUT_PATTERN = Pattern.compile( "(", Pattern.DOTALL ); Matcher dataElementMatcher = INPUT_PATTERN.matcher( dataEntryFormCode ); // --------------------------------------------------------------------- @@ -852,11 +621,10 @@ // Get HTML input field code // ----------------------------------------------------------------- + String compulsory = "null"; String dataElementCode = dataElementMatcher.group( 1 ); - Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode ); - - String compulsory = "null"; + Matcher identifierMatcher = IDENTIFIER_PATTERN_TEXTBOX.matcher( dataElementCode ); if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 ) { @@ -865,8 +633,11 @@ // ------------------------------------------------------------- int programStageId = Integer.parseInt( identifierMatcher.group( 1 ) ); + int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) ); + int optionComboId = Integer.parseInt( identifierMatcher.group( 3 ) ); + DataElement dataElement = null; String programStageName = programStage.getName(); @@ -895,7 +666,9 @@ { continue; } - if ( !DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) ) + + if ( !DataElement.VALUE_TYPE_INT.equals( dataElement.getType() ) + && !DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) ) { continue; } @@ -904,14 +677,16 @@ // Find type of data element // ------------------------------------------------------------- - String dataElementType = dataElement.getType(); + String dataElementType = dataElement.getDetailedNumberType(); // ------------------------------------------------------------- // Find existing value of data element in data set // ------------------------------------------------------------- PatientDataValue patientDataValue = null; + String dataElementValue = EMPTY; + if ( programStageId != programStage.getId() ) { Collection patientDataValues = mapDataValue.get( programStageId ); @@ -925,56 +700,76 @@ mapDataValue.put( programStageId, patientDataValues ); } - patientDataValue = getValue( patientDataValues, dataElementId ); + patientDataValue = getValue( patientDataValues, dataElementId, optionComboId ); dataElementValue = patientDataValue != null ? patientDataValue.getValue() : dataElementValue; } else { - patientDataValue = getValue( dataValues, dataElementId ); + patientDataValue = getValue( dataValues, dataElementId, optionComboId ); dataElementValue = patientDataValue != null ? patientDataValue.getValue() : dataElementValue; } - String appendCode = dataElementCode.replaceFirst( "input", "select" ); - ; - appendCode = appendCode.replace( "name=\"entryselect\"", jsCodeForCombo ); - - appendCode += ">"; - appendCode += ""; - for ( DataElementCategoryOptionCombo optionCombo : dataElement.getCategoryCombo().getOptionCombos() ) - { - appendCode += ""; - } - - // ------------------------------------------------------------- - // Insert value of data element in output code - // ------------------------------------------------------------- - - if ( patientDataValue != null ) - { - appendCode = appendCode.replace( ""; + for ( String option : dataElement.getOptionSet().getOptions() ) + { + appendCode += ""; + } + + if ( patientDataValue != null ) + { + appendCode = appendCode.replace( "