Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PI Disaggregation objects [DHIS2-18745] #19601

Draft
wants to merge 2 commits into
base: DHIS2-18745
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public class Program extends BaseNameableObject implements VersionedObject, Meta
/** Property indicating level of access */
private AccessLevel accessLevel = AccessLevel.OPEN;

private Set<ProgramCategoryMapping> categoryMappings = new HashSet<>();

// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -935,6 +937,18 @@ public void setAccessLevel(AccessLevel accessLevel) {
this.accessLevel = accessLevel;
}

@JsonProperty("categoryMappings")
@JsonSerialize(contentAs = BaseIdentifiableObject.class)
@JacksonXmlElementWrapper(localName = "categoryMappings", namespace = DxfNamespaces.DXF_2_0)
@JacksonXmlProperty(localName = "categoryMappings", namespace = DxfNamespaces.DXF_2_0)
public Set<ProgramCategoryMapping> getCategoryMappings() {
return categoryMappings;
}

public void setCategoryMappings(Set<ProgramCategoryMapping> categoryMappings) {
this.categoryMappings = categoryMappings;
}

public static Program shallowCopy(Program original, Map<String, String> options) {
Program copy = new Program();
copy.setAutoFields();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2004-2022, 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.
*/
package org.hisp.dhis.program;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
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 java.util.HashSet;
import java.util.Set;
import lombok.NoArgsConstructor;
import org.hisp.dhis.category.Category;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.MetadataObject;

/**
* Defines one of the ways in which a {@link ProgramIndicator} for a {@link Program} can return
* category option combinations or attribute option combinations based on filters for the options in
* the option combinations
*
* @author Jim Grace
*/
@NoArgsConstructor
@JacksonXmlRootElement(localName = "programCategoryMapping", namespace = DxfNamespaces.DXF_2_0)
public class ProgramCategoryMapping extends BaseIdentifiableObject implements MetadataObject {

/** The program for this category mapping */
private Program program;

/** The category for this category mapping */
private Category category;

/** The category mapping name, must be unique within a program and category */
private String mappingName;

/** The category option mappings for this program, category, and name */
private Set<ProgramCategoryOptionMapping> optionMappings = new HashSet<>();

// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------

@JsonProperty
@JsonSerialize(as = BaseIdentifiableObject.class)
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Program getProgram() {
return program;
}

public void setProgram(Program program) {
this.program = program;
}

@JsonProperty
@JsonSerialize(as = BaseIdentifiableObject.class)
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Category getCategory() {
return category;
}

public void setCategory(Category category) {
this.category = category;
}

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getMappingName() {
return mappingName;
}

public void setMappingName(String mappingName) {
this.mappingName = mappingName;
}

@JsonProperty
@JacksonXmlElementWrapper(localName = "optionMappings", namespace = DxfNamespaces.DXF_2_0)
@JacksonXmlProperty(localName = "optionMapping", namespace = DxfNamespaces.DXF_2_0)
public Set<ProgramCategoryOptionMapping> getOptionMappings() {
return optionMappings;
}

public void setOptionMappings(Set<ProgramCategoryOptionMapping> optionMappings) {
this.optionMappings = optionMappings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2004-2022, 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.
*/
package org.hisp.dhis.program;

import java.util.List;

/**
* @author Jim Grace
*/
public interface ProgramCategoryMappingService {
// -------------------------------------------------------------------------
// ProgramCategoryMapping
// -------------------------------------------------------------------------

/**
* Adds a {@link ProgramCategoryMapping}
*
* @param programCategoryMapping The ProgramCategoryMapping to add.
* @return A generated unique id of the added {@link ProgramCategoryMapping}.
*/
long saveProgramCategoryMapping(ProgramCategoryMapping programCategoryMapping);

/**
* Deletes a {@link ProgramCategoryMapping}.
*
* @param programCategoryMapping the ProgramCategoryMapping to delete.
*/
void deleteProgramCategoryMapping(ProgramCategoryMapping programCategoryMapping);

/**
* Updates an {@link ProgramCategoryMapping}.
*
* @param programCategoryMapping the ProgramCategoryMapping to update.
*/
void updateProgramCategoryMapping(ProgramCategoryMapping programCategoryMapping);

/**
* Returns a {@link ProgramCategoryMapping}.
*
* @param id the id of the ProgramCategoryMapping to return.
* @return the ProgramCategoryMapping with the given id
*/
ProgramCategoryMapping getProgramCategoryMapping(long id);

/**
* Returns the {@link ProgramCategoryMapping} with the given UID.
*
* @param uid the UID.
* @return the ProgramCategoryMapping with the given UID, or null if no match.
*/
ProgramCategoryMapping getProgramCategoryMapping(String uid);

/**
* Retrieve all ProgramCategoryMappings associated with the given {@link Program}.
*
* @param program the Program.
* @return a list og ProgramCategoryMappings.
*/
List<ProgramCategoryMapping> getProgramCategoryMappingsByProgram(Program program);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2004-2022, 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.
*/
package org.hisp.dhis.program;

import java.util.List;
import org.hisp.dhis.common.IdentifiableObjectStore;

/**
* @author Jim Grace
*/
public interface ProgramCategoryMappingStore
extends IdentifiableObjectStore<ProgramCategoryMapping> {
/**
* Returns a list of program category mappings for a program
*
* @param program the program for which the category mappings are desired
* @return a list of program category mappings for that program
*/
List<ProgramCategoryMapping> getByProgram(Program program);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2004-2022, 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.
*/
package org.hisp.dhis.program;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.NoArgsConstructor;
import org.hisp.dhis.category.CategoryOption;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.EmbeddedObject;

/**
* Defines a filter expression fragment for a {@link CategoryOption} within a {@link
* ProgramCategoryMapping} to identify an option in a category option combination or an attribute
* option combination to be returned as a program indicator dimension.
*
* @author Jim Grace
*/
@NoArgsConstructor
@JacksonXmlRootElement(localName = "optionMappings", namespace = DxfNamespaces.DXF_2_0)
public class ProgramCategoryOptionMapping implements EmbeddedObject {

/** The database internal identifier for this Object. */
private int id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id column is mapped as bigint in database so I think it should be long java type.


/** The program category mapping */
private ProgramCategoryMapping categoryMapping;

/** The category option to be mapped */
private CategoryOption categoryOption;

/** The filter for this category option */
private String filter;

// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------

@JsonIgnore
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public ProgramCategoryMapping getCategoryMapping() {
return categoryMapping;
}

public void setCategoryMapping(ProgramCategoryMapping categoryMapping) {
this.categoryMapping = categoryMapping;
}

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public CategoryOption getCategoryOption() {
return categoryOption;
}

public void setCategoryOption(CategoryOption categoryOption) {
this.categoryOption = categoryOption;
}

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getFilter() {
return filter;
}

public void setFilter(String filter) {
this.filter = filter;
}
}
Loading
Loading