@Test( expected = TransformerDataException.class ) public void convertBooleanInvalid() { utils.convert( new DateTimeType( new Date() ), "boolean" ); }
@Nullable @Override protected Object convert( @Nullable IBaseDatatype fhirValue, @Nonnull ValueType valueType ) { if ( fhirValue == null ) { return null; } switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: if ( fhirValue instanceof IPrimitiveType ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Integer ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Number ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; case DATETIME: case DATE: case AGE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof DateTimeType ) { return DateTimeFormatter.ISO_LOCAL_DATE_TIME .format( ( (DateTimeType) fhirValue ).getValue().toInstant().atZone( ZoneId.systemDefault() ).toLocalDateTime() ); } break; case TIME: if ( fhirValue instanceof TimeType ) { return ( (TimeType) fhirValue ).getValueAsString(); } break; case BOOLEAN: case TRUE_ONLY: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Boolean ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } throw new TransformerDataException( "Unsupported FHIR type " + fhirValue.getClass().getSimpleName() + " for DHIS2 value type " + valueType ); }
Dstu3ValueTypeFhirToDhisTransformerUtils extends AbstractValueTypeFhirToDhisTransformerUtils { @Nullable @Override protected Object convert( @Nullable IBaseDatatype fhirValue, @Nonnull ValueType valueType ) { if ( fhirValue == null ) { return null; } switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: if ( fhirValue instanceof IPrimitiveType ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Integer ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Number ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; case DATETIME: case DATE: case AGE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof DateTimeType ) { return DateTimeFormatter.ISO_LOCAL_DATE_TIME .format( ( (DateTimeType) fhirValue ).getValue().toInstant().atZone( ZoneId.systemDefault() ).toLocalDateTime() ); } break; case TIME: if ( fhirValue instanceof TimeType ) { return ( (TimeType) fhirValue ).getValueAsString(); } break; case BOOLEAN: case TRUE_ONLY: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Boolean ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } throw new TransformerDataException( "Unsupported FHIR type " + fhirValue.getClass().getSimpleName() + " for DHIS2 value type " + valueType ); } }
Dstu3ValueTypeFhirToDhisTransformerUtils extends AbstractValueTypeFhirToDhisTransformerUtils { @Nullable @Override protected Object convert( @Nullable IBaseDatatype fhirValue, @Nonnull ValueType valueType ) { if ( fhirValue == null ) { return null; } switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: if ( fhirValue instanceof IPrimitiveType ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Integer ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Number ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; case DATETIME: case DATE: case AGE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof DateTimeType ) { return DateTimeFormatter.ISO_LOCAL_DATE_TIME .format( ( (DateTimeType) fhirValue ).getValue().toInstant().atZone( ZoneId.systemDefault() ).toLocalDateTime() ); } break; case TIME: if ( fhirValue instanceof TimeType ) { return ( (TimeType) fhirValue ).getValueAsString(); } break; case BOOLEAN: case TRUE_ONLY: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Boolean ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } throw new TransformerDataException( "Unsupported FHIR type " + fhirValue.getClass().getSimpleName() + " for DHIS2 value type " + valueType ); } Dstu3ValueTypeFhirToDhisTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext ); }
Dstu3ValueTypeFhirToDhisTransformerUtils extends AbstractValueTypeFhirToDhisTransformerUtils { @Nullable @Override protected Object convert( @Nullable IBaseDatatype fhirValue, @Nonnull ValueType valueType ) { if ( fhirValue == null ) { return null; } switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: if ( fhirValue instanceof IPrimitiveType ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Integer ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Number ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; case DATETIME: case DATE: case AGE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof DateTimeType ) { return DateTimeFormatter.ISO_LOCAL_DATE_TIME .format( ( (DateTimeType) fhirValue ).getValue().toInstant().atZone( ZoneId.systemDefault() ).toLocalDateTime() ); } break; case TIME: if ( fhirValue instanceof TimeType ) { return ( (TimeType) fhirValue ).getValueAsString(); } break; case BOOLEAN: case TRUE_ONLY: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Boolean ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } throw new TransformerDataException( "Unsupported FHIR type " + fhirValue.getClass().getSimpleName() + " for DHIS2 value type " + valueType ); } Dstu3ValueTypeFhirToDhisTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext ); @Nonnull @Override Set<FhirVersion> getFhirVersions(); }
Dstu3ValueTypeFhirToDhisTransformerUtils extends AbstractValueTypeFhirToDhisTransformerUtils { @Nullable @Override protected Object convert( @Nullable IBaseDatatype fhirValue, @Nonnull ValueType valueType ) { if ( fhirValue == null ) { return null; } switch ( valueType ) { case TEXT: case LONG_TEXT: case EMAIL: case LETTER: case ORGANISATION_UNIT: case PHONE_NUMBER: case TRACKER_ASSOCIATE: case URL: case USERNAME: if ( fhirValue instanceof IPrimitiveType ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case INTEGER: case INTEGER_POSITIVE: case INTEGER_NEGATIVE: case INTEGER_ZERO_OR_POSITIVE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Integer ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } if ( fhirValue instanceof Coding ) { return getCode( (Coding) fhirValue ); } break; case NUMBER: case PERCENTAGE: case UNIT_INTERVAL: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Number ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; case DATETIME: case DATE: case AGE: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof DateTimeType ) { return DateTimeFormatter.ISO_LOCAL_DATE_TIME .format( ( (DateTimeType) fhirValue ).getValue().toInstant().atZone( ZoneId.systemDefault() ).toLocalDateTime() ); } break; case TIME: if ( fhirValue instanceof TimeType ) { return ( (TimeType) fhirValue ).getValueAsString(); } break; case BOOLEAN: case TRUE_ONLY: if ( fhirValue.isEmpty() ) { return null; } if ( fhirValue instanceof IPrimitiveType && ( (IPrimitiveType) fhirValue ).getValue() instanceof Boolean ) { return ( (IPrimitiveType) fhirValue ).getValueAsString(); } break; default: throw new TransformerDataException( "Unsupported DHIS2 value type: " + valueType ); } throw new TransformerDataException( "Unsupported FHIR type " + fhirValue.getClass().getSimpleName() + " for DHIS2 value type " + valueType ); } Dstu3ValueTypeFhirToDhisTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext ); @Nonnull @Override Set<FhirVersion> getFhirVersions();  }