Skip to content

Commit

Permalink
Transformation from DHIS to FHIR for tracked entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Dec 11, 2018
1 parent 56daaba commit 7f6c2cb
Show file tree
Hide file tree
Showing 67 changed files with 1,140 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @author volsch
*/
@Scriptable
public class ImmutableDataElement implements DataElement, Serializable
public class ImmutableDataElement implements DataElement, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = -7040983692879273412L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*
* @author volsch
*/
public class ImmutableDataValue implements DataValue, Serializable
public class ImmutableDataValue implements DataValue, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = 5577400306112844124L;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.dhis2.fhir.adapter.dhis.model;

/*
* Copyright (c) 2004-2018, 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.
*/

/**
* Marker interface that marks immutable DHIS objects.
*
* @author volsch
*/
public interface ImmutableDhisObject
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
* @author volsch
*/
public class ImmutableOption implements Option, Serializable
public class ImmutableOption implements Option, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = -4836329163657710844L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*
* @author volsch
*/
public class ImmutableOptionSet implements OptionSet, Serializable
public class ImmutableOptionSet implements OptionSet, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = -5542523378884979052L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.dhis2.fhir.adapter.data.model.ProcessedItemInfo;
import org.dhis2.fhir.adapter.data.model.UuidDataGroupId;
import org.dhis2.fhir.adapter.data.processor.DataItemQueueItem;
Expand All @@ -55,17 +54,4 @@ public DhisResourceQueueItem( @Nonnull UuidDataGroupId dataGroupId, @Nonnull Pro
{
super( dataGroupId, processedItemInfo );
}

@JsonIgnore
@Override
public UuidDataGroupId getDataGroupId()
{
return super.getDataGroupId();
}

@Override
public void setDataGroupId( UuidDataGroupId dataGroupId )
{
super.setDataGroupId( dataGroupId );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public class Enrollment implements DhisResource, Serializable
@JsonInclude( JsonInclude.Include.NON_NULL )
private String id;

@JsonProperty( access = JsonProperty.Access.READ_ONLY )
@JsonProperty
@JsonInclude( JsonInclude.Include.NON_NULL )
private ZonedDateTime lastUpdated;

@JsonProperty( "orgUnit" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public class Event implements DhisResource, Serializable, Comparable<Event>
@JsonInclude( JsonInclude.Include.NON_NULL )
private String id;

@JsonProperty( access = JsonProperty.Access.READ_ONLY )
@JsonProperty
@JsonInclude( JsonInclude.Include.NON_NULL )
private ZonedDateTime lastUpdated;

@JsonProperty( "orgUnit" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.ImmutableDhisObject;
import org.dhis2.fhir.adapter.dhis.model.Reference;

import javax.annotation.Nonnull;
Expand All @@ -41,7 +42,7 @@
import java.util.Set;
import java.util.stream.Collectors;

public class ImmutableProgram implements Program, Serializable
public class ImmutableProgram implements Program, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = 4157706296470781519L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.ImmutableDhisObject;
import org.dhis2.fhir.adapter.dhis.model.Reference;

import javax.annotation.Nonnull;
Expand All @@ -41,7 +42,7 @@
import java.util.Set;
import java.util.stream.Collectors;

public class ImmutableProgramStage implements ProgramStage, Serializable
public class ImmutableProgramStage implements ProgramStage, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = 6563663856499434307L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.ImmutableDhisObject;
import org.dhis2.fhir.adapter.dhis.model.WritableDataElement;

import javax.annotation.Nonnull;
import java.io.Serializable;

public class ImmutableProgramStageDataElement implements ProgramStageDataElement, Serializable
public class ImmutableProgramStageDataElement implements ProgramStageDataElement, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = -5845301607041878968L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.ImmutableDhisObject;
import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.ImmutableTrackedEntityAttribute;
import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityAttribute;
import org.dhis2.fhir.adapter.model.ValueType;

import javax.annotation.Nonnull;
import java.io.Serializable;

public class ImmutableProgramTrackedEntityAttribute implements ProgramTrackedEntityAttribute, Serializable
public class ImmutableProgramTrackedEntityAttribute implements ProgramTrackedEntityAttribute, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = -6094500152005916960L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
public interface ProgramMetadataService
{
@Nonnull
Optional<? extends Program> findOneByReference( @Nonnull Reference reference );
Optional<? extends Program> findProgramByReference( @Nonnull Reference reference );
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ProgramMetadataServiceImpl( @Nonnull @Qualifier( "systemDhis2RestTemplate
@Cacheable
@Nonnull
@Override
public Optional<? extends Program> findOneByReference( @Nonnull Reference reference )
public Optional<? extends Program> findProgramByReference( @Nonnull Reference reference )
{
final ResponseEntity<DhisPrograms> result;
switch ( reference.getType() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.ImmutableDhisObject;
import org.dhis2.fhir.adapter.dhis.model.ImmutableOptionSet;
import org.dhis2.fhir.adapter.dhis.model.OptionSet;
import org.dhis2.fhir.adapter.model.ValueType;

import javax.annotation.Nonnull;
import java.io.Serializable;

public class ImmutableTrackedEntityAttribute implements TrackedEntityAttribute, Serializable
public class ImmutableTrackedEntityAttribute implements TrackedEntityAttribute, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = -6135628541438060211L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.ImmutableDhisObject;
import org.dhis2.fhir.adapter.dhis.model.Reference;
import org.dhis2.fhir.adapter.scriptable.Scriptable;

Expand All @@ -43,7 +44,7 @@
import java.util.stream.Collectors;

@Scriptable
public class ImmutableTrackedEntityType implements TrackedEntityType, Serializable
public class ImmutableTrackedEntityType implements TrackedEntityType, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = 797154293863611491L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.ImmutableDhisObject;
import org.dhis2.fhir.adapter.model.ValueType;

import javax.annotation.Nonnull;
import java.io.Serializable;

public class ImmutableTrackedEntityTypeAttribute implements TrackedEntityTypeAttribute, Serializable
public class ImmutableTrackedEntityTypeAttribute implements TrackedEntityTypeAttribute, ImmutableDhisObject, Serializable
{
private static final long serialVersionUID = -6094500152005916960L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public Optional<TrackedEntityAttribute> getOptionalById( @Nonnull String id )
Map<String, TrackedEntityAttribute> attributesById = this.attributesById;
if ( attributesById == null )
{
this.attributesById = attributesById = attributes.stream().collect( Collectors.toMap( TrackedEntityAttribute::getId, a -> a ) );
this.attributesById = attributesById = attributes.stream().map( ImmutableTrackedEntityAttribute::new )
.collect( Collectors.toMap( TrackedEntityAttribute::getId, a -> a ) );
}
return Optional.ofNullable( attributesById.get( id ) );
}
Expand All @@ -100,7 +101,8 @@ public Optional<TrackedEntityAttribute> getOptionalByCode( @Nonnull String code
Map<String, TrackedEntityAttribute> attributesByCode = this.attributesByCode;
if ( attributesByCode == null )
{
this.attributesByCode = attributesByCode = attributes.stream().filter( a -> StringUtils.isNotBlank( a.getCode() ) ).collect( Collectors.toMap( TrackedEntityAttribute::getCode, a -> a ) );
this.attributesByCode = attributesByCode = attributes.stream().filter( a -> StringUtils.isNotBlank( a.getCode() ) )
.map( ImmutableTrackedEntityAttribute::new ).collect( Collectors.toMap( TrackedEntityAttribute::getCode, a -> a ) );
}
return Optional.ofNullable( attributesByCode.get( code ) );
}
Expand All @@ -111,7 +113,8 @@ public Optional<TrackedEntityAttribute> getOptionalByName( @Nonnull String name
Map<String, TrackedEntityAttribute> attributesByName = this.attributesByName;
if ( attributesByName == null )
{
this.attributesByName = attributesByName = attributes.stream().collect( Collectors.toMap( TrackedEntityAttribute::getName, a -> a ) );
this.attributesByName = attributesByName = attributes.stream().map( ImmutableTrackedEntityAttribute::new )
.collect( Collectors.toMap( TrackedEntityAttribute::getName, a -> a ) );
}
return Optional.ofNullable( attributesByName.get( name ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class TrackedEntityInstance implements DhisResource, Serializable
@JsonInclude( JsonInclude.Include.NON_NULL )
private String id;

@JsonProperty( access = JsonProperty.Access.READ_ONLY )
@JsonProperty
@JsonInclude( JsonInclude.Include.NON_NULL )
private ZonedDateTime lastUpdated;

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public interface TrackedEntityMetadataService
{
@Nonnull
Optional<? extends TrackedEntityType> getType( @Nonnull Reference reference );
Optional<? extends TrackedEntityType> findTypeByReference( @Nonnull Reference reference );

@Nonnull
TrackedEntityAttributes getAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public TrackedEntityMetadataServiceImpl( @Nonnull @Qualifier( "systemDhis2RestTe
@Cacheable( value = "trackedEntityTypes", cacheManager = "dhisCacheManager" )
@Nonnull
@Override
public Optional<? extends TrackedEntityType> getType( @Nonnull Reference reference )
public Optional<? extends TrackedEntityType> findTypeByReference( @Nonnull Reference reference )
{
switch ( reference.getType() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void findOneByReferenceId() throws IOException
"generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) )
.andExpect( method( HttpMethod.GET ) ).andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/program.json" ), MediaType.APPLICATION_JSON ) );

Optional<? extends Program> ou = service.findOneByReference( new Reference( "93783", ReferenceType.ID ) );
Optional<? extends Program> ou = service.findProgramByReference( new Reference( "93783", ReferenceType.ID ) );
Assert.assertTrue( ou.isPresent() );
assertProgram( ou.get() );
}
Expand All @@ -96,7 +96,7 @@ public void findOneByReferenceIdNotFound()
"generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) ).andExpect( method( HttpMethod.GET ) )
.andRespond( MockRestResponseCreators.withStatus( HttpStatus.NOT_FOUND ).body( "{}" ).contentType( MediaType.APPLICATION_JSON ) );

Optional<? extends Program> ou = service.findOneByReference( new Reference( "93783", ReferenceType.ID ) );
Optional<? extends Program> ou = service.findProgramByReference( new Reference( "93783", ReferenceType.ID ) );
Assert.assertFalse( ou.isPresent() );
}

Expand All @@ -107,7 +107,7 @@ public void findOneByReferenceIdServerError()
"trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," +
"generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) ).andExpect( method( HttpMethod.GET ) )
.andRespond( MockRestResponseCreators.withServerError() );
service.findOneByReference( new Reference( "93783", ReferenceType.ID ) );
service.findProgramByReference( new Reference( "93783", ReferenceType.ID ) );
}

@Test
Expand All @@ -118,7 +118,7 @@ public void findOneByReferenceCode() throws IOException
"generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D&filter=code:eq:OU_3783" ) ).andExpect( method( HttpMethod.GET ) )
.andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/programs.json" ), MediaType.APPLICATION_JSON ) );

Optional<? extends Program> ou = service.findOneByReference( new Reference( "OU_3783", ReferenceType.CODE ) );
Optional<? extends Program> ou = service.findProgramByReference( new Reference( "OU_3783", ReferenceType.CODE ) );
Assert.assertTrue( ou.isPresent() );
assertProgram( ou.get() );
}
Expand All @@ -131,7 +131,7 @@ public void findOneByReferenceCodeNotFound() throws IOException
"generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D&filter=code:eq:OU_3783" ) ).andExpect( method( HttpMethod.GET ) )
.andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/emptyPrograms.json" ), MediaType.APPLICATION_JSON ) );

Optional<? extends Program> ou = service.findOneByReference( new Reference( "OU_3783", ReferenceType.CODE ) );
Optional<? extends Program> ou = service.findProgramByReference( new Reference( "OU_3783", ReferenceType.CODE ) );
Assert.assertFalse( ou.isPresent() );
}

Expand All @@ -143,7 +143,7 @@ public void findOneByReferenceName() throws IOException
"generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D&filter=name:eq:Freetown" ) ).andExpect( method( HttpMethod.GET ) )
.andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/programs.json" ), MediaType.APPLICATION_JSON ) );

Optional<? extends Program> ou = service.findOneByReference( new Reference( "Freetown", ReferenceType.NAME ) );
Optional<? extends Program> ou = service.findProgramByReference( new Reference( "Freetown", ReferenceType.NAME ) );
Assert.assertTrue( ou.isPresent() );
assertProgram( ou.get() );
}
Expand All @@ -156,7 +156,7 @@ public void findOneByReferenceNameNotFound() throws IOException
"generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D&filter=name:eq:Freetown" ) ).andExpect( method( HttpMethod.GET ) )
.andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/emptyPrograms.json" ), MediaType.APPLICATION_JSON ) );

Optional<? extends Program> ou = service.findOneByReference( new Reference( "Freetown", ReferenceType.NAME ) );
Optional<? extends Program> ou = service.findProgramByReference( new Reference( "Freetown", ReferenceType.NAME ) );
Assert.assertFalse( ou.isPresent() );
}

Expand Down
Loading

0 comments on commit 7f6c2cb

Please sign in to comment.