@Test( expected = TransformerDataException.class ) public void convertUnsupportedType() { utils.convert( "This is a test", "image", null ); Mockito.verify( valueConverter ).convert( Mockito.any(), Mockito.any(), Mockito.eq( String.class ) ); }
@Nullable @Override protected IBaseDatatype convert( @Nullable String dhisValue, @Nonnull ValueType valueType, @Nullable OptionSet optionSet ) { if ( dhisValue == null ) { return null; } if ( optionSet != null ) { final Option option = optionSet.getOptionalOptionByCode( dhisValue ).orElseGet( () -> new WritableOption( dhisValue, dhisValue ) ); return new Coding().setCode( option.getCode() ).setDisplay( option.getName() ); } try { switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: return new StringType( dhisValue ); case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: return new IntegerType( dhisValue ); case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: return new DecimalType( dhisValue ); case DATETIME: case DATE: case AGE: return new DateTimeType( dhisValue ); case TIME: return new TimeType( dhisValue ); case BOOLEAN: case TRUE_ONLY: return new BooleanType( dhisValue ); default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } } catch ( DataFormatException | IllegalArgumentException e ) { throw new TransformerDataException( "Value with value type " + valueType + " could not be parsed for setting corresponding FHIR value: " + dhisValue, e ); } }
Dstu3ValueTypeDhisToFhirTransformerUtils extends AbstractValueTypeDhisToFhirTransformerUtils { @Nullable @Override protected IBaseDatatype convert( @Nullable String dhisValue, @Nonnull ValueType valueType, @Nullable OptionSet optionSet ) { if ( dhisValue == null ) { return null; } if ( optionSet != null ) { final Option option = optionSet.getOptionalOptionByCode( dhisValue ).orElseGet( () -> new WritableOption( dhisValue, dhisValue ) ); return new Coding().setCode( option.getCode() ).setDisplay( option.getName() ); } try { switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: return new StringType( dhisValue ); case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: return new IntegerType( dhisValue ); case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: return new DecimalType( dhisValue ); case DATETIME: case DATE: case AGE: return new DateTimeType( dhisValue ); case TIME: return new TimeType( dhisValue ); case BOOLEAN: case TRUE_ONLY: return new BooleanType( dhisValue ); default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } } catch ( DataFormatException | IllegalArgumentException e ) { throw new TransformerDataException( "Value with value type " + valueType + " could not be parsed for setting corresponding FHIR value: " + dhisValue, e ); } } }
Dstu3ValueTypeDhisToFhirTransformerUtils extends AbstractValueTypeDhisToFhirTransformerUtils { @Nullable @Override protected IBaseDatatype convert( @Nullable String dhisValue, @Nonnull ValueType valueType, @Nullable OptionSet optionSet ) { if ( dhisValue == null ) { return null; } if ( optionSet != null ) { final Option option = optionSet.getOptionalOptionByCode( dhisValue ).orElseGet( () -> new WritableOption( dhisValue, dhisValue ) ); return new Coding().setCode( option.getCode() ).setDisplay( option.getName() ); } try { switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: return new StringType( dhisValue ); case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: return new IntegerType( dhisValue ); case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: return new DecimalType( dhisValue ); case DATETIME: case DATE: case AGE: return new DateTimeType( dhisValue ); case TIME: return new TimeType( dhisValue ); case BOOLEAN: case TRUE_ONLY: return new BooleanType( dhisValue ); default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } } catch ( DataFormatException | IllegalArgumentException e ) { throw new TransformerDataException( "Value with value type " + valueType + " could not be parsed for setting corresponding FHIR value: " + dhisValue, e ); } } Dstu3ValueTypeDhisToFhirTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext, @Nonnull ValueConverter valueConverter ); }
Dstu3ValueTypeDhisToFhirTransformerUtils extends AbstractValueTypeDhisToFhirTransformerUtils { @Nullable @Override protected IBaseDatatype convert( @Nullable String dhisValue, @Nonnull ValueType valueType, @Nullable OptionSet optionSet ) { if ( dhisValue == null ) { return null; } if ( optionSet != null ) { final Option option = optionSet.getOptionalOptionByCode( dhisValue ).orElseGet( () -> new WritableOption( dhisValue, dhisValue ) ); return new Coding().setCode( option.getCode() ).setDisplay( option.getName() ); } try { switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: return new StringType( dhisValue ); case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: return new IntegerType( dhisValue ); case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: return new DecimalType( dhisValue ); case DATETIME: case DATE: case AGE: return new DateTimeType( dhisValue ); case TIME: return new TimeType( dhisValue ); case BOOLEAN: case TRUE_ONLY: return new BooleanType( dhisValue ); default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } } catch ( DataFormatException | IllegalArgumentException e ) { throw new TransformerDataException( "Value with value type " + valueType + " could not be parsed for setting corresponding FHIR value: " + dhisValue, e ); } } Dstu3ValueTypeDhisToFhirTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext, @Nonnull ValueConverter valueConverter ); @Nonnull @Override Set<FhirVersion> getFhirVersions(); }
Dstu3ValueTypeDhisToFhirTransformerUtils extends AbstractValueTypeDhisToFhirTransformerUtils { @Nullable @Override protected IBaseDatatype convert( @Nullable String dhisValue, @Nonnull ValueType valueType, @Nullable OptionSet optionSet ) { if ( dhisValue == null ) { return null; } if ( optionSet != null ) { final Option option = optionSet.getOptionalOptionByCode( dhisValue ).orElseGet( () -> new WritableOption( dhisValue, dhisValue ) ); return new Coding().setCode( option.getCode() ).setDisplay( option.getName() ); } try { switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: return new StringType( dhisValue ); case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: return new IntegerType( dhisValue ); case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: return new DecimalType( dhisValue ); case DATETIME: case DATE: case AGE: return new DateTimeType( dhisValue ); case TIME: return new TimeType( dhisValue ); case BOOLEAN: case TRUE_ONLY: return new BooleanType( dhisValue ); default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } } catch ( DataFormatException | IllegalArgumentException e ) { throw new TransformerDataException( "Value with value type " + valueType + " could not be parsed for setting corresponding FHIR value: " + dhisValue, e ); } } Dstu3ValueTypeDhisToFhirTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext, @Nonnull ValueConverter valueConverter ); @Nonnull @Override Set<FhirVersion> getFhirVersions();  }