use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opGreaterOrEqual.
private List<Base> opGreaterOrEqual(List<Base> left, List<Base> right) throws FHIRException {
if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
Base l = left.get(0);
Base r = right.get(0);
if (l.hasType("string") && r.hasType("string"))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) >= 0);
else if ((l.hasType("integer", "decimal")) && (r.hasType("integer", "decimal")))
return makeBoolean(new Double(l.primitiveValue()) >= new Double(r.primitiveValue()));
else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) >= 0);
else if ((l.hasType("time")) && (r.hasType("time")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) >= 0);
} else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
List<Base> lUnit = left.get(0).listChildrenByName("unit");
List<Base> rUnit = right.get(0).listChildrenByName("unit");
if (Base.compareDeep(lUnit, rUnit, true)) {
return opGreaterOrEqual(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"));
} else {
throw new Error("Canonical Comparison isn't done yet");
}
}
return new ArrayList<Base>();
}
use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opLessThen.
private List<Base> opLessThen(List<Base> left, List<Base> right) throws FHIRException {
if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
Base l = left.get(0);
Base r = right.get(0);
if (l.hasType("string") && r.hasType("string"))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) < 0);
else if ((l.hasType("integer") || l.hasType("decimal")) && (r.hasType("integer") || r.hasType("decimal")))
return makeBoolean(new Double(l.primitiveValue()) < new Double(r.primitiveValue()));
else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) < 0);
else if ((l.hasType("time")) && (r.hasType("time")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) < 0);
} else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
List<Base> lUnit = left.get(0).listChildrenByName("unit");
List<Base> rUnit = right.get(0).listChildrenByName("unit");
if (Base.compareDeep(lUnit, rUnit, true)) {
return opLessThen(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"));
} else {
throw new Error("Canonical Comparison isn't done yet");
}
}
return new ArrayList<Base>();
}
use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.
the class JsonParser method composeType.
protected void composeType(String prefix, Type type) throws IOException {
if (type == null)
;
else if (type instanceof Age)
composeAge(prefix + "Age", (Age) type);
else if (type instanceof Count)
composeCount(prefix + "Count", (Count) type);
else if (type instanceof Money)
composeMoney(prefix + "Money", (Money) type);
else if (type instanceof Distance)
composeDistance(prefix + "Distance", (Distance) type);
else if (type instanceof Duration)
composeDuration(prefix + "Duration", (Duration) type);
else if (type instanceof SimpleQuantity)
composeSimpleQuantity(prefix + "SimpleQuantity", (SimpleQuantity) type);
else if (type instanceof Period)
composePeriod(prefix + "Period", (Period) type);
else if (type instanceof Coding)
composeCoding(prefix + "Coding", (Coding) type);
else if (type instanceof Range)
composeRange(prefix + "Range", (Range) type);
else if (type instanceof Quantity)
composeQuantity(prefix + "Quantity", (Quantity) type);
else if (type instanceof Attachment)
composeAttachment(prefix + "Attachment", (Attachment) type);
else if (type instanceof Ratio)
composeRatio(prefix + "Ratio", (Ratio) type);
else if (type instanceof Annotation)
composeAnnotation(prefix + "Annotation", (Annotation) type);
else if (type instanceof SampledData)
composeSampledData(prefix + "SampledData", (SampledData) type);
else if (type instanceof Reference)
composeReference(prefix + "Reference", (Reference) type);
else if (type instanceof CodeableConcept)
composeCodeableConcept(prefix + "CodeableConcept", (CodeableConcept) type);
else if (type instanceof Identifier)
composeIdentifier(prefix + "Identifier", (Identifier) type);
else if (type instanceof Signature)
composeSignature(prefix + "Signature", (Signature) type);
else if (type instanceof TriggerDefinition)
composeTriggerDefinition(prefix + "TriggerDefinition", (TriggerDefinition) type);
else if (type instanceof ElementDefinition)
composeElementDefinition(prefix + "ElementDefinition", (ElementDefinition) type);
else if (type instanceof Timing)
composeTiming(prefix + "Timing", (Timing) type);
else if (type instanceof ModuleMetadata)
composeModuleMetadata(prefix + "ModuleMetadata", (ModuleMetadata) type);
else if (type instanceof ActionDefinition)
composeActionDefinition(prefix + "ActionDefinition", (ActionDefinition) type);
else if (type instanceof Address)
composeAddress(prefix + "Address", (Address) type);
else if (type instanceof HumanName)
composeHumanName(prefix + "HumanName", (HumanName) type);
else if (type instanceof DataRequirement)
composeDataRequirement(prefix + "DataRequirement", (DataRequirement) type);
else if (type instanceof Meta)
composeMeta(prefix + "Meta", (Meta) type);
else if (type instanceof ParameterDefinition)
composeParameterDefinition(prefix + "ParameterDefinition", (ParameterDefinition) type);
else if (type instanceof ContactPoint)
composeContactPoint(prefix + "ContactPoint", (ContactPoint) type);
else if (type instanceof MarkdownType) {
composeMarkdownCore(prefix + "Markdown", (MarkdownType) type, false);
composeMarkdownExtras(prefix + "Markdown", (MarkdownType) type, false);
} else if (type instanceof UnsignedIntType) {
composeUnsignedIntCore(prefix + "UnsignedInt", (UnsignedIntType) type, false);
composeUnsignedIntExtras(prefix + "UnsignedInt", (UnsignedIntType) type, false);
} else if (type instanceof CodeType) {
composeCodeCore(prefix + "Code", (CodeType) type, false);
composeCodeExtras(prefix + "Code", (CodeType) type, false);
} else if (type instanceof IdType) {
composeIdCore(prefix + "Id", (IdType) type, false);
composeIdExtras(prefix + "Id", (IdType) type, false);
} else if (type instanceof OidType) {
composeOidCore(prefix + "Oid", (OidType) type, false);
composeOidExtras(prefix + "Oid", (OidType) type, false);
} else if (type instanceof PositiveIntType) {
composePositiveIntCore(prefix + "PositiveInt", (PositiveIntType) type, false);
composePositiveIntExtras(prefix + "PositiveInt", (PositiveIntType) type, false);
} else if (type instanceof UuidType) {
composeUuidCore(prefix + "Uuid", (UuidType) type, false);
composeUuidExtras(prefix + "Uuid", (UuidType) type, false);
} else if (type instanceof IntegerType) {
composeIntegerCore(prefix + "Integer", (IntegerType) type, false);
composeIntegerExtras(prefix + "Integer", (IntegerType) type, false);
} else if (type instanceof DateTimeType) {
composeDateTimeCore(prefix + "DateTime", (DateTimeType) type, false);
composeDateTimeExtras(prefix + "DateTime", (DateTimeType) type, false);
} else if (type instanceof DateType) {
composeDateCore(prefix + "Date", (DateType) type, false);
composeDateExtras(prefix + "Date", (DateType) type, false);
} else if (type instanceof DecimalType) {
composeDecimalCore(prefix + "Decimal", (DecimalType) type, false);
composeDecimalExtras(prefix + "Decimal", (DecimalType) type, false);
} else if (type instanceof UriType) {
composeUriCore(prefix + "Uri", (UriType) type, false);
composeUriExtras(prefix + "Uri", (UriType) type, false);
} else if (type instanceof Base64BinaryType) {
composeBase64BinaryCore(prefix + "Base64Binary", (Base64BinaryType) type, false);
composeBase64BinaryExtras(prefix + "Base64Binary", (Base64BinaryType) type, false);
} else if (type instanceof TimeType) {
composeTimeCore(prefix + "Time", (TimeType) type, false);
composeTimeExtras(prefix + "Time", (TimeType) type, false);
} else if (type instanceof StringType) {
composeStringCore(prefix + "String", (StringType) type, false);
composeStringExtras(prefix + "String", (StringType) type, false);
} else if (type instanceof BooleanType) {
composeBooleanCore(prefix + "Boolean", (BooleanType) type, false);
composeBooleanExtras(prefix + "Boolean", (BooleanType) type, false);
} else if (type instanceof InstantType) {
composeInstantCore(prefix + "Instant", (InstantType) type, false);
composeInstantExtras(prefix + "Instant", (InstantType) type, false);
} else
throw new Error("Unhandled type");
}
use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method textTypeNarrowing1.
/**
* check that narrowing types is working
* this one doesn't rename the path
*
* @param context2
* @
* @throws EOperationOutcome
*/
private void textTypeNarrowing1() throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBase(base.getUrl());
ElementDefinition id = focus.getDifferential().addElement();
id.setPath("Patient.deceased[x]");
id.addType().setCode("dateTime");
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
if (ok) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
if (f.getPath().equals("Patient.deceasedDateTime")) {
ok = f.getType().size() == 1 && f.getType().get(0).getCode().equals("dateTime");
if (ok) {
f.getType().clear();
b.getType().clear();
f.setPath(b.getPath());
}
}
ok = ok && Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation narrow type 1 failed");
} else
System.out.println("Snap shot generation narrow type 1 test passed");
}
use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method textTypeNarrowing2.
/**
* check that narrowing types is working
* this one renames the path
*
* @param context2
* @
* @throws EOperationOutcome
*/
private void textTypeNarrowing2() throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBase(base.getUrl());
ElementDefinition id = focus.getDifferential().addElement();
id.setPath("Patient.deceasedDateTime");
id.addType().setCode("dateTime");
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
if (ok) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
if (f.getPath().equals("Patient.deceasedDateTime")) {
ok = f.getType().size() == 1 && f.getType().get(0).getCode().equals("dateTime");
if (ok) {
f.getType().clear();
b.getType().clear();
f.setPath(b.getPath());
}
}
ok = ok && Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation narrow type 2 failed");
} else
System.out.println("Snap shot generation narrow type 2 test passed");
}
Aggregations