Skip to content

Commit

Permalink
Integrated the possibility to import limited metadata by Excel workbo…
Browse files Browse the repository at this point in the history
…ok. (#1)

* Adds support for importing from Excel sheet.
  • Loading branch information
volsch authored May 26, 2019
1 parent 3f0ecc8 commit 0575bf3
Show file tree
Hide file tree
Showing 46 changed files with 3,242 additions and 18 deletions.
5 changes: 5 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<artifactId>dhis2-fhir-adapter-fhir</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.dhis2.fhir.adapter</groupId>
<artifactId>dhis2-fhir-adapter-metadata-sheet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.dhis2.fhir.adapter</groupId>
<artifactId>dhis2-fhir-adapter-fhir-dstu3</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/resources/default-application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ server:
port: 8081

spring:
servlet:
# Configuration of multipart requests. These are used for metadata sheet
# upload only.
multipart:
max-file-size: 50MB
max-request-size: 50MB
# Settings for the database connection.
datasource:
# The JDBC URL of the database in which the Adapter tables are located.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.dhis2.fhir.adapter.model;

/*
* 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 @@ -68,7 +68,7 @@ public enum ValueType
USERNAME( String.class ),
FILE_RESOURCE( String.class ),
COORDINATE( Location.class ),
ORGANIZATION_UNIT( Id.class ),
ORGANISATION_UNIT( Id.class ),
AGE( ZonedDateTime.class ),
URL( String.class ),
IMAGE( String.class );
Expand Down
19 changes: 18 additions & 1 deletion common/src/main/java/org/dhis2/fhir/adapter/util/NameUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

/**
* Name utilities for converting to enum constants and class names.
*
* @author volsch
*/
public abstract class NameUtils
{
Expand Down Expand Up @@ -90,7 +92,7 @@ public static String toEnumName( @Nullable Object value )
{
return stringValue;
}
if ( StringUtils.isAllUpperCase( stringValue ) )
if ( containsNoLowerCase( stringValue ) )
{
return stringValue.replace( '-', '_' );
}
Expand All @@ -99,6 +101,21 @@ public static String toEnumName( @Nullable Object value )
.filter( v -> !v.equals( "_" ) ).collect( Collectors.joining( "_" ) ).toUpperCase();
}

private static boolean containsNoLowerCase( @Nonnull String value )
{
final int length = value.length();

for ( int i = 0; i < length; i++ )
{
if ( Character.isLowerCase( value.charAt( i ) ) )
{
return false;
}
}

return true;
}

private NameUtils()
{
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ public void toEnumNameCamelCaseLower()
Assert.assertEquals( "TEST_VALUE_1", NameUtils.toEnumName( "testValue1" ) );
}

@Test
public void toEnumNameUnchanged2()
{
Assert.assertEquals( "DSTU3", NameUtils.toEnumName( "DSTU3" ) );
}

@Test
public void toClassNameNull()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,22 @@ public StringToReferenceConverter()
public Reference doConvert( @Nonnull String source ) throws ConversionException
{
final int index = source.indexOf( SEPARATOR );
final ReferenceType referenceType;

if ( (index <= 0) || (index + 1 == source.length()) )
{
throw new ConversionException( "Reference does not include required separator: " + source );
}
return new Reference( source.substring( index + 1 ), NameUtils.toEnumValue( ReferenceType.class, source.substring( 0, index ) ) );

try
{
referenceType = NameUtils.toEnumValue( ReferenceType.class, source.substring( 0, index ) );
}
catch ( IllegalArgumentException e )
{
throw new ConversionException( "Reference type is invalid: " + source );
}

return new Reference( source.substring( index + 1 ), referenceType );
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.dhis2.fhir.adapter.dhis.model;

/*
* 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 @@ -39,7 +39,7 @@
* @author volsch
*/
@Scriptable
public interface DataElement
public interface DataElement extends DhisType
{
String getId();

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

/*
* 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 @@ -36,6 +36,7 @@

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

/**
* Immutable implementation of {@link DataElement} that may delegate to a mutable
Expand Down Expand Up @@ -106,4 +107,19 @@ public OptionSet getOptionSet()
{
return (delegate.getOptionSet() == null) ? null : new ImmutableOptionSet( delegate.getOptionSet() );
}

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

@JsonIgnore
@Override
public boolean isReference( @Nonnull Reference reference )
{
return delegate.isReference( reference );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ public Reference convertToEntityAttribute( String dbData )
return null;
}
final int index = dbData.indexOf( SEPARATOR );

if ( (index <= 0) || (index + 1 == dbData.length()) )
{
throw new IllegalArgumentException( "Reference does not include required separator: " + dbData );
}

return new Reference( dbData.substring( index + 1 ), NameUtils.toEnumValue( ReferenceType.class, dbData.substring( 0, index ) ) );
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.dhis2.fhir.adapter.dhis.model;

/*
* 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 @@ -38,7 +38,7 @@
*
* @author volsch
*/
public class WritableDataElement implements DataElement, Serializable
public class WritableDataElement extends AbstractDhisType implements DataElement, Serializable
{
private static final long serialVersionUID = -3933887626350878763L;

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

/*
* 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 @@ -55,7 +55,7 @@ public void convert()
Assert.assertEquals( new Reference( "678", ReferenceType.CODE ), converter.convert( "CODE:678" ) );
}

@Test( expected = IllegalArgumentException.class )
@Test( expected = ConversionException.class )
public void convertInvalidCode()
{
converter.convert( "COD:678" );
Expand Down
2 changes: 0 additions & 2 deletions fhir/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@
</dependencies>

<build>
<finalName>dhis2-fhir-adapter</finalName>

<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
@Entity
@Table( name = "fhir_code" )
@JsonFilter( value = AdapterBeanPropertyFilter.FILTER_NAME )
public class Code extends VersionedBaseMetadata implements Serializable
public class Code extends VersionedBaseMetadata implements CodeCategoryAware, Serializable
{
private static final long serialVersionUID = 6376382638316116368L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.UUID;

/**
* Contains the category of a {@linkplain Code code}. E.g. there may be multiple codes for the category "vaccine".
Expand All @@ -56,6 +57,8 @@ public class CodeCategory extends VersionedBaseMetadata implements Serializable

public static final int MAX_CODE_LENGTH = 50;

public static final UUID UNSPECIFIED_CATEGORY_ID = UUID.fromString( "8f0363dc-632d-4ccf-ba07-0da5eff6be97" );

@NotBlank
@Size( max = MAX_NAME_LENGTH )
private String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.dhis2.fhir.adapter.fhir.metadata.model;

/*
* 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.
*/

/**
* Implemented by metadata classes that contain a code category.
*
* @author volsch
*/
public interface CodeCategoryAware
{
/**
* @return the assigned code category.
*/
CodeCategory getCodeCategory();

/**
* @param codeCategory the code category to assign.
*/
void setCodeCategory( CodeCategory codeCategory );
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
@Entity
@Table( name = "fhir_code_set" )
@JsonFilter( AdapterBeanPropertyFilter.FILTER_NAME )
public class CodeSet extends VersionedBaseMetadata implements Serializable
public class CodeSet extends VersionedBaseMetadata implements CodeCategoryAware, Serializable
{
private static final long serialVersionUID = 1177970691904984600L;

Expand Down Expand Up @@ -136,7 +136,7 @@ public void setCodeCategory( CodeCategory codeCategory )
}

@JsonCacheIgnore
@Access( AccessType.PROPERTY )
@Access( AccessType.FIELD )
@OneToMany( orphanRemoval = true, mappedBy = "codeSet", cascade = CascadeType.ALL )
@OrderBy( "id" )
@BatchSize( size = 100 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import javax.annotation.Nonnull;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
Expand All @@ -61,6 +62,10 @@ default Class<CodeSet> getEntityType()
return CodeSet.class;
}

@Nonnull
@RestResource( exported = false )
Optional<CodeSet> findOneByCode( @Nonnull String code );

@Override
@Nonnull
@CacheEvict( allEntries = true )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.dhis2.fhir.adapter.fhir.metadata.repository;

/*
* 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,6 +29,7 @@
*/

import org.dhis2.fhir.adapter.dhis.model.Reference;
import org.dhis2.fhir.adapter.fhir.metadata.model.MappedTrackerProgram;
import org.dhis2.fhir.adapter.fhir.metadata.model.ProgramStageRule;
import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo;
import org.springframework.data.rest.core.annotation.RestResource;
Expand All @@ -47,4 +48,7 @@ public interface CustomProgramStageRuleRepository
@RestResource( exported = false )
@Nonnull
Collection<RuleInfo<ProgramStageRule>> findAllExp( @Nonnull Collection<Reference> programReferences, @Nonnull Collection<Reference> programStageReferences, @Nullable Collection<Reference> dataReferences );

@RestResource( exported = false )
void deleteAllByProgram( @Nonnull MappedTrackerProgram program );
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import javax.annotation.Nonnull;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
Expand All @@ -61,6 +62,10 @@ default Class<ExecutableScript> getEntityType()
return ExecutableScript.class;
}

@Nonnull
@RestResource( exported = false )
Optional<ExecutableScript> findOneByCode( @Nonnull String code );

@Override
@Nonnull
@CacheEvict( allEntries = true )
Expand Down
Loading

0 comments on commit 0575bf3

Please sign in to comment.