Skip to content

Commit

Permalink
Merge branch 'OpenLMIS-MeasureReport-integration'
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Aug 6, 2019
2 parents 57c5a02 + 5dcf9f7 commit 893944a
Show file tree
Hide file tree
Showing 27 changed files with 1,831 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ private void getPlanDefinition() throws Exception
.andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );
userDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", "Basic Zmhpcl9jbGllbnQ6Zmhpcl9jbGllbnRfMQ==" ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&fields=id,name,code,description,lastUpdated,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration," +
"withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name," +
"withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid," +
"program%5Bid%5D,lastUpdated,name," +
"description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name," +
"options%5Bcode,name%5D%5D%5D%5D%5D" ) )
.andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/all-programs.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );
Expand Down Expand Up @@ -153,7 +154,8 @@ private void getPlanDefinitionNotExists()

userDhis2Server.expect( ExpectedCount.once(), method( HttpMethod.GET ) ).andExpect( header( "Authorization", "Basic Zmhpcl9jbGllbnQ6Zmhpcl9jbGllbnRfMQ==" ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs/0dXIdLNUNEn.json?fields=id,name,code,description,lastUpdated,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration," +
"withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name," +
"withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid," +
"program%5Bid%5D,lastUpdated,name," +
"description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name," +
"options%5Bcode,name%5D%5D%5D%5D%5D" ) )
.andRespond( withStatus( HttpStatus.NOT_FOUND ).contentType( MediaType.APPLICATION_JSON ).body( "{}" ) );
Expand Down Expand Up @@ -218,7 +220,8 @@ public void getPlanDefinitionByIdentifierInvalidAuthorization()
userDhis2Server.expect( ExpectedCount.once(), method( HttpMethod.GET ) ).andExpect( header( "Authorization", "Basic Zmhpcl9jbGllbnQ6aW52YWxpZF8x" ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion +
"/programs.json?paging=false&fields=id,name,code,description,lastUpdated,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration," +
"captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name,description,repeatable," +
"captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name," +
"description,repeatable," +
"captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," +
"name%5D%5D%5D%5D%5D&filter=code:eq:OU_1234" ) )
.andRespond( withStatus( HttpStatus.UNAUTHORIZED ) );
Expand Down Expand Up @@ -247,7 +250,8 @@ private void getPlanDefinitionByIdentifier() throws Exception
userDhis2Server.expect( ExpectedCount.between( 1, 2 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", "Basic Zmhpcl9jbGllbnQ6Zmhpcl9jbGllbnRfMQ==" ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&fields=id,name,code,description,lastUpdated,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration," +
"withoutRegistration," +
"captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name,description,repeatable," +
"captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name," +
"description,repeatable," +
"captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," +
"name%5D%5D%5D%5D%5D&filter=code:eq:PD_1234" ) )
.andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/default-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );
Expand Down Expand Up @@ -275,7 +279,8 @@ public void searchPlanDefinitionWithoutAuthorization()
public void searchPlanDefinitionInvalidAuthorization()
{
userDhis2Server.expect( ExpectedCount.once(), method( HttpMethod.GET ) ).andExpect( header( "Authorization", "Basic Zmhpcl9jbGllbnQ6aW52YWxpZF8x" ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?filter=name:$ilike:Test&paging=true&page=1&pageSize=10&order=id&fields=id,name,code,description,lastUpdated,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture," +
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?filter=name:$ilike:Test&paging=true&page=1&pageSize=10&order=id&fields=id,name,code,description,lastUpdated,selectIncidentDatesInFuture," +
"selectEnrollmentDatesInFuture," +
"displayIncidentDate,registration,withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D," +
"programStages%5Bid,program%5Bid%5D,lastUpdated,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName," +
"valueType,optionSetValue," +
Expand All @@ -297,7 +302,8 @@ public void searchPlanDefinition() throws Exception
userDhis2Server.expect( ExpectedCount.once(), method( HttpMethod.GET ) ).andExpect( header( "Authorization", "Basic Zmhpcl9jbGllbnQ6Zmhpcl9jbGllbnRfMQ==" ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?filter=name:$ilike:Child%20Programme&paging=true&page=1&pageSize=10&order=id&fields=id,name,code,description,lastUpdated,selectIncidentDatesInFuture," +
"selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name," +
"code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName," +
"code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere," +
"dataElement%5Bid,name,code,formName," +
"valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) )
.andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/default-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.dhis2.fhir.adapter.spring;

/*
* Copyright (c) 2004-2018, University of Oslo
* Copyright (c) 2004-2019, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,9 +29,11 @@
*/

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.ObjectProvider;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Object provider for a static non-null object.
Expand All @@ -42,7 +44,7 @@ public class StaticObjectProvider<T> implements ObjectProvider<T>
{
private final T object;

public StaticObjectProvider( @Nonnull T object )
public StaticObjectProvider( @Nullable T object )
{
this.object = object;
}
Expand All @@ -51,6 +53,11 @@ public StaticObjectProvider( @Nonnull T object )
@Nonnull
public T getObject( @Nonnull Object... args ) throws BeansException
{
if ( object == null )
{
throw new BeanCreationException( "Bean has not been provided." );
}

return object;
}

Expand All @@ -70,6 +77,11 @@ public T getIfUnique() throws BeansException
@Nonnull
public T getObject() throws BeansException
{
if ( object == null )
{
throw new BeanCreationException( "Bean has not been provided." );
}

return object;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
package org.dhis2.fhir.adapter.dhis.aggregate;

/*
* Copyright (c) 2004-2019, 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.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.DataValue;
import org.dhis2.fhir.adapter.dhis.model.DhisResource;
import org.dhis2.fhir.adapter.dhis.model.DhisResourceId;
import org.dhis2.fhir.adapter.dhis.model.DhisResourceType;
import org.dhis2.fhir.adapter.dhis.model.WritableDataValue;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* @author David Katuscak
*/
public class DataValueSet implements DhisResource, Serializable
{
// reporter > reference -> Organisation unit
// period > start/end -> Period
// group > code > text -> Data element
// group > measurescore -> Data value
//
// orgUnit
// period
// dataElement
// dataValue

private static final long serialVersionUID = 6347075531883647618L;

@JsonProperty( access = JsonProperty.Access.WRITE_ONLY )
private boolean deleted;

@JsonIgnore
private boolean modified;

@JsonIgnore
private boolean newResource;

@JsonIgnore
private boolean local;

@JsonProperty
@JsonInclude( JsonInclude.Include.NON_NULL )
private ZonedDateTime lastUpdated;

@JsonProperty( "dataValueSet" )
@JsonInclude( JsonInclude.Include.NON_NULL )
private String id;

@JsonProperty( "dataSet" )
private String dataSetId;

@JsonProperty( "orgUnit" )
private String orgUnitId;

@JsonProperty
private String period;

private List<WritableDataValue> dataValues;

public DataValueSet()
{
super();
}

public DataValueSet( @Nonnull String id )
{
this.id = id;
}

public DataValueSet( boolean newResource )
{
this.newResource = newResource;
this.modified = newResource;
this.local = newResource;
this.dataValues = new ArrayList<>();
}

@Override
@JsonIgnore
public String getId()
{
return id;
}

@Override
public void setId( String id )
{
this.id = id;
}

@Override
public DhisResourceId getResourceId()
{
return (getId() == null) ? null : new DhisResourceId( DhisResourceType.DATA_VALUE_SET, getId() );
}

@Override
public String getOrgUnitId()
{
return orgUnitId;
}

public void setOrgUnitId( String orgUnitId )
{
this.orgUnitId = orgUnitId;
}

public String getPeriod()
{
return period;
}

public void setPeriod( String period )
{
this.period = period;
}

public String getDataSetId()
{
return dataSetId;
}

public void setDataSetId( String dataSetId )
{
this.dataSetId = dataSetId;
}

@JsonIgnore
@Nonnull
@Override
public DhisResourceType getResourceType()
{
return DhisResourceType.DATA_VALUE_SET;
}

@Override
public boolean isNewResource()
{
return newResource;
}

@Override
public void resetNewResource()
{
this.newResource = false;
this.modified = false;

if ( lastUpdated == null )
{
lastUpdated = ZonedDateTime.now();
}
}

@Override
public boolean isLocal()
{
return local;
}

public void setLocal( boolean local )
{
this.local = local;
}

public boolean isModified()
{
return modified;
}

public void setModified( boolean modified )
{
this.modified = modified;
}

@Override
public boolean isDeleted()
{
return deleted;
}

@Override
public ZonedDateTime getLastUpdated()
{
return lastUpdated;
}

public void setLastUpdated( ZonedDateTime lastUpdated )
{
this.lastUpdated = lastUpdated;
}

public List<WritableDataValue> getDataValues()
{
return dataValues;
}

public void setDataValues( List<WritableDataValue> dataValues )
{
this.dataValues = dataValues;
}

public boolean containsDataValue( @Nonnull String dataElementId )
{
return getDataValues().stream().anyMatch( dv -> Objects.equals( dataElementId, dv.getDataElementId() ) );
}

public boolean containsDataValue( @Nonnull String dataElementId, @Nonnull String value )
{
return getDataValues().stream()
.anyMatch( dv -> Objects.equals( dataElementId, dv.getDataElementId() )
&& dv.getValue() != null
&& Objects.equals( value, String.valueOf( dv.getValue() ) ) );
}

public boolean containsDataValueWithValue( @Nonnull String dataElementId )
{
return getDataValues().stream()
.filter( dv -> ( dv.getValue() != null ) )
.anyMatch( dv -> Objects.equals( dataElementId, dv.getDataElementId() ) );
}

@Nonnull
public WritableDataValue getDataValue( @Nonnull String dataElementId )
{
if ( getDataValues() == null )
{
setDataValues( new ArrayList<>() );
}

WritableDataValue dataValue = getDataValues().stream()
.filter( dv -> Objects.equals( dataElementId, dv.getDataElementId() ) )
.findFirst()
.orElse( null );

if ( dataValue == null )
{
dataValue = new WritableDataValue( dataElementId, true );
getDataValues().add( dataValue );
}
return dataValue;
}

@JsonIgnore
public boolean isAnyDataValueModified()
{
return (getDataValues() != null) && getDataValues().stream().anyMatch( DataValue::isModified );
}
}
Loading

0 comments on commit 893944a

Please sign in to comment.