Skip to content

Commit

Permalink
Start of transformation from DHIS to FHIR.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Dec 10, 2018
1 parent 3b10c92 commit 56daaba
Show file tree
Hide file tree
Showing 51 changed files with 1,188 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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.
*/

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
* Abstract implementation of {@link DhisType}.
*
* @author volsch
*/
public abstract class AbstractDhisType implements DhisType, Serializable
{
private static final long serialVersionUID = 7960220674294587120L;

@JsonIgnore
@Nonnull
@Override
public Set<Reference> getAllReferences()
{
final Set<Reference> references = new HashSet<>();
if ( getId() != null )
{
references.add( new Reference( getId(), ReferenceType.ID ) );
}
if ( getCode() != null )
{
references.add( new Reference( getCode(), ReferenceType.CODE ) );
}
if ( getName() != null )
{
references.add( new Reference( getName(), ReferenceType.NAME ) );
}
return references;
}
}
58 changes: 58 additions & 0 deletions dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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.
*/

import org.dhis2.fhir.adapter.model.Identifiable;

import javax.annotation.Nonnull;
import java.util.Set;

/**
* Implemented by DHIS 2 types.
*
* @author volsch
*/
public interface DhisType extends Identifiable<String>
{
/**
* @return the unique code of the type or <code>null</code> if the type has no code.
*/
String getCode();

/**
* @return the unique name of the type.
*/
String getName();

/**
* @return all references that can be used to reference this type.
*/
@Nonnull
Set<Reference> getAllReferences();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import org.dhis2.fhir.adapter.dhis.tracker.program.EnrollmentService;
import org.dhis2.fhir.adapter.dhis.tracker.program.Event;
import org.dhis2.fhir.adapter.dhis.tracker.program.EventService;
import org.dhis2.fhir.adapter.dhis.tracker.program.ProgramMetadataService;
import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityInstance;
import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityMetadataService;
import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -57,18 +59,22 @@ public class DhisResourceRepositoryImpl implements DhisResourceRepository

private final TrackedEntityService trackedEntityService;

private final TrackedEntityMetadataService trackedEntityMetadataService;

private final EnrollmentService enrollmentService;

private final EventService eventService;

public DhisResourceRepositoryImpl(
@Nonnull TrackedEntityService trackedEntityService,
@Nonnull EnrollmentService enrollmentService,
@Nonnull EventService eventService )
private final ProgramMetadataService programMetadataService;

public DhisResourceRepositoryImpl( @Nonnull TrackedEntityService trackedEntityService, @Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
@Nonnull EnrollmentService enrollmentService, @Nonnull EventService eventService, @Nonnull ProgramMetadataService programMetadataService )
{
this.trackedEntityService = trackedEntityService;
this.trackedEntityMetadataService = trackedEntityMetadataService;
this.enrollmentService = enrollmentService;
this.eventService = eventService;
this.programMetadataService = programMetadataService;
}

@Nonnull
Expand Down Expand Up @@ -174,5 +180,4 @@ private boolean saveEvent( @Nonnull Event event )

return updated;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

public class ImmutableProgram implements Program, Serializable
Expand All @@ -53,6 +54,14 @@ public ImmutableProgram( @Nonnull @JsonProperty( "delegate" ) WritableProgram de
this.delegate = delegate;
}

@JsonIgnore
@Override
@Nonnull
public Set<Reference> getAllReferences()
{
return delegate.getAllReferences();
}

@JsonIgnore
@Override
public String getId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

public class ImmutableProgramStage implements ProgramStage, Serializable
Expand All @@ -53,13 +54,28 @@ public ImmutableProgramStage( @Nonnull @JsonProperty( "delegate" ) WritableProgr
this.delegate = delegate;
}

@JsonIgnore
@Override
@Nonnull
public Set<Reference> getAllReferences()
{
return delegate.getAllReferences();
}

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

@JsonIgnore
@Override
public String getCode()
{
return delegate.getCode();
}

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

import org.dhis2.fhir.adapter.dhis.model.DhisType;
import org.dhis2.fhir.adapter.dhis.model.Reference;
import org.dhis2.fhir.adapter.scriptable.Scriptable;

Expand All @@ -44,14 +45,8 @@
* @author volsch
*/
@Scriptable
public interface Program
public interface Program extends DhisType
{
String getId();

String getName();

String getCode();

String getTrackedEntityTypeId();

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

import org.dhis2.fhir.adapter.dhis.model.DhisType;
import org.dhis2.fhir.adapter.dhis.model.Reference;
import org.dhis2.fhir.adapter.scriptable.Scriptable;

Expand All @@ -44,12 +45,8 @@
* @author volsch
*/
@Scriptable
public interface ProgramStage
public interface ProgramStage extends DhisType
{
String getId();

String getName();

boolean isRepeatable();

boolean isCaptureCoordinates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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.AbstractDhisType;
import org.dhis2.fhir.adapter.dhis.model.Reference;
import org.dhis2.fhir.adapter.model.Id;

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

public class WritableProgram implements Program, Serializable
public class WritableProgram extends AbstractDhisType implements Program, Serializable
{
private static final long serialVersionUID = -4906529875383953995L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.AbstractDhisType;
import org.dhis2.fhir.adapter.dhis.model.Reference;

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

public class WritableProgramStage implements ProgramStage, Serializable
public class WritableProgramStage extends AbstractDhisType implements ProgramStage, Serializable
{
private static final long serialVersionUID = -7544648580734783374L;

Expand Down Expand Up @@ -90,6 +91,13 @@ public void setName( String name )
this.name = name;
}

@Override
public String getCode()
{
// program stages do not have a code
return null;
}

@Override
public boolean isRepeatable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

@Scriptable
Expand All @@ -55,13 +56,28 @@ public ImmutableTrackedEntityType( @Nonnull @JsonProperty( "delegate" ) Writable
this.delegate = delegate;
}

@JsonIgnore
@Override
@Nonnull
public Set<Reference> getAllReferences()
{
return delegate.getAllReferences();
}

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

@JsonIgnore
@Override
public String getCode()
{
return delegate.getCode();
}

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

import org.dhis2.fhir.adapter.dhis.model.DhisType;
import org.dhis2.fhir.adapter.dhis.model.Reference;
import org.dhis2.fhir.adapter.scriptable.Scriptable;

Expand All @@ -37,12 +38,8 @@
import java.util.Optional;

@Scriptable
public interface TrackedEntityType
public interface TrackedEntityType extends DhisType
{
String getId();

String getName();

List<? extends TrackedEntityTypeAttribute> getAttributes();

@Nonnull
Expand Down
Loading

0 comments on commit 56daaba

Please sign in to comment.