ca.uhn.fhir.parser.DataFormatException Java Examples

The following examples show how to use ca.uhn.fhir.parser.DataFormatException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the value for this type using the given Java Date object as the time, and using the specified precision, as
 * well as the local timezone as determined by the local operating system. Both of
 * these properties may be modified in subsequent calls if neccesary.
 *
 * @param theValue
 *           The date value
 * @param thePrecision
 *           The precision
 * @throws DataFormatException
 */
public void setValue(Date theValue, TemporalPrecisionEnum thePrecision) throws DataFormatException {
	if (getTimeZone() == null) {
		setTimeZone(TimeZone.getDefault());
	}
	myPrecision = thePrecision;
	myFractionalSeconds = "";
	if (theValue != null) {
		long millis = theValue.getTime() % 1000;
		if (millis < 0) {
			// This is for times before 1970 (see bug #444)
			millis = 1000 + millis;
		}
		String fractionalSeconds = Integer.toString((int) millis);
		myFractionalSeconds = StringUtils.leftPad(fractionalSeconds, 3, '0');
	}
	super.setValue(theValue);
}
 
Example #2
Source File: ModelUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static Optional<IBaseResource> loadResource(IFinding finding) throws DataFormatException{
	IBaseResource resource = null;
	String rawContent = finding.getRawContent();
	if (rawContent != null && !rawContent.isEmpty()) {
		// always convert to newest json format
		if (!FindingsFormatUtil.isCurrentFindingsFormat(rawContent)) {
			Optional<String> convertedContent =
				FindingsFormatUtil.convertToCurrentFindingsFormat(rawContent);
			if (convertedContent.isPresent()) {
				rawContent = convertedContent.get();
			}
		}
		resource = getAsResource(rawContent);
	}
	return Optional.ofNullable(resource);
}
 
Example #3
Source File: PatientResourceProvider.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The "@Update" annotation indicates that this method supports replacing an existing
 * resource (by ID) with a new instance of that resource.
 *
 * @param theId      This is the ID of the patient to update
 * @param thePatient This is the actual resource to save
 * @return This method returns a "MethodOutcome"
 */
@Update()
public MethodOutcome updatePatient(@IdParam IdType theId, @ResourceParam Patient thePatient) {
   validateResource(thePatient);

   Long id;
   try {
      id = theId.getIdPartAsLong();
   } catch (DataFormatException e) {
      throw new InvalidRequestException("Invalid ID " + theId.getValue() + " - Must be numeric");
   }

   /*
    * Throw an exception (HTTP 404) if the ID is not known
    */
   if (!myIdToPatientVersions.containsKey(id)) {
      throw new ResourceNotFoundException(theId);
   }

   addNewVersion(thePatient, id);

   return new MethodOutcome();
}
 
Example #4
Source File: BooleanType.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
protected Boolean parse(String theValue) {
	String value = theValue.trim();
	if ("true".equals(value)) {
		return Boolean.TRUE;
	} else if ("false".equals(value)) {
		return Boolean.FALSE;
	} else {
		throw new DataFormatException("Invalid boolean string: '" + theValue + "'");
	}
}
 
Example #5
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the value for this type using the given Java Date object as the time, and using the specified precision, as
 * well as the local timezone as determined by the local operating system. Both of
 * these properties may be modified in subsequent calls if neccesary.
 *
 * @param theValue
 *           The date value
 * @param thePrecision
 *           The precision
 * @throws DataFormatException
 */
public void setValue(Date theValue, TemporalPrecisionEnum thePrecision) throws DataFormatException {
  if (getTimeZone() == null) {
    setTimeZone(TimeZone.getDefault());
  }
  myPrecision = thePrecision;
  myFractionalSeconds = "";
  if (theValue != null) {
    long millis = theValue.getTime() % 1000;
    if (millis < 0) {
      // This is for times before 1970 (see bug #444)
      millis = 1000 + millis;
    }
    String fractionalSeconds = Integer.toString((int) millis);
    myFractionalSeconds = StringUtils.leftPad(fractionalSeconds, 3, '0');
  }
  super.setValue(theValue);
}
 
Example #6
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the value for this type using the given Java Date object as the time, and using the specified precision, as
 * well as the local timezone as determined by the local operating system. Both of
 * these properties may be modified in subsequent calls if neccesary.
 *
 * @param theValue
 *           The date value
 * @param thePrecision
 *           The precision
 * @throws DataFormatException
 */
public void setValue(Date theValue, TemporalPrecisionEnum thePrecision) throws DataFormatException {
  if (getTimeZone() == null) {
    setTimeZone(TimeZone.getDefault());
  }
  myPrecision = thePrecision;
  myFractionalSeconds = "";
  if (theValue != null) {
    long millis = theValue.getTime() % 1000;
    if (millis < 0) {
      // This is for times before 1970 (see bug #444)
      millis = 1000 + millis;
    }
    String fractionalSeconds = Integer.toString((int) millis);
    myFractionalSeconds = StringUtils.leftPad(fractionalSeconds, 3, '0');
  }
  super.setValue(theValue);
}
 
Example #7
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the value for this type using the given Java Date object as the time, and using the specified precision, as
 * well as the local timezone as determined by the local operating system. Both of
 * these properties may be modified in subsequent calls if neccesary.
 *
 * @param theValue
 *           The date value
 * @param thePrecision
 *           The precision
 * @throws DataFormatException
 */
public void setValue(Date theValue, TemporalPrecisionEnum thePrecision) throws DataFormatException {
	if (getTimeZone() == null) {
		setTimeZone(TimeZone.getDefault());
	}
	myPrecision = thePrecision;
	myFractionalSeconds = "";
	if (theValue != null) {
		long millis = theValue.getTime() % 1000;
		if (millis < 0) {
			// This is for times before 1970 (see bug #444)
			millis = 1000 + millis;
		}
		String fractionalSeconds = Integer.toString((int) millis);
		myFractionalSeconds = StringUtils.leftPad(fractionalSeconds, 3, '0');
	}
	super.setValue(theValue);
}
 
Example #8
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the precision for this datatype
 *
 * @throws DataFormatException
 */
public void setPrecision(TemporalPrecisionEnum thePrecision) throws DataFormatException {
  if (thePrecision == null) {
    throw new NullPointerException("Precision may not be null");
  }
  myPrecision = thePrecision;
  updateStringValue();
}
 
Example #9
Source File: Base64BinaryTypeTest.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("Null String value creates non-null instance with null value.")
public void testNullInstance() throws DataFormatException {
  String v = null;
  Base64BinaryType b64 = new Base64BinaryType(v);
  Assertions.assertNotNull(b64);
  Assertions.assertNull(b64.getValue());
  Assertions.assertNull(b64.getValueAsString());
}
 
Example #10
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the given amount to the field specified by theField
 *
 * @param theField
 *           The field, uses constants from {@link Calendar} such as {@link Calendar#YEAR}
 * @param theValue
 *           The number to add (or subtract for a negative number)
 */
public void add(int theField, int theValue) {
  switch (theField) {
    case Calendar.YEAR:
      setValue(DateUtils.addYears(getValue(), theValue), getPrecision());
      break;
    case Calendar.MONTH:
      setValue(DateUtils.addMonths(getValue(), theValue), getPrecision());
      break;
    case Calendar.DATE:
      setValue(DateUtils.addDays(getValue(), theValue), getPrecision());
      break;
    case Calendar.HOUR:
      setValue(DateUtils.addHours(getValue(), theValue), getPrecision());
      break;
    case Calendar.MINUTE:
      setValue(DateUtils.addMinutes(getValue(), theValue), getPrecision());
      break;
    case Calendar.SECOND:
      setValue(DateUtils.addSeconds(getValue(), theValue), getPrecision());
      break;
    case Calendar.MILLISECOND:
      setValue(DateUtils.addMilliseconds(getValue(), theValue), getPrecision());
      break;
    default:
      throw new DataFormatException("Unknown field constant: " + theField);
  }
}
 
Example #11
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the given amount to the field specified by theField
 *
 * @param theField
 *           The field, uses constants from {@link Calendar} such as {@link Calendar#YEAR}
 * @param theValue
 *           The number to add (or subtract for a negative number)
 */
public void add(int theField, int theValue) {
	switch (theField) {
	case Calendar.YEAR:
		setValue(DateUtils.addYears(getValue(), theValue), getPrecision());
		break;
	case Calendar.MONTH:
		setValue(DateUtils.addMonths(getValue(), theValue), getPrecision());
		break;
	case Calendar.DATE:
		setValue(DateUtils.addDays(getValue(), theValue), getPrecision());
		break;
	case Calendar.HOUR:
		setValue(DateUtils.addHours(getValue(), theValue), getPrecision());
		break;
	case Calendar.MINUTE:
		setValue(DateUtils.addMinutes(getValue(), theValue), getPrecision());
		break;
	case Calendar.SECOND:
		setValue(DateUtils.addSeconds(getValue(), theValue), getPrecision());
		break;
	case Calendar.MILLISECOND:
		setValue(DateUtils.addMilliseconds(getValue(), theValue), getPrecision());
		break;
	default:
		throw new DataFormatException("Unknown field constant: " + theField);
	}
}
 
Example #12
Source File: BooleanType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected Boolean parse(String theValue) {
	String value = theValue.trim();
	if ("true".equals(value)) {
		return Boolean.TRUE;
	} else if ("false".equals(value)) {
		return Boolean.FALSE;
	} else {
		throw new DataFormatException("Invalid boolean string: '" + theValue + "'");
	}
}
 
Example #13
Source File: Base64BinaryTypeTest.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("Null String value creates non-null instance with null value.")
public void testNullInstance() throws DataFormatException {
  String v = null;
  Base64BinaryType b64 = new Base64BinaryType(v);
  Assertions.assertNotNull(b64);
  Assertions.assertNull(b64.getValue());
  Assertions.assertNull(b64.getValueAsString());
}
 
Example #14
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @throws DataFormatException
 *            If the specified precision is not allowed for this type
 */
public BaseDateTimeType(Date theDate, TemporalPrecisionEnum thePrecision) {
  setValue(theDate, thePrecision);
  if (isPrecisionAllowed(thePrecision) == false) {
    throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + thePrecision + " precision): " + theDate);
  }
}
 
Example #15
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @throws DataFormatException
 *            If the specified precision is not allowed for this type
 */
public BaseDateTimeType(String theString) {
  setValueAsString(theString);
  if (isPrecisionAllowed(getPrecision()) == false) {
    throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + getPrecision() + " precision): " + theString);
  }
}
 
Example #16
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the precision for this datatype
 *
 * @throws DataFormatException
 */
public void setPrecision(TemporalPrecisionEnum thePrecision) throws DataFormatException {
  if (thePrecision == null) {
    throw new NullPointerException("Precision may not be null");
  }
  myPrecision = thePrecision;
  updateStringValue();
}
 
Example #17
Source File: Base64BinaryTypeTest.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("Null String value creates non-null instance with null value.")
public void testNullInstance() throws DataFormatException {
  String v = null;
  Base64BinaryType b64 = new Base64BinaryType(v);
  Assertions.assertNotNull(b64);
  Assertions.assertNull(b64.getValue());
  Assertions.assertNull(b64.getValueAsString());
}
 
Example #18
Source File: CareConnectServerConformanceR4Provider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
private DateTimeType conformanceDate() {
        IPrimitiveType<Date> buildDate = serverConfiguration.getConformanceDate();
        if (buildDate != null) {
            try {
                return new DateTimeType(buildDate.getValue());
            } catch (DataFormatException e) {
// fall through
            }
        }
        return DateTimeType.now();
    }
 
Example #19
Source File: CareConnectServerConformanceProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
private DateTimeType conformanceDate() {
    IPrimitiveType<Date> buildDate = serverConfiguration.getConformanceDate();
    if (buildDate != null) {
        try {
            return new DateTimeType(buildDate.getValue());
        } catch (DataFormatException e) {
            // fall through
        }
    }
    return DateTimeType.now();
}
 
Example #20
Source File: ModelUtil.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static void saveResource(IBaseResource resource, IFinding finding)
	throws DataFormatException{
	if (resource != null) {
		String resourceJson = getJsonParser().encodeResourceToString(resource);
		finding.setRawContent(resourceJson);
	}
}
 
Example #21
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the precision for this datatype
 *
 * @throws DataFormatException
 */
public void setPrecision(TemporalPrecisionEnum thePrecision) throws DataFormatException {
	if (thePrecision == null) {
		throw new NullPointerException("Precision may not be null");
	}
	myPrecision = thePrecision;
	updateStringValue();
}
 
Example #22
Source File: Base64BinaryTypeTest.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("Null String value creates non-null instance with null value.")
public void testNullInstance() throws DataFormatException {
  String v = null;
  Base64BinaryType b64 = new Base64BinaryType(v);
  Assertions.assertNotNull(b64);
  Assertions.assertNull(b64.getValue());
  Assertions.assertNull(b64.getValueAsString());
}
 
Example #23
Source File: BooleanType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected Boolean parse(String theValue) {
	String value = theValue.trim();
	if ("true".equals(value)) {
		return Boolean.TRUE;
	} else if ("false".equals(value)) {
		return Boolean.FALSE;
	} else {
		throw new DataFormatException("Invalid boolean string: '" + theValue + "'");
	}
}
 
Example #24
Source File: Base64BinaryTypeTest.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("Null String value creates non-null instance with null value.")
public void testNullInstance() throws DataFormatException {
  String v = null;
  Base64BinaryType b64 = new Base64BinaryType(v);
  Assertions.assertNotNull(b64);
  Assertions.assertNull(b64.getValue());
  Assertions.assertNull(b64.getValueAsString());
}
 
Example #25
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the given amount to the field specified by theField
 *
 * @param theField
 *           The field, uses constants from {@link Calendar} such as {@link Calendar#YEAR}
 * @param theValue
 *           The number to add (or subtract for a negative number)
 */
public void add(int theField, int theValue) {
	switch (theField) {
	case Calendar.YEAR:
		setValue(DateUtils.addYears(getValue(), theValue), getPrecision());
		break;
	case Calendar.MONTH:
		setValue(DateUtils.addMonths(getValue(), theValue), getPrecision());
		break;
	case Calendar.DATE:
		setValue(DateUtils.addDays(getValue(), theValue), getPrecision());
		break;
	case Calendar.HOUR:
		setValue(DateUtils.addHours(getValue(), theValue), getPrecision());
		break;
	case Calendar.MINUTE:
		setValue(DateUtils.addMinutes(getValue(), theValue), getPrecision());
		break;
	case Calendar.SECOND:
		setValue(DateUtils.addSeconds(getValue(), theValue), getPrecision());
		break;
	case Calendar.MILLISECOND:
		setValue(DateUtils.addMilliseconds(getValue(), theValue), getPrecision());
		break;
	default:
		throw new DataFormatException("Unknown field constant: " + theField);
	}
}
 
Example #26
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the precision for this datatype
 *
 * @throws DataFormatException
 */
public void setPrecision(TemporalPrecisionEnum thePrecision) throws DataFormatException {
	if (thePrecision == null) {
		throw new NullPointerException("Precision may not be null");
	}
	myPrecision = thePrecision;
	updateStringValue();
}
 
Example #27
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@Override
public void setValueAsString(String theValue) throws DataFormatException {
	clearTimeZone();
	super.setValueAsString(theValue);
}
 
Example #28
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@Override
public void setValueAsString(String theValue) throws DataFormatException {
	clearTimeZone();
	super.setValueAsString(theValue);
}
 
Example #29
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void throwBadDateFormat(String theValue) {
	throw new DataFormatException("Invalid date/time format: \"" + theValue + "\"");
}
 
Example #30
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void throwBadDateFormat(String theValue, String theMesssage) {
	throw new DataFormatException("Invalid date/time format: \"" + theValue + "\": " + theMesssage);
}