From 0575bf3428d1e9084cee6da03a7ae0dd3f64fe35 Mon Sep 17 00:00:00 2001 From: Volker Date: Sun, 26 May 2019 20:12:28 +0200 Subject: [PATCH] Integrated the possibility to import limited metadata by Excel workbook. (#1) * Adds support for importing from Excel sheet. --- app/pom.xml | 5 + .../main/resources/default-application.yml | 6 + .../dhis2/fhir/adapter/model/ValueType.java | 4 +- .../dhis2/fhir/adapter/util/NameUtils.java | 19 +- .../fhir/adapter/util/NameUtilsTest.java | 6 + .../converter/StringToReferenceConverter.java | 14 +- .../fhir/adapter/dhis/model/DataElement.java | 4 +- .../dhis/model/ImmutableDataElement.java | 18 +- .../model/ReferenceAttributeConverter.java | 2 + .../dhis/model/WritableDataElement.java | 4 +- .../StringToReferenceConverterTest.java | 4 +- fhir/pom.xml | 2 - .../adapter/fhir/metadata/model/Code.java | 2 +- .../fhir/metadata/model/CodeCategory.java | 3 + .../metadata/model/CodeCategoryAware.java | 47 ++ .../adapter/fhir/metadata/model/CodeSet.java | 4 +- .../repository/CodeSetRepository.java | 5 + .../CustomProgramStageRuleRepository.java | 6 +- .../ExecutableScriptRepository.java | 5 + .../MappedTrackedEntityRepository.java | 10 + .../MappedTrackerProgramRepository.java | 8 + .../MappedTrackerProgramStageRepository.java | 11 + .../metadata/repository/ScriptRepository.java | 4 + .../repository/SystemCodeRepository.java | 10 + .../metadata/repository/SystemRepository.java | 4 + .../TrackedEntityRuleRepository.java | 9 + .../CustomProgramStageRuleRepositoryImpl.java | 15 +- .../V1.1.0.23_0_0__Default_Filters.sql | 64 ++ metadata-sheet/pom.xml | 62 ++ .../MetadataSheetImportController.java | 118 ++++ .../controller/MetadataSheetImportResult.java | 96 +++ .../sheet/model/MetadataSheetLocation.java | 94 +++ .../sheet/model/MetadataSheetMessage.java | 88 +++ .../model/MetadataSheetMessageCollector.java | 76 +++ .../model/MetadataSheetMessageSeverity.java | 42 ++ .../AbstractMetadataSheetImportProcessor.java | 287 ++++++++ .../MetadataSheetCodeImportProcessor.java | 374 +++++++++++ .../MetadataSheetImportException.java | 68 ++ .../MetadataSheetImportProcessor.java | 102 +++ .../MetadataSheetProgramImportProcessor.java | 357 ++++++++++ .../MetadataSheetRuleImportProcessor.java | 631 ++++++++++++++++++ .../MetadataSheetScriptImportProcessor.java | 283 ++++++++ .../processor/ProgramStageDataElementKey.java | 95 +++ .../src/main/resources/static/favicon.ico | Bin 0 -> 1150 bytes .../resources/templates/metadata-sheet.html | 185 +++++ pom.xml | 7 + 46 files changed, 3242 insertions(+), 18 deletions(-) create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategoryAware.java create mode 100644 fhir/src/main/resources/db/migration/production/V1.1.0.23_0_0__Default_Filters.sql create mode 100644 metadata-sheet/pom.xml create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/controller/MetadataSheetImportController.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/controller/MetadataSheetImportResult.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/model/MetadataSheetLocation.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/model/MetadataSheetMessage.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/model/MetadataSheetMessageCollector.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/model/MetadataSheetMessageSeverity.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/AbstractMetadataSheetImportProcessor.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetCodeImportProcessor.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetImportException.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetImportProcessor.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetProgramImportProcessor.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetRuleImportProcessor.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetScriptImportProcessor.java create mode 100644 metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/ProgramStageDataElementKey.java create mode 100644 metadata-sheet/src/main/resources/static/favicon.ico create mode 100644 metadata-sheet/src/main/resources/templates/metadata-sheet.html diff --git a/app/pom.xml b/app/pom.xml index 95019079..bb203037 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -69,6 +69,11 @@ dhis2-fhir-adapter-fhir ${project.version} + + org.dhis2.fhir.adapter + dhis2-fhir-adapter-metadata-sheet + ${project.version} + org.dhis2.fhir.adapter dhis2-fhir-adapter-fhir-dstu3 diff --git a/app/src/main/resources/default-application.yml b/app/src/main/resources/default-application.yml index ffb24038..b2fdd708 100644 --- a/app/src/main/resources/default-application.yml +++ b/app/src/main/resources/default-application.yml @@ -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. diff --git a/common/src/main/java/org/dhis2/fhir/adapter/model/ValueType.java b/common/src/main/java/org/dhis2/fhir/adapter/model/ValueType.java index f1d1511a..ea16137c 100644 --- a/common/src/main/java/org/dhis2/fhir/adapter/model/ValueType.java +++ b/common/src/main/java/org/dhis2/fhir/adapter/model/ValueType.java @@ -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 @@ -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 ); diff --git a/common/src/main/java/org/dhis2/fhir/adapter/util/NameUtils.java b/common/src/main/java/org/dhis2/fhir/adapter/util/NameUtils.java index 5ff18c58..33bc1c60 100644 --- a/common/src/main/java/org/dhis2/fhir/adapter/util/NameUtils.java +++ b/common/src/main/java/org/dhis2/fhir/adapter/util/NameUtils.java @@ -39,6 +39,8 @@ /** * Name utilities for converting to enum constants and class names. + * + * @author volsch */ public abstract class NameUtils { @@ -90,7 +92,7 @@ public static String toEnumName( @Nullable Object value ) { return stringValue; } - if ( StringUtils.isAllUpperCase( stringValue ) ) + if ( containsNoLowerCase( stringValue ) ) { return stringValue.replace( '-', '_' ); } @@ -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(); diff --git a/common/src/test/java/org/dhis2/fhir/adapter/util/NameUtilsTest.java b/common/src/test/java/org/dhis2/fhir/adapter/util/NameUtilsTest.java index e8f60a4c..3bff4eb8 100644 --- a/common/src/test/java/org/dhis2/fhir/adapter/util/NameUtilsTest.java +++ b/common/src/test/java/org/dhis2/fhir/adapter/util/NameUtilsTest.java @@ -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() { diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/converter/StringToReferenceConverter.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/converter/StringToReferenceConverter.java index fa4ab64f..93988903 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/converter/StringToReferenceConverter.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/converter/StringToReferenceConverter.java @@ -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 ); } } diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DataElement.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DataElement.java index 433ba1ed..547d5c9c 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DataElement.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DataElement.java @@ -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 @@ -39,7 +39,7 @@ * @author volsch */ @Scriptable -public interface DataElement +public interface DataElement extends DhisType { String getId(); diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ImmutableDataElement.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ImmutableDataElement.java index c27efa52..f2ae7262 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ImmutableDataElement.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ImmutableDataElement.java @@ -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 @@ -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 @@ -106,4 +107,19 @@ public OptionSet getOptionSet() { return (delegate.getOptionSet() == null) ? null : new ImmutableOptionSet( delegate.getOptionSet() ); } + + @JsonIgnore + @Nonnull + @Override + public Set getAllReferences() + { + return delegate.getAllReferences(); + } + + @JsonIgnore + @Override + public boolean isReference( @Nonnull Reference reference ) + { + return delegate.isReference( reference ); + } } diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ReferenceAttributeConverter.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ReferenceAttributeConverter.java index 50de0531..ea2c9fd5 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ReferenceAttributeConverter.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ReferenceAttributeConverter.java @@ -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 ) ) ); } } diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/WritableDataElement.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/WritableDataElement.java index 6de2db4d..0a889702 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/WritableDataElement.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/WritableDataElement.java @@ -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 @@ -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; diff --git a/dhis/src/test/java/org/dhis2/fhir/adapter/dhis/converter/StringToReferenceConverterTest.java b/dhis/src/test/java/org/dhis2/fhir/adapter/dhis/converter/StringToReferenceConverterTest.java index 714acfba..a8c0ec8b 100644 --- a/dhis/src/test/java/org/dhis2/fhir/adapter/dhis/converter/StringToReferenceConverterTest.java +++ b/dhis/src/test/java/org/dhis2/fhir/adapter/dhis/converter/StringToReferenceConverterTest.java @@ -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 @@ -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" ); diff --git a/fhir/pom.xml b/fhir/pom.xml index ce9c6912..a7d46e31 100644 --- a/fhir/pom.xml +++ b/fhir/pom.xml @@ -111,8 +111,6 @@ - dhis2-fhir-adapter - com.mysema.maven diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Code.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Code.java index d751bbc7..804479f8 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Code.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Code.java @@ -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; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategory.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategory.java index 810b2b3d..4b781c28 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategory.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategory.java @@ -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". @@ -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; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategoryAware.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategoryAware.java new file mode 100644 index 00000000..c68d69e5 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategoryAware.java @@ -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 ); +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSet.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSet.java index 1af7ccb4..2ca1caed 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSet.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSet.java @@ -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; @@ -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 ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeSetRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeSetRepository.java index 3cb52e95..ab9b95b2 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeSetRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeSetRepository.java @@ -40,6 +40,7 @@ import javax.annotation.Nonnull; import java.util.List; +import java.util.Optional; import java.util.UUID; /** @@ -61,6 +62,10 @@ default Class getEntityType() return CodeSet.class; } + @Nonnull + @RestResource( exported = false ) + Optional findOneByCode( @Nonnull String code ); + @Override @Nonnull @CacheEvict( allEntries = true ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomProgramStageRuleRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomProgramStageRuleRepository.java index 15fb47c3..e82d5ece 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomProgramStageRuleRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomProgramStageRuleRepository.java @@ -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 @@ -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; @@ -47,4 +48,7 @@ public interface CustomProgramStageRuleRepository @RestResource( exported = false ) @Nonnull Collection> findAllExp( @Nonnull Collection programReferences, @Nonnull Collection programStageReferences, @Nullable Collection dataReferences ); + + @RestResource( exported = false ) + void deleteAllByProgram( @Nonnull MappedTrackerProgram program ); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptRepository.java index d3a8b4a6..e34f91da 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptRepository.java @@ -40,6 +40,7 @@ import javax.annotation.Nonnull; import java.util.List; +import java.util.Optional; import java.util.UUID; /** @@ -61,6 +62,10 @@ default Class getEntityType() return ExecutableScript.class; } + @Nonnull + @RestResource( exported = false ) + Optional findOneByCode( @Nonnull String code ); + @Override @Nonnull @CacheEvict( allEntries = true ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackedEntityRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackedEntityRepository.java index d09482ee..2597f2da 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackedEntityRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackedEntityRepository.java @@ -28,18 +28,23 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.dhis2.fhir.adapter.dhis.model.Reference; import org.dhis2.fhir.adapter.fhir.metadata.model.MappedTrackedEntity; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RestResource; import org.springframework.security.access.prepost.PreAuthorize; import javax.annotation.Nonnull; import java.util.List; +import java.util.Optional; +import java.util.Set; import java.util.UUID; /** @@ -61,6 +66,11 @@ default Class getEntityType() return MappedTrackedEntity.class; } + @Nonnull + @RestResource( exported = false ) + @Query( value = "SELECT e FROM #{#entityName} e WHERE e.trackedEntityReference IN (:references)" ) + Optional findOneByTrackedEntityReference( @Param( "references" ) @Nonnull Set references ); + @Override @Nonnull @CacheEvict( allEntries = true ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackerProgramRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackerProgramRepository.java index 186516e1..25451181 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackerProgramRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackerProgramRepository.java @@ -37,6 +37,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RestResource; import org.springframework.security.access.prepost.PreAuthorize; @@ -44,6 +45,8 @@ import javax.annotation.Nonnull; import java.util.Collection; import java.util.List; +import java.util.Optional; +import java.util.Set; import java.util.UUID; /** @@ -71,6 +74,11 @@ default Class getEntityType() @Nonnull Collection findAllPolledProgramReferences(); + @Nonnull + @RestResource( exported = false ) + @Query( value = "SELECT e FROM #{#entityName} e WHERE e.programReference IN (:references)" ) + Optional findOneByProgramReference( @Param( "references" ) @Nonnull Set references ); + @Override @Nonnull @CacheEvict( allEntries = true ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackerProgramStageRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackerProgramStageRepository.java index 806e48c9..bd0917f8 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackerProgramStageRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/MappedTrackerProgramStageRepository.java @@ -28,18 +28,24 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +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.MappedTrackerProgramStage; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RestResource; import org.springframework.security.access.prepost.PreAuthorize; import javax.annotation.Nonnull; import java.util.List; +import java.util.Optional; +import java.util.Set; import java.util.UUID; /** @@ -61,6 +67,11 @@ default Class getEntityType() return MappedTrackerProgramStage.class; } + @Nonnull + @RestResource( exported = false ) + @Query( value = "SELECT e FROM #{#entityName} e WHERE e.program=:program AND e.programStageReference IN (:references)" ) + Optional findOneByProgramAndProgramStageReference( @Param( "program" ) @Nonnull MappedTrackerProgram program, @Param( "references" ) @Nonnull Set references ); + @Override @Nonnull @CacheEvict( allEntries = true ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptRepository.java index 35a8aed3..fd19a0f1 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptRepository.java @@ -40,6 +40,7 @@ import javax.annotation.Nonnull; import java.util.List; +import java.util.Optional; import java.util.UUID; /** @@ -61,6 +62,9 @@ default Class