=== 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 2013-04-04 06:13:42 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2013-04-12 04:20:19 +0000 @@ -44,7 +44,7 @@ /** * @author Chau Thu Tran * @version $ DefaultProgramDataEntryService.java May 26, 2011 3:59:43 PM $ - * + * */ public class DefaultProgramDataEntryService implements ProgramDataEntryService @@ -139,7 +139,7 @@ String inputHTML = dataElementMatcher.group( 1 ); Matcher identifierMatcher = IDENTIFIER_PATTERN_FIELD.matcher( inputHTML ); - + if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 ) { // ------------------------------------------------------------- @@ -758,7 +758,7 @@ /** * Replaces i18n string in the custom form code. - * + * * @param dataEntryFormCode the data entry form html. * @param i18n the I18n object. * @return internationalized data entry form html. === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java 2013-04-10 03:13:47 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java 2013-04-12 04:20:19 +0000 @@ -50,6 +50,7 @@ import org.hisp.dhis.program.ProgramStageInstanceService; import org.hisp.dhis.program.ProgramStageSection; import org.hisp.dhis.program.ProgramStageSectionService; +import org.hisp.dhis.program.ProgramStageService; import org.hisp.dhis.program.comparator.ProgramStageDataElementSortOrderComparator; import org.hisp.dhis.program.comparator.ProgramStageSectionSortOrderComparator; import org.hisp.dhis.system.util.ValidationUtils; @@ -81,6 +82,13 @@ this.patientDataValueService = patientDataValueService; } + private ProgramStageService programStageService; + + public void setProgramStageService( ProgramStageService programStageService ) + { + this.programStageService = programStageService; + } + private ProgramStageInstanceService programStageInstanceService; public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService ) @@ -113,6 +121,10 @@ // Input && Output // ------------------------------------------------------------------------- + private Integer organisationUnitId; + + private Integer programStageId; + private Integer programStageInstanceId; private ProgramStageInstance programStageInstance; @@ -125,8 +137,6 @@ private Map patientDataValueMap; - private Integer organisationUnitId; - private OrganisationUnit organisationUnit; private Program program; @@ -141,6 +151,16 @@ // Getters && Setters // ------------------------------------------------------------------------- + public void setOrganisationUnitId( Integer organisationUnitId ) + { + this.organisationUnitId = organisationUnitId; + } + + public void setProgramStageId( Integer programStageId ) + { + this.programStageId = programStageId; + } + public void setProgramStageInstanceId( Integer programStageInstanceId ) { this.programStageInstanceId = programStageInstanceId; @@ -234,10 +254,6 @@ organisationUnit = organisationUnitId == null ? selectedStateManager.getSelectedOrganisationUnit() : organisationUnitService.getOrganisationUnit( organisationUnitId ); - // --------------------------------------------------------------------- - // Get program-stage-instance - // --------------------------------------------------------------------- - if ( programStageInstanceId != null ) { programStageInstance = programStageInstanceService.getProgramStageInstance( programStageInstanceId ); @@ -247,7 +263,36 @@ programStage = programStageInstance.getProgramStage(); selectedStateManager.setSelectedProgramStageInstance( programStageInstance ); - + } + else if ( programStageId != null ) + { + programStage = programStageService.getProgramStage( programStageId ); + + program = programStage.getProgram(); + } + else + { + return INPUT; + } + + // --------------------------------------------------------------------- + // Get program-stage-instance + // --------------------------------------------------------------------- + + programStageDataElements = new ArrayList( programStage.getProgramStageDataElements() ); + + Collections.sort( programStageDataElements, new ProgramStageDataElementSortOrderComparator() ); + + if ( programStage.getDataEntryType().equals( ProgramStage.TYPE_SECTION ) ) + { + sections = new ArrayList( + programStageSectionService.getProgramStages( programStage ) ); + + Collections.sort( sections, new ProgramStageSectionSortOrderComparator() ); + } + + if ( programStageInstance != null ) + { if ( program.isRegistration() ) { patient = programStageInstance.getProgramInstance().getPatient(); @@ -257,42 +302,21 @@ // Get data values // --------------------------------------------------------------------- - programStageDataElements = new ArrayList( programStageInstance.getProgramStage() - .getProgramStageDataElements() ); - - Collections.sort( programStageDataElements, new ProgramStageDataElementSortOrderComparator() ); - - Collection patientDataValues = patientDataValueService - .getPatientDataValues( programStageInstance ); - - patientDataValueMap = new HashMap( patientDataValues.size() ); - - for ( PatientDataValue patientDataValue : patientDataValues ) - { - int key = patientDataValue.getDataElement().getId(); - patientDataValueMap.put( key, patientDataValue ); - } + Collection patientDataValues = getPatientDataValues(); // --------------------------------------------------------------------- // Get data-entry-form // --------------------------------------------------------------------- - DataEntryForm dataEntryForm = programStageInstance.getProgramStage().getDataEntryForm(); - if ( programStage.getDataEntryType().equals( ProgramStage.TYPE_CUSTOM ) ) { + DataEntryForm dataEntryForm = programStage.getDataEntryForm(); + Boolean disabled = (program.getDisplayProvidedOtherFacility() == null) ? true : !program .getDisplayProvidedOtherFacility(); customDataEntryFormCode = programDataEntryService.prepareDataEntryFormForEntry( dataEntryForm.getHtmlCode(), patientDataValues, disabled.toString(), i18n, - programStageInstance.getProgramStage(), programStageInstance, organisationUnit ); - } - else if ( programStage.getDataEntryType().equals( ProgramStage.TYPE_SECTION ) ) - { - sections = new ArrayList( - programStageSectionService.getProgramStages( programStage ) ); - - Collections.sort( sections, new ProgramStageSectionSortOrderComparator() ); + programStage, programStageInstance, organisationUnit ); } // ----------------------------------------------------------------- @@ -306,4 +330,19 @@ return SUCCESS; } + private Collection getPatientDataValues() + { + Collection patientDataValues = patientDataValueService + .getPatientDataValues( programStageInstance ); + + patientDataValueMap = new HashMap( patientDataValues.size() ); + + for ( PatientDataValue patientDataValue : patientDataValues ) + { + int key = patientDataValue.getDataElement().getId(); + patientDataValueMap.put( key, patientDataValue ); + } + + return patientDataValues; + } } === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-04-11 08:30:45 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-04-12 04:20:19 +0000 @@ -87,18 +87,18 @@ ref="org.hisp.dhis.caseentry.state.SelectedStateManager" /> - - - - - - - - + + + + + + + + + -
$customDataEntryFormCode -
\ No newline at end of file + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm 2013-04-10 04:22:14 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm 2013-04-12 04:20:19 +0000 @@ -1,18 +1,17 @@ @@ -21,20 +20,20 @@ - - + + - - - + + + - - + +
- - #if($programStageInstance.programStage.captureCoordinates=='true') + + #if($programStage.captureCoordinates=='true') @@ -52,8 +51,8 @@ - - #if( $programStageInstance.programStage.getDataEntryType()=='section' ) + + #if( $programStage.getDataEntryType()=='section' )
@@ -88,7 +87,7 @@

- + #if( $customDataEntryFormCode ) #parse( "/dhis-web-caseentry/customDataEntryForm.vm" ) #elseif( $sections && $sections.size() > 0 ) @@ -122,7 +121,7 @@ var i18n_enter_values_for_longitude_and_latitude_fields = '$encoder.jsEscape( $i18n.getString( "enter_values_for_longitude_and_latitude_fields" ) , "'" )'; var i18n_enter_a_valid_number = '$encoder.jsEscape( $i18n.getString( "enter_a_valid_number" ) , "'" )'; - #if( $programStageInstance.programInstance.program.type=='1' && $programStageInstance.programInstance.status==1) + #if( $program.type == '1' && $programStageInstance.programInstance.status==1) jQuery("[id=entryFormContainer] :input").prop('disabled', true); jQuery("[id=entryFormContainer] :input").datepicker("destroy"); jQuery("[id=executionDate]").prop('disabled', true); @@ -133,4 +132,3 @@ blockEntryForm(); } - === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm 2013-04-04 05:07:53 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm 2013-04-12 04:20:19 +0000 @@ -3,7 +3,7 @@ - #if( $!programStageInstance.programStage.program.displayProvidedOtherFacility=='true') + #if( $!program.displayProvidedOtherFacility=='true') #end @@ -11,7 +11,7 @@ $i18n.getString( "data_element" ) $i18n.getString( "value" ) - #if( $programStage.program.displayProvidedOtherFacility=='true') + #if( $program.displayProvidedOtherFacility=='true') $i18n.getString( "provided_elsewhere" ) #end === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-04-11 08:30:45 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-04-12 04:20:19 +0000 @@ -539,7 +539,7 @@ setInnerHTML( 'dataEntryFormDiv', '' ); showLoader(); - service.loadDataEntryForm( programStageInstanceId, getFieldValue( 'orgunitId' ) ); + service.loadDataEntryForm( getFieldValue( 'programStageId' ), programStageInstanceId, getFieldValue( 'orgunitId' ) ); } function backEventList() { @@ -650,18 +650,34 @@ // execution date module var service = (function () { + var executionDateStoreInitialized = false; + var dataValueStoreInitialized = false; + var formStoreInitialized = false; + + var executionDateStore = new dhis2.storage.Store( {name: 'anonymousExecutionDate' }, function ( store ) { + executionDateStoreInitialized = true; + } ); + + var dataValueStore = new dhis2.storage.Store( {name: 'anonymousDataValue' }, function ( store ) { + dataValueStoreInitialized = true; + } ); + + var formStore = new dhis2.storage.Store( {name: 'anonymousForm', adapter: 'dom-ss'}, function ( store ) { + formStoreInitialized = true; + } ); + return { saveExecutionDate: function( programId, programStageInstanceId, executionDate, organisationUnitId ) { - jQuery.postJSON( "saveExecutionDate.action", { - programId: programId, - programStageInstanceId: programStageInstanceId, - executionDate: executionDate, - organisationUnitId: organisationUnitId - }, - function ( json ) { + $.ajax( { + url: 'saveExecutionDate.action', + data: createExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId), + type: 'POST', + dataType: 'json' + } ).done(function ( json ) { if ( json.response == 'success' ) { jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR ); setFieldValue( 'programStageInstanceId', json.message ); + if ( programStageInstanceId != json.message ) { showUpdateEvent( json.message ); } @@ -670,45 +686,99 @@ jQuery( "#executionDate" ).css( 'background-color', ERROR_COLOR ); showWarningMessage( json.message ); } + } ).fail( function () { + function waitForExecutionDateStore() { + if(!executionDateStoreInitialized) { + setTimeout(waitForExecutionDateStore, 50); + } + } + + waitForExecutionDateStore(); + + var data = createExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId); + + if(programStageInstanceId == 0) { + executionDateStore.keys(function(store, keys) { + var i = 100; + + for(; i<10000; i++) { + if( keys.indexOf(i) == -1 ) break; + } + + console.log("i: ", i); + + setFieldValue( 'programStageInstanceId', "local"+i ); + jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR ); + showUpdateEvent( programStageInstanceId ); + console.log("programStageInstanceId: ", getFieldValue('programStageInstanceId')); + }); + } else { + // if we have a programStageInstanceId, just reuse that one + setFieldValue( 'programStageInstanceId', programStageInstanceId ); + jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR ); + showUpdateEvent( programStageInstanceId ); + console.log("programStageInstanceId: ", getFieldValue('programStageInstanceId')); + } } ); }, - loadDataEntryForm: function( programStageInstanceId, organisationUnitId ) { - $( '#dataEntryFormDiv' ).load( "dataentryform.action", { - programStageInstanceId: programStageInstanceId, - organisationUnitId: organisationUnitId - }, function () { - jQuery( '#inputCriteriaDiv' ).remove(); - showById( 'programName' ); - showById( 'actionDiv' ); - var programName = jQuery( '#programId option:selected' ).text(); - var programStageId = jQuery( '#programId option:selected' ).attr( 'psid' ); - jQuery( '.stage-object-selected' ).attr( 'psid', programStageId ); - setInnerHTML( 'programName', programName ); - jQuery('#executionDate').css('width',430); - jQuery('#executionDate').css('margin-right',30); - - if ( getFieldValue( 'completed' ) == 'true' ) { - disable( "completeBtn" ); - enable( "uncompleteBtn" ); - } - else { - enable( "completeBtn" ); - disable( "uncompleteBtn" ); - } + loadDataEntryForm: function( programStageId, programStageInstanceId, organisationUnitId ) { + $.ajax( { + url: 'dataentryform.action', + data: { + programStageId: programStageId, + programStageInstanceId: programStageInstanceId, + organisationUnitId: organisationUnitId + }, + dataType: 'html' + } ).done(function(data) { + $( '#dataEntryFormDiv' ).html( data ); + updateDataForm(); + } ).fail(function() { + $( '#dataEntryFormDiv' ).html( "
Unable to load form.
" ); hideById( 'loaderDiv' ); - showById( 'dataEntryInfor' ); - showById( 'entryFormContainer' ); - - jQuery( "#entryForm :input" ).each( function () { - if ( ( jQuery( this ).attr( 'options' ) != null && jQuery( this ).attr( 'options' ) == 'true' ) - || ( jQuery( this ).attr( 'username' ) != null && jQuery( this ).attr( 'username' ) == 'true' ) ) { - var input = jQuery( this ); - input.parent().width( input.width() + 200 ); - } - } ); - } ); - + }); } } })(); + +function updateDataForm() { + jQuery( '#inputCriteriaDiv' ).remove(); + showById( 'programName' ); + showById( 'actionDiv' ); + var programName = jQuery( '#programId option:selected' ).text(); + var programStageId = jQuery( '#programId option:selected' ).attr( 'psid' ); + jQuery( '.stage-object-selected' ).attr( 'psid', programStageId ); + setInnerHTML( 'programName', programName ); + jQuery('#executionDate').css('width',430); + jQuery('#executionDate').css('margin-right',30); + + if ( getFieldValue( 'completed' ) == 'true' ) { + disable( "completeBtn" ); + enable( "uncompleteBtn" ); + } + else { + enable( "completeBtn" ); + disable( "uncompleteBtn" ); + } + hideById( 'loaderDiv' ); + showById( 'dataEntryInfor' ); + showById( 'entryFormContainer' ); + + jQuery( "#entryForm :input" ).each( function () { + if ( ( jQuery( this ).attr( 'options' ) != null && jQuery( this ).attr( 'options' ) == 'true' ) + || ( jQuery( this ).attr( 'username' ) != null && jQuery( this ).attr( 'username' ) == 'true' ) ) { + var input = jQuery( this ); + input.parent().width( input.width() + 200 ); + } + } ); +} + +function createExecutionDate( programId, programStageInstanceId, executionDate, organisationUnitId ) { + return { + programId: programId, + programStageInstanceId: programStageInstanceId, + executionDate: executionDate, + organisationUnitId: organisationUnitId + } +}