use of org.hl7.fhir.dstu3.model.TimeType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method compareTimeElements.
private Integer compareTimeElements(Base theL, Base theR, boolean theEquivalenceTest) {
TimeType left = theL instanceof TimeType ? (TimeType) theL : new TimeType(theL.primitiveValue());
TimeType right = theR instanceof TimeType ? (TimeType) theR : new TimeType(theR.primitiveValue());
if (left.getHour() < right.getHour()) {
return -1;
} else if (left.getHour() > right.getHour()) {
return 1;
// hour is not a valid precision
// } else if (dateLeft.getPrecision() == TemporalPrecisionEnum.YEAR && dateRight.getPrecision() == TemporalPrecisionEnum.YEAR) {
// return 0;
// } else if (dateLeft.getPrecision() == TemporalPrecisionEnum.HOUR || dateRight.getPrecision() == TemporalPrecisionEnum.HOUR) {
// return null;
}
if (left.getMinute() < right.getMinute()) {
return -1;
} else if (left.getMinute() > right.getMinute()) {
return 1;
} else if (left.getPrecision() == TemporalPrecisionEnum.MINUTE && right.getPrecision() == TemporalPrecisionEnum.MINUTE) {
return 0;
} else if (left.getPrecision() == TemporalPrecisionEnum.MINUTE || right.getPrecision() == TemporalPrecisionEnum.MINUTE) {
return null;
}
if (left.getSecond() < right.getSecond()) {
return -1;
} else if (left.getSecond() > right.getSecond()) {
return 1;
} else {
return 0;
}
}
use of org.hl7.fhir.dstu3.model.TimeType in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method convertType.
@SuppressWarnings("unchecked")
private DataType convertType(Base value, QuestionnaireItemType af, ValueSet vs, String path) throws FHIRException {
switch(af) {
// simple cases
case BOOLEAN:
if (value instanceof BooleanType)
return (DataType) value;
break;
case DECIMAL:
if (value instanceof DecimalType)
return (DataType) value;
break;
case INTEGER:
if (value instanceof IntegerType)
return (DataType) value;
break;
case DATE:
if (value instanceof DateType)
return (DataType) value;
break;
case DATETIME:
if (value instanceof DateTimeType)
return (DataType) value;
break;
case TIME:
if (value instanceof TimeType)
return (DataType) value;
break;
case STRING:
if (value instanceof StringType)
return (DataType) value;
else if (value instanceof UriType)
return new StringType(((UriType) value).asStringValue());
break;
case TEXT:
if (value instanceof StringType)
return (DataType) value;
break;
case QUANTITY:
if (value instanceof Quantity)
return (DataType) value;
break;
// ? QuestionnaireItemTypeAttachment: ...?
case CODING:
if (value instanceof Coding)
return (DataType) value;
else if (value instanceof Enumeration) {
Coding cc = new Coding();
cc.setCode(((Enumeration<Enum<?>>) value).asStringValue());
cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
return cc;
} else if (value instanceof StringType) {
Coding cc = new Coding();
cc.setCode(((StringType) value).asStringValue());
cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
return cc;
}
break;
case REFERENCE:
if (value instanceof Reference)
return (DataType) value;
else if (value instanceof StringType) {
Reference r = new Reference();
r.setReference(((StringType) value).asStringValue());
}
break;
default:
break;
}
throw new FHIRException("Unable to convert from '" + value.getClass().toString() + "' for Answer Format " + af.toCode() + ", path = " + path);
}
use of org.hl7.fhir.dstu3.model.TimeType in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireValidator method checkTimeOption.
private void checkTimeOption(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean openChoice) {
Element v = answer.getNamedChild("valueTime");
NodeStack ns = stack.push(v, -1, null, null);
if (qItem.getAnswerOption().size() > 0) {
List<TimeType> list = new ArrayList<TimeType>();
for (QuestionnaireItemAnswerOptionComponent components : qItem.getAnswerOption()) {
try {
list.add(components.getValueTimeType());
} catch (FHIRException e) {
// If it's the wrong type, just keep going
}
}
if (list.isEmpty() && !openChoice) {
rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONSTIME);
} else {
boolean found = false;
for (TimeType item : list) {
if (item.getValue().equals(v.primitiveValue())) {
found = true;
break;
}
}
if (!found) {
rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), found, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOTIME, v.primitiveValue());
}
}
} else
hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_TIMENOOPTIONS);
}
use of org.hl7.fhir.dstu3.model.TimeType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method processDateConstant.
private Base processDateConstant(Object appInfo, String value, ExpressionNode expr) throws PathEngineException {
String date = null;
String time = null;
String tz = null;
TemporalPrecisionEnum temp = null;
if (value.startsWith("T")) {
time = value.substring(1);
} else if (!value.contains("T")) {
date = value;
} else {
String[] p = value.split("T");
date = p[0];
if (p.length > 1) {
time = p[1];
}
}
if (time != null) {
int i = time.indexOf("-");
if (i == -1) {
i = time.indexOf("+");
}
if (i == -1) {
i = time.indexOf("Z");
}
if (i > -1) {
tz = time.substring(i);
time = time.substring(0, i);
}
if (time.length() == 2) {
time = time + ":00:00";
temp = TemporalPrecisionEnum.MINUTE;
} else if (time.length() == 5) {
temp = TemporalPrecisionEnum.MINUTE;
time = time + ":00";
} else if (time.contains(".")) {
temp = TemporalPrecisionEnum.MILLI;
} else {
temp = TemporalPrecisionEnum.SECOND;
}
}
if (date == null) {
if (tz != null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONTEXT, value);
} else {
TimeType tt = new TimeType(time);
tt.setPrecision(temp);
return tt.noExtensions();
}
} else if (time != null) {
DateTimeType dt = new DateTimeType(date + "T" + time + (tz == null ? "" : tz));
dt.setPrecision(temp);
return dt.noExtensions();
} else {
return new DateType(date).noExtensions();
}
}
use of org.hl7.fhir.dstu3.model.TimeType in project org.hl7.fhir.core by hapifhir.
the class TimeTypeNullTest method testToString.
@Test
@DisplayName("Test null value toString()")
void testToString() {
TimeType nullTime = new TimeType();
System.out.println("Value -> " + nullTime);
}
Aggregations