use of org.hl7.fhir.r4.model.TimeType in project org.hl7.fhir.core by hapifhir.
the class TimeTypeNullTest method equalsShallow.
@Test
@DisplayName("Test null value equalsShallow()")
void equalsShallow() {
TimeType nullTime = new TimeType();
TimeType validTime = new TimeType("42");
Assertions.assertFalse(nullTime.equalsShallow(validTime));
}
use of org.hl7.fhir.r4.model.TimeType in project org.hl7.fhir.core by hapifhir.
the class TimeTypeNullTest method typedCopy.
@Test
@DisplayName("Test null value typedCopy()")
void typedCopy() {
TimeType nullTime = new TimeType();
TimeType copyTime = (TimeType) nullTime.typedCopy();
Assertions.assertNull(copyTime.getValue());
}
use of org.hl7.fhir.r4.model.TimeType in project clinical_quality_language by cqframework.
the class DataRequirementsProcessor method toFhirValue.
private DataType toFhirValue(ElmRequirementsContext context, Expression value) {
if (value == null) {
return null;
}
if (value instanceof Interval) {
// TODO: Handle lowclosed/highclosed
return new Period().setStartElement(toFhirDateTimeValue(context, ((Interval) value).getLow())).setEndElement(toFhirDateTimeValue(context, ((Interval) value).getHigh()));
} else if (value instanceof Literal) {
if (context.getTypeResolver().isDateTimeType(value.getResultType())) {
return new DateTimeType(((Literal) value).getValue());
} else if (context.getTypeResolver().isDateType(value.getResultType())) {
return new DateType(((Literal) value).getValue());
} else if (context.getTypeResolver().isIntegerType(value.getResultType())) {
return new IntegerType(((Literal) value).getValue());
} else if (context.getTypeResolver().isDecimalType(value.getResultType())) {
return new DecimalType(((Literal) value).getValue());
} else if (context.getTypeResolver().isStringType(value.getResultType())) {
return new StringType(((Literal) value).getValue());
}
} else if (value instanceof DateTime) {
DateTime dateTime = (DateTime) value;
return new DateTimeType(toDateTimeString(toFhirValue(context, dateTime.getYear()), toFhirValue(context, dateTime.getMonth()), toFhirValue(context, dateTime.getDay()), toFhirValue(context, dateTime.getHour()), toFhirValue(context, dateTime.getMinute()), toFhirValue(context, dateTime.getSecond()), toFhirValue(context, dateTime.getMillisecond()), toFhirValue(context, dateTime.getTimezoneOffset())));
} else if (value instanceof org.hl7.elm.r1.Date) {
org.hl7.elm.r1.Date date = (org.hl7.elm.r1.Date) value;
return new DateType(toDateString(toFhirValue(context, date.getYear()), toFhirValue(context, date.getMonth()), toFhirValue(context, date.getDay())));
} else if (value instanceof Start) {
DataType operand = toFhirValue(context, ((Start) value).getOperand());
if (operand != null) {
Period period = (Period) operand;
return period.getStartElement();
}
} else if (value instanceof End) {
DataType operand = toFhirValue(context, ((End) value).getOperand());
if (operand != null) {
Period period = (Period) operand;
return period.getEndElement();
}
} else if (value instanceof ParameterRef) {
if (context.getTypeResolver().isIntervalType(value.getResultType())) {
Extension e = toExpression(context, (ParameterRef) value);
org.hl7.cql.model.DataType pointType = ((IntervalType) value.getResultType()).getPointType();
if (context.getTypeResolver().isDateTimeType(pointType) || context.getTypeResolver().isDateType(pointType)) {
Period period = new Period();
period.addExtension(e);
return period;
} else if (context.getTypeResolver().isQuantityType(pointType) || context.getTypeResolver().isIntegerType(pointType) || context.getTypeResolver().isDecimalType(pointType)) {
Range range = new Range();
range.addExtension(e);
return range;
} else {
throw new IllegalArgumentException(String.format("toFhirValue not implemented for interval of %s", pointType.toString()));
}
} else // Boolean, Integer, Decimal, String, Quantity, Date, DateTime, Time, Coding, CodeableConcept
if (context.getTypeResolver().isBooleanType(value.getResultType())) {
BooleanType result = new BooleanType();
result.addExtension(toExpression(context, (ParameterRef) value));
return result;
} else if (context.getTypeResolver().isIntegerType(value.getResultType())) {
IntegerType result = new IntegerType();
result.addExtension(toExpression(context, (ParameterRef) value));
return result;
} else if (context.getTypeResolver().isDecimalType(value.getResultType())) {
DecimalType result = new DecimalType();
result.addExtension(toExpression(context, (ParameterRef) value));
return result;
} else if (context.getTypeResolver().isQuantityType(value.getResultType())) {
Quantity result = new Quantity();
result.addExtension(toExpression(context, (ParameterRef) value));
return result;
} else if (context.getTypeResolver().isCodeType(value.getResultType())) {
Coding result = new Coding();
result.addExtension(toExpression(context, (ParameterRef) value));
return result;
} else if (context.getTypeResolver().isConceptType(value.getResultType())) {
CodeableConcept result = new CodeableConcept();
result.addExtension(toExpression(context, (ParameterRef) value));
return result;
} else if (context.getTypeResolver().isDateType(value.getResultType())) {
DateType result = new DateType();
result.addExtension(toExpression(context, (ParameterRef) value));
return result;
} else if (context.getTypeResolver().isDateTimeType(value.getResultType())) {
DateTimeType result = new DateTimeType();
result.addExtension(toExpression(context, (ParameterRef) value));
return result;
} else if (context.getTypeResolver().isTimeType(value.getResultType())) {
TimeType result = new TimeType();
result.addExtension(toExpression(context, (ParameterRef) value));
return result;
} else {
throw new IllegalArgumentException(String.format("toFhirValue not implemented for parameter of type %s", value.getResultType().toString()));
}
}
throw new IllegalArgumentException(String.format("toFhirValue not implemented for %s", value.getClass().getSimpleName()));
}
use of org.hl7.fhir.r4.model.TimeType in project quality-measure-and-cohort-service by Alvearie.
the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.
public static Parameter toCohortParameter(Extension extension) {
Parameter parameter;
Type extensionValue = extension.getValue();
if (extensionValue instanceof Base64BinaryType) {
parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
} else if (extensionValue instanceof BooleanType) {
parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
} else if (extensionValue instanceof DateType) {
parameter = new DateParameter(((DateType) extensionValue).asStringValue());
} else if (extensionValue instanceof DateTimeType) {
parameter = convertDateTimeType((DateTimeType) extensionValue);
} else if (extensionValue instanceof DecimalType) {
parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
} else if (extensionValue instanceof InstantType) {
parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
} else if (extensionValue instanceof IntegerType) {
parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
} else if (extensionValue instanceof StringType) {
parameter = new StringParameter(((StringType) extensionValue).getValue());
} else if (extensionValue instanceof TimeType) {
parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
} else if (extensionValue instanceof UriType) {
parameter = new StringParameter(((UriType) extensionValue).getValue());
} else if (extensionValue instanceof Coding) {
parameter = convertCoding((Coding) extensionValue);
} else if (extensionValue instanceof CodeableConcept) {
parameter = convertCodeableConcept((CodeableConcept) extensionValue);
} else if (extensionValue instanceof Period) {
Period castValue = (Period) extensionValue;
parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
} else if (extensionValue instanceof Quantity) {
parameter = convertQuantity((Quantity) extensionValue);
} else if (extensionValue instanceof Range) {
Range castValue = (Range) extensionValue;
parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
} else if (extensionValue instanceof Ratio) {
Ratio castValue = (Ratio) extensionValue;
parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
} else {
throw new UnsupportedFhirTypeException(extensionValue);
}
return parameter;
}
use of org.hl7.fhir.r4.model.TimeType in project kindling by HL7.
the class OldSpreadsheetParser method processValue.
private DataType processValue(Sheet sheet, int row, String column, String source, ElementDefn e) throws Exception {
if (Utilities.noString(source))
return null;
if (e.getTypes().size() != 1)
throw new Exception("Unable to process " + column + " unless a single type is specified (types = " + e.typeCode() + ") " + getLocation(row) + ", column = " + column);
String type = e.typeCode();
if (definitions != null) {
if (definitions.getConstraints().containsKey(type))
type = definitions.getConstraints().get(type).getBaseType();
} else {
StructureDefinition sd = context.fetchTypeDefinition(type);
if (// not loaded yet?
sd != null)
type = sd.getType();
if (type.equals("SimpleQuantity"))
type = "Quantity";
}
if (source.startsWith("{")) {
JsonParser json = new JsonParser();
return json.parseType(source, type);
} else if (source.startsWith("<")) {
XmlParser xml = new XmlParser();
return xml.parseType(source, type);
} else {
if (source.startsWith("\"") && source.endsWith("\""))
source = source.substring(1, source.length() - 1);
if (type.equals("string"))
return new StringType(source);
if (type.equals("boolean"))
return new BooleanType(Boolean.valueOf(source));
if (type.equals("integer"))
return new IntegerType(Integer.valueOf(source));
if (type.equals("integer64"))
return new Integer64Type(Long.valueOf(source));
if (type.equals("unsignedInt"))
return new UnsignedIntType(Integer.valueOf(source));
if (type.equals("positiveInt"))
return new PositiveIntType(Integer.valueOf(source));
if (type.equals("decimal"))
return new DecimalType(new BigDecimal(source));
if (type.equals("base64Binary"))
return new Base64BinaryType(Base64.decode(source.toCharArray()));
if (type.equals("instant"))
return new InstantType(source);
if (type.equals("uri"))
return new UriType(source);
if (type.equals("url"))
return new UrlType(source);
if (type.equals("canonical"))
return new CanonicalType(source);
if (type.equals("date"))
return new DateType(source);
if (type.equals("dateTime"))
return new DateTimeType(source);
if (type.equals("time"))
return new TimeType(source);
if (type.equals("code"))
return new CodeType(source);
if (type.equals("oid"))
return new OidType(source);
if (type.equals("uuid"))
return new UuidType(source);
if (type.equals("id"))
return new IdType(source);
if (type.startsWith("Reference(")) {
Reference r = new Reference();
r.setReference(source);
return r;
}
if (type.equals("Period")) {
if (source.contains("->")) {
String[] parts = source.split("\\-\\>");
Period p = new Period();
p.setStartElement(new DateTimeType(parts[0].trim()));
if (parts.length > 1)
p.setEndElement(new DateTimeType(parts[1].trim()));
return p;
} else
throw new Exception("format not understood parsing " + source + " into a period");
}
if (type.equals("CodeableConcept")) {
CodeableConcept cc = new CodeableConcept();
if (source.contains(":")) {
String[] parts = source.split("\\:");
String system = "";
if (parts[0].equalsIgnoreCase("SCT"))
system = "http://snomed.info/sct";
else if (parts[0].equalsIgnoreCase("LOINC"))
system = "http://loinc.org";
else if (parts[0].equalsIgnoreCase("AMTv2"))
system = "http://nehta.gov.au/amtv2";
else
system = "http://hl7.org/fhir/" + parts[0];
String code = parts[1];
String display = parts.length > 2 ? parts[2] : null;
cc.addCoding().setSystem(system).setCode(code).setDisplay(display);
} else
throw new Exception("format not understood parsing " + source + " into a codeable concept");
return cc;
}
if (type.equals("Identifier")) {
Identifier id = new Identifier();
id.setSystem("urn:ietf:rfc:3986");
id.setValue(source);
return id;
}
if (type.equals("Quantity")) {
int s = 0;
if (source.startsWith("<=") || source.startsWith("=>"))
s = 2;
else if (source.startsWith("<") || source.startsWith(">"))
s = 1;
int i = s;
while (i < source.length() && Character.isDigit(source.charAt(i))) i++;
Quantity q = new Quantity();
if (s > 0)
q.setComparator(QuantityComparator.fromCode(source.substring(0, s)));
if (i > s)
q.setValue(new BigDecimal(source.substring(s, i)));
if (i < source.length())
q.setUnit(source.substring(i).trim());
return q;
}
throw new Exception("Unable to process primitive value '" + source + "' provided for " + column + " - unhandled type " + type + " @ " + getLocation(row));
}
}
Aggregations