=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java 2015-04-08 11:07:34 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java 2015-06-19 07:35:50 +0000 @@ -34,6 +34,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + import org.hisp.dhis.attribute.AttributeValue; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.DxfNamespaces; @@ -44,6 +45,7 @@ import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataentryform.DataEntryForm; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.relationship.RelationshipType; import org.hisp.dhis.schema.annotation.PropertyRange; @@ -132,6 +134,8 @@ */ private Set attributeValues = new HashSet<>(); + private DataEntryForm dataEntryForm; + // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- @@ -616,6 +620,19 @@ this.attributeValues = attributeValues; } + @JsonProperty + @JsonView( { DetailedView.class, ExportView.class } ) + @JacksonXmlProperty( localName = "dataEntryForm", namespace = DxfNamespaces.DXF_2_0 ) + public DataEntryForm getDataEntryForm() + { + return dataEntryForm; + } + + public void setDataEntryForm( DataEntryForm dataEntryForm ) + { + this.dataEntryForm = dataEntryForm; + } + @Override public void mergeWith( IdentifiableObject other, MergeStrategy strategy ) { === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java 2015-06-16 17:43:23 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java 2015-06-19 07:35:50 +0000 @@ -28,10 +28,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.Collection; import java.util.List; +import java.util.regex.Pattern; +import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.trackedentity.TrackedEntity; +import org.hisp.dhis.trackedentity.TrackedEntityInstance; import org.hisp.dhis.user.User; import org.hisp.dhis.validation.ValidationCriteria; @@ -41,8 +46,25 @@ */ public interface ProgramService { + String ID = ProgramService.class.getName(); + final Pattern INPUT_PATTERN = Pattern.compile( "()", Pattern.DOTALL ); + + final Pattern DYNAMIC_ATTRIBUTE_PATTERN = Pattern.compile( "attributeid=\"(\\w+)\"" ); + + final Pattern PROGRAM_PATTERN = Pattern.compile( "programid=\"(\\w+)\"" ); + + final Pattern VALUE_TAG_PATTERN = Pattern.compile( "value=\"(.*?)\"", Pattern.DOTALL ); + + final Pattern TITLE_TAG_PATTERN = Pattern.compile( "title=\"(.*?)\"", Pattern.DOTALL ); + + final Pattern SUGGESTED_VALUE_PATTERN = Pattern.compile( "suggested=('|\")(\\w*)('|\")" ); + + final Pattern CLASS_PATTERN = Pattern.compile( "class=('|\")(\\w*)('|\")" ); + + final Pattern STYLE_PATTERN = Pattern.compile( "style=('|\")([\\w|\\d\\:\\;]+)('|\")" ); + /** * Adds an {@link Program} * @@ -87,7 +109,7 @@ * Returns all {@link Program}. * * @return a collection of all Program, or an empty collection if there are - * no Programs. + * no Programs. */ List getAllPrograms(); @@ -117,8 +139,8 @@ * Get {@link Program} by the current user and a certain type * * @param type The type of program. There are three types, include Multi - * events with registration, Single event with registration and - * Single event without registration. + * events with registration, Single event with registration and + * Single event without registration. * @return Program list by a type specified */ List getProgramsByCurrentUser( int type ); @@ -136,8 +158,8 @@ * Get {@link Program} by a type * * @param type The type of program. There are three types, include Multi - * events with registration, Single event with registration and - * Single event without registration + * events with registration, Single event with registration and + * Single event without registration * @return Program list by a type specified */ List getPrograms( int type ); @@ -145,9 +167,9 @@ /** * Get {@link Program} assigned to an {@link OrganisationUnit} by a type * - * @param type The type of program. There are three types, include Multi - * events with registration, Single event with registration and - * Single event without registration + * @param type The type of program. There are three types, include Multi + * events with registration, Single event with registration and + * Single event without registration * @param orgunit Where programs assigned * @return Program list by a type specified */ @@ -187,10 +209,10 @@ * Returns {@link Program} list with paging * * @param name Keyword for searching by name - * @param min First result - * @param max Maximum results - * @return a List of all Program, or an empty collection if - * there are no Program. + * @param min First result + * @param max Maximum results + * @return a List of all Program, or an empty collection if there are no + * Program. */ List getProgramBetweenByName( String name, int min, int max ); @@ -204,8 +226,7 @@ * * @param min First result * @param max Maximum results - * @return a List of all Program, or an empty List if - * there are no Program. + * @return a List of all Program, or an empty List if there are no Program. */ List getProgramsBetween( int min, int max ); @@ -220,9 +241,22 @@ * Get {@link Program} by the current user and a certain type * * @param type The type of program. There are three types, include Multi - * events with registration, Single event with registration and - * Single event without registration. + * events with registration, Single event with registration and + * Single event without registration. * @return Program list by a type specified */ List getByCurrentUser( int type ); + + /** + * @param htmlCode + * @param program + * @param healthWorkers + * @param instance + * @param programInstance + * @param i18n + * @param format + * @return + */ + String prepareDataEntryFormForAdd( String htmlCode, Program program, Collection healthWorkers, + TrackedEntityInstance instance, ProgramInstance programInstance, I18n i18n, I18nFormat format ); } === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/TrackedEntityFormSchemaDescriptor.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/TrackedEntityFormSchemaDescriptor.java 2015-04-29 07:11:23 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/TrackedEntityFormSchemaDescriptor.java 1970-01-01 00:00:00 +0000 @@ -1,65 +0,0 @@ -package org.hisp.dhis.schema.descriptors; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import com.google.common.collect.Lists; -import org.hisp.dhis.schema.Authority; -import org.hisp.dhis.schema.AuthorityType; -import org.hisp.dhis.schema.Schema; -import org.hisp.dhis.schema.SchemaDescriptor; -import org.hisp.dhis.trackedentity.TrackedEntityForm; -import org.springframework.stereotype.Component; - -/** - * @author Morten Olav Hansen - */ -@Component -public class TrackedEntityFormSchemaDescriptor implements SchemaDescriptor -{ - public static final String SINGULAR = "trackedEntityForm"; - - public static final String PLURAL = "trackedEntityForms"; - - public static final String API_ENDPOINT = "/" + PLURAL; - - @Override - public Schema getSchema() - { - Schema schema = new Schema( TrackedEntityForm.class, SINGULAR, PLURAL ); - schema.setRelativeApiEndpoint( API_ENDPOINT ); - schema.setOrder( 1490 ); - schema.setMetadata( false ); - - schema.getAuthorities().add( new Authority( AuthorityType.CREATE, Lists.newArrayList( "F_TRACKED_ENTITY_FORM_ADD" ) ) ); - schema.getAuthorities().add( new Authority( AuthorityType.UPDATE, Lists.newArrayList( "F_TRACKED_ENTITY_FORM_ADD" ) ) ); - schema.getAuthorities().add( new Authority( AuthorityType.DELETE, Lists.newArrayList( "F_TRACKED_ENTITY_FORM_DELETE" ) ) ); - - return schema; - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityForm.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityForm.java 2015-02-26 15:21:29 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityForm.java 1970-01-01 00:00:00 +0000 @@ -1,158 +0,0 @@ -package org.hisp.dhis.trackedentity; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonView; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; -import org.hisp.dhis.common.BaseIdentifiableObject; -import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.common.IdentifiableObject; -import org.hisp.dhis.common.MergeStrategy; -import org.hisp.dhis.common.view.DetailedView; -import org.hisp.dhis.common.view.ExportView; -import org.hisp.dhis.dataentryform.DataEntryForm; -import org.hisp.dhis.program.Program; - -import java.util.Objects; - -/** - * @author Chau Thu Tran - */ -@JacksonXmlRootElement( localName = "trackedEntityForm", namespace = DxfNamespaces.DXF_2_0 ) -public class TrackedEntityForm - extends BaseIdentifiableObject -{ - private static final long serialVersionUID = -6000530171659755186L; - - private Program program; - - private DataEntryForm dataEntryForm; - - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- - - public TrackedEntityForm() - { - } - - public TrackedEntityForm( DataEntryForm dataEntryForm ) - { - this.dataEntryForm = dataEntryForm; - } - - public TrackedEntityForm( Program program, DataEntryForm dataEntryForm ) - { - this.program = program; - this.dataEntryForm = dataEntryForm; - } - - // ------------------------------------------------------------------------- - // Getters && Setters - // ------------------------------------------------------------------------- - - @JsonProperty - @JsonView( { DetailedView.class, ExportView.class } ) - @JsonSerialize( as = BaseIdentifiableObject.class ) - @JacksonXmlProperty( localName = "program", namespace = DxfNamespaces.DXF_2_0 ) - public Program getProgram() - { - return program; - } - - public void setProgram( Program program ) - { - this.program = program; - } - - @JsonProperty - @JsonView( { DetailedView.class, ExportView.class } ) - @JacksonXmlProperty( localName = "dataEntryForm", namespace = DxfNamespaces.DXF_2_0 ) - public DataEntryForm getDataEntryForm() - { - return dataEntryForm; - } - - public void setDataEntryForm( DataEntryForm dataEntryForm ) - { - this.dataEntryForm = dataEntryForm; - } - - @Override - public int hashCode() - { - return 31 * super.hashCode() + Objects.hash( program, dataEntryForm ); - } - - @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || getClass() != obj.getClass() ) - { - return false; - } - if ( !super.equals( obj ) ) - { - return false; - } - - final TrackedEntityForm other = (TrackedEntityForm) obj; - - return Objects.equals( this.program, other.program ) && Objects.equals( this.dataEntryForm, other.dataEntryForm ); - } - - @Override - public void mergeWith( IdentifiableObject other, MergeStrategy strategy ) - { - super.mergeWith( other, strategy ); - - if ( other.getClass().isInstance( this ) ) - { - TrackedEntityForm trackedEntityForm = (TrackedEntityForm) other; - - if ( strategy.isReplace() ) - { - program = trackedEntityForm.getProgram(); - dataEntryForm = trackedEntityForm.getDataEntryForm(); - } - else if ( strategy.isMerge() ) - { - program = trackedEntityForm.getProgram() == null ? program : trackedEntityForm.getProgram(); - dataEntryForm = trackedEntityForm.getDataEntryForm() == null ? dataEntryForm : trackedEntityForm.getDataEntryForm(); - } - } - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityFormService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityFormService.java 2015-06-16 13:17:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityFormService.java 1970-01-01 00:00:00 +0000 @@ -1,141 +0,0 @@ -package org.hisp.dhis.trackedentity; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.Collection; -import java.util.List; -import java.util.regex.Pattern; - -import org.hisp.dhis.i18n.I18n; -import org.hisp.dhis.i18n.I18nFormat; -import org.hisp.dhis.program.Program; -import org.hisp.dhis.program.ProgramInstance; -import org.hisp.dhis.user.User; - -/** - * @author Chau Thu Tran - * - * @version TrackedEntityFormService.java 9:35:44 AM Jan 31, 2013 $ - */ -public interface TrackedEntityFormService -{ - final Pattern INPUT_PATTERN = Pattern.compile( "()", Pattern.DOTALL ); - - final Pattern DYNAMIC_ATTRIBUTE_PATTERN = Pattern.compile( "attributeid=\"(\\w+)\"" ); - - final Pattern PROGRAM_PATTERN = Pattern.compile( "programid=\"(\\w+)\"" ); - - final Pattern VALUE_TAG_PATTERN = Pattern.compile( "value=\"(.*?)\"", Pattern.DOTALL ); - - final Pattern TITLE_TAG_PATTERN = Pattern.compile( "title=\"(.*?)\"", Pattern.DOTALL ); - - final Pattern SUGGESTED_VALUE_PATTERN = Pattern.compile( "suggested=('|\")(\\w*)('|\")" ); - - final Pattern CLASS_PATTERN = Pattern.compile( "class=('|\")(\\w*)('|\")" ); - - final Pattern STYLE_PATTERN = Pattern.compile( "style=('|\")([\\w|\\d\\:\\;]+)('|\")" ); - - // -------------------------------------------------------------------------- - // ProgramDataEntryService - // -------------------------------------------------------------------------- - - /** - * Adds an {@link TrackedEntityForm} - * - * @param trackedEntityForm The to TrackedEntityForm add. - * - * @return A generated unique id of the added {@link TrackedEntityForm}. - */ - int saveTrackedEntityForm( TrackedEntityForm trackedEntityForm ); - - /** - * Deletes a {@link TrackedEntityForm}. - * - * @param trackedEntityForm the TrackedEntityForm to delete. - */ - void deleteTrackedEntityForm( TrackedEntityForm trackedEntityForm ); - - /** - * Updates an {@link TrackedEntityForm}. - * - * @param instanceAttribute the TrackedEntityForm to update. - */ - void updateTrackedEntityForm( TrackedEntityForm trackedEntityForm ); - - /** - * Returns a {@link TrackedEntityForm}. - * - * @param id the id of the TrackedEntityForm to return. - * - * @return the TrackedEntityForm with the given id - */ - TrackedEntityForm getTrackedEntityForm( int id ); - - /** - * Returns all {@link TrackedEntityForm} - * - * @return a collection of all TrackedEntityForm, or an empty collection if - * there are no TrackedEntityForms. - */ - List getAllTrackedEntityForms(); - - /** - * Get tracked entity form of a program - * - * @param program Program - * - * @return TrackedEntityForm - */ - TrackedEntityForm getFormsWithProgram( Program program ); - - /** - * Get tracked entity form which doesn't belong to any program - * - * @return TrackedEntityForm - */ - TrackedEntityForm getFormsWithoutProgram(); - - /** - * Prepares the custom registration by injecting required javascripts and - * drop down lists. - * - * @param htmlCode the HTML code of the data entry form. - * @param program Program which include a custom entry form - * @param healthWorkers DHIS users list - * @param instance TrackedEntityInstance - * @param programInstance Program-instance of the instance - * @param i18n the i18n object - * @param format the I18nFormat object - * - * @return HTML code for the form. - */ - String prepareDataEntryFormForAdd( String htmlCode, Program program, Collection healthWorkers, - TrackedEntityInstance instance, ProgramInstance programInstance, I18n i18n, I18nFormat format ); - -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityFormStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityFormStore.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityFormStore.java 1970-01-01 00:00:00 +0000 @@ -1,56 +0,0 @@ -package org.hisp.dhis.trackedentity; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.hisp.dhis.common.GenericIdentifiableObjectStore; -import org.hisp.dhis.program.Program; - -/** - * @author Chau Thu Tran - */ -public interface TrackedEntityFormStore - extends GenericIdentifiableObjectStore -{ - String ID = TrackedEntityFormStore.class.getName(); - - /** - * Get tracked entity form of a program - * - * @param program Program - * @return TrackedEntityForm - */ - TrackedEntityForm get( Program program ); - - /** - * Get tracked entity form which doesn't belong to any program - * - * @return TrackedEntityForm - */ - TrackedEntityForm getFormsWithoutProgram(); -} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java 2015-04-09 19:00:25 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java 2015-06-19 07:35:50 +0000 @@ -71,6 +71,10 @@ executeSql( "ALTER TABLE program DROP COLUMN displayonallorgunit" ); upgradeProgramStageDataElements(); + + executeSql( "UPDATE program SET dataentryformid =(SELECT trackedentityform.dataentryformid FROM trackedentityform WHERE program.programid=trackedentityform.programid) " + + "WHERE program.programid = (SELECT trackedentityform.programid FROM trackedentityform WHERE program.programid = trackedentityform.programid)" ); +// executeSql( "drop table trackedentityform"); } // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java' --- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java 2015-06-16 17:43:23 +0000 +++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java 2015-06-19 07:35:50 +0000 @@ -31,17 +31,30 @@ import static org.hisp.dhis.i18n.I18nUtils.i18n; import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; import java.util.List; import java.util.Set; +import java.util.regex.Matcher; +import org.apache.commons.lang3.StringUtils; +import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.i18n.I18nService; +import org.hisp.dhis.option.Option; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.trackedentity.TrackedEntity; +import org.hisp.dhis.trackedentity.TrackedEntityAttribute; +import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; +import org.hisp.dhis.trackedentity.TrackedEntityInstance; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserAuthorityGroup; import org.hisp.dhis.user.UserService; import org.hisp.dhis.validation.ValidationCriteria; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.google.common.collect.Sets; @@ -53,6 +66,16 @@ public class DefaultProgramService implements ProgramService { + private static final String TAG_OPEN = "<"; + + private static final String TAG_CLOSE = "/>"; + + private static final String PROGRAM_INCIDENT_DATE = "dateOfIncident"; + + private static final String PROGRAM_ENROLLMENT_DATE = "enrollmentDate"; + + private static final String DOB_FIELD = "@DOB_FIELD"; + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -85,6 +108,12 @@ this.userService = userService; } + @Autowired + private TrackedEntityAttributeService attributeService; + + @Autowired + private TrackedEntityAttributeValueService attributeValueService; + // ------------------------------------------------------------------------- // Implementation methods // ------------------------------------------------------------------------- @@ -278,4 +307,261 @@ return programs; } + + + @Override + public String prepareDataEntryFormForAdd( String htmlCode, Program program, Collection healthWorkers, + TrackedEntityInstance instance, ProgramInstance programInstance, I18n i18n, I18nFormat format ) + { + int index = 1; + + StringBuffer sb = new StringBuffer(); + + Matcher inputMatcher = INPUT_PATTERN.matcher( htmlCode ); + + boolean hasBirthdate = false; + boolean hasAge = false; + + while ( inputMatcher.find() ) + { + // ----------------------------------------------------------------- + // Get HTML input field code + // ----------------------------------------------------------------- + + String inputHtml = inputMatcher.group(); + Matcher dynamicAttrMatcher = DYNAMIC_ATTRIBUTE_PATTERN.matcher( inputHtml ); + Matcher programMatcher = PROGRAM_PATTERN.matcher( inputHtml ); + + index++; + + String hidden = ""; + String style = ""; + Matcher classMarcher = CLASS_PATTERN.matcher( inputHtml ); + if ( classMarcher.find() ) + { + hidden = classMarcher.group( 2 ); + } + + Matcher styleMarcher = STYLE_PATTERN.matcher( inputHtml ); + if ( styleMarcher.find() ) + { + style = styleMarcher.group( 2 ); + } + + if ( dynamicAttrMatcher.find() && dynamicAttrMatcher.groupCount() > 0 ) + { + String uid = dynamicAttrMatcher.group( 1 ); + TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid ); + + if ( attribute == null ) + { + inputHtml = "/"; + } + else + { + // Get value + String value = ""; + if ( instance != null ) + { + TrackedEntityAttributeValue attributeValue = attributeValueService + .getTrackedEntityAttributeValue( instance, attribute ); + if ( attributeValue != null ) + { + value = attributeValue.getValue(); + } + } + + inputHtml = getAttributeField( inputHtml, attribute, program, value, i18n, index, hidden, style ); + + } + + } + else if ( programMatcher.find() && programMatcher.groupCount() > 0 ) + { + String property = programMatcher.group( 1 ); + + // Get value + String value = ""; + if ( programInstance != null ) + { + value = format.formatDate( ((Date) getValueFromProgram( StringUtils.capitalize( property ), + programInstance )) ); + } + + inputHtml = ""; + } + else + { + inputHtml += ""; + } + } + else if ( property.equals( PROGRAM_INCIDENT_DATE ) ) + { + if ( program != null && program.getSelectIncidentDatesInFuture() ) + { + inputHtml += ""; + } + else + { + inputHtml += ""; + } + } + } + + inputMatcher.appendReplacement( sb, inputHtml ); + } + + inputMatcher.appendTail( sb ); + + String entryForm = sb.toString(); + String dobType = ""; + if ( hasBirthdate && hasAge ) + { + dobType = ""; + } + else if ( hasBirthdate ) + { + dobType = ""; + } + else if ( hasAge ) + { + dobType = ""; + } + + entryForm = entryForm.replaceFirst( DOB_FIELD, dobType ); + entryForm = entryForm.replaceAll( DOB_FIELD, "" ); + + return entryForm; + } + + // ------------------------------------------------------------------------- + // Supportive methods + // ------------------------------------------------------------------------- + + private String getAttributeField( String inputHtml, TrackedEntityAttribute attribute, Program program, + String value, I18n i18n, int index, String hidden, String style ) + { + boolean mandatory = false; + boolean allowDateInFuture = false; + + if ( program != null && program.getAttribute( attribute ) != null ) + { + ProgramTrackedEntityAttribute programAttribute = program.getAttribute( attribute ); + mandatory = programAttribute.isMandatory(); + allowDateInFuture = programAttribute.getAllowFutureDate(); + } + + inputHtml = TAG_OPEN + "input id=\"attr" + attribute.getId() + "\" name=\"attr" + attribute.getId() + + "\" tabindex=\"" + index + "\" style=\"" + style + "\""; + + inputHtml += "\" class=\"" + hidden + " {validate:{required:" + mandatory; + if ( TrackedEntityAttribute.TYPE_NUMBER.equals( attribute.getValueType() ) ) + { + inputHtml += ",number:true"; + } + else if ( TrackedEntityAttribute.TYPE_PHONE_NUMBER.equals( attribute.getValueType() ) ) + { + inputHtml += ",phone:true"; + } + inputHtml += "}}\" "; + + + if ( attribute.getValueType().equals( TrackedEntityAttribute.TYPE_PHONE_NUMBER ) ) + { + inputHtml += " phoneNumber value=\"" + value + "\"" + TAG_CLOSE; + } + else if ( attribute.getValueType().equals( TrackedEntityAttribute.TYPE_TRUE_ONLY ) ) + { + inputHtml += " type='checkbox' value='true' "; + if ( value.equals( "true" ) ) + { + inputHtml += " checked "; + } + } + else if ( attribute.getValueType().equals( TrackedEntityAttribute.TYPE_BOOL ) ) + { + inputHtml = inputHtml.replaceFirst( "input", "select" ) + ">"; + + if ( value.equals( "" ) ) + { + inputHtml += ""; + inputHtml += ""; + inputHtml += ""; + } + else if ( value.equals( "true" ) ) + { + inputHtml += ""; + inputHtml += ""; + inputHtml += ""; + } + else if ( value.equals( "false" ) ) + { + inputHtml += ""; + inputHtml += ""; + inputHtml += ""; + } + + inputHtml += ""; + } + else if ( attribute.getValueType().equals( TrackedEntityAttribute.TYPE_OPTION_SET ) ) + { + inputHtml = inputHtml.replaceFirst( "input", "select" ) + ">"; + inputHtml += ""; + for ( Option option : attribute.getOptionSet().getOptions() ) + { + String optionValue = option.getName(); + inputHtml += "