use of org.hl7.elm.r1.Slice in project beneficiary-fhir-data by CMSgov.
the class TransformerUtilsV2 method addProviderSlice.
/**
* Looks up or adds a contained {@link Organization} object to the current {@link
* ExplanationOfBenefit}. This is used to store Identifier slices related to the Provider
* organization.
*
* @param eob The {@link ExplanationOfBenefit} to provider org details to
* @param type The {@link C4BBIdentifierType} of the identifier slice
* @param value The value of the identifier. If empty, this call is a no-op
*/
static void addProviderSlice(ExplanationOfBenefit eob, C4BBOrganizationIdentifierType type, Optional<String> value, Optional<Instant> lastUpdated) {
if (value.isPresent()) {
Resource providerResource = findOrCreateContainedOrg(eob, PROVIDER_ORG_ID);
// We are assuming that the contained resource with an id of "provider-org" is an Organization
if (!Organization.class.isInstance(providerResource)) {
throw new BadCodeMonkeyException();
}
Organization provider = (Organization) providerResource;
// Add the new Identifier to the Organization
Identifier id = new Identifier().setType(createCodeableConcept(type.getSystem(), type.toCode())).setValue(value.get());
// Certain types have specific systems
if (type == C4BBOrganizationIdentifierType.NPI) {
id.setSystem(TransformerConstants.CODING_NPI_US);
}
provider.addIdentifier(id);
// Set active to value of true
provider.setActive(true);
setLastUpdated(provider, lastUpdated);
// This gets updated for every call, but always set to the same value
eob.getProvider().setReference(PROVIDER_ORG_REFERENCE);
}
}
use of org.hl7.elm.r1.Slice in project kindling by HL7.
the class JsonSpecGenerator method generateCoreElemSliced.
private void generateCoreElemSliced(List<ElementDefinition> elements, ElementDefinition elem, List<ElementDefinition> children, int indent, String pathName, boolean asValue, TypeRefComponent type, boolean last, boolean complex) throws Exception {
String name = tail(elem.getPath());
String en = asValue ? "value[x]" : name;
if (en.contains("[x]"))
en = en.replace("[x]", upFirst(type.getWorkingCode()));
boolean unbounded = elem.hasMax() && elem.getMax().equals("*");
String indentS = "";
for (int i = 0; i < indent; i++) {
indentS += " ";
}
write(indentS);
List<ElementDefinition> slices = getSlices(elem, children);
boolean hasContent = slices.size() > 0;
write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(getEnhancedDefinition(elem)) + "\" class=\"dict\"><span style=\"text-decoration: underline\">" + en + "</span></a>\" : ");
write("[ // <span style=\"color: navy\">" + describeSlicing(elem.getSlicing()) + "</span> " + (hasContent ? "" : "]"));
// write(" <span style=\"color: Gray\">//</span>");
// writeCardinality(elem);
write("\r\n");
int c = 0;
for (ElementDefinition slice : slices) {
write(indentS + " ");
write("{ // <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(slice.getShort()) + "</span>");
write(" <span style=\"color: Gray\">//</span>");
writeCardinality(slice);
write("\r\n");
List<ElementDefinition> extchildren = getChildren(elements, slice);
boolean extcomplex = isComplex(extchildren) && complex;
if (!extcomplex) {
write(indentS + " ");
write(" // from Element: <a href=\"" + prefix + "extensibility.html\">extension</a>\r\n");
}
int cc = 0;
int l = lastChild(extchildren);
for (ElementDefinition child : extchildren) if (child.hasSlicing())
generateCoreElemSliced(elements, child, children, indent + 2, pathName + "." + en, false, child.getType().get(0), ++cc == l, extcomplex);
else if (wasSliced(child, children))
// nothing
;
else if (child.getType().size() == 1)
generateCoreElem(elements, child, indent + 2, pathName + "." + en, false, child.getType().get(0), ++cc == l, extcomplex);
else {
write("<span style=\"color: Gray\">// value[x]: <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(child.getShort()) + "</span>. One of these " + Integer.toString(child.getType().size()) + ":</span>\r\n");
for (TypeRefComponent t : child.getType()) generateCoreElem(elements, child, indent + 2, pathName + "." + en, false, t, ++cc == l, false);
}
c++;
write(indentS);
if (c == slices.size())
write(" }\r\n");
else
write(" },\r\n");
}
if (hasContent) {
write(indentS);
if (last)
write("]\r\n");
else
write("],\r\n");
}
}
use of org.hl7.elm.r1.Slice in project LivingLogic.Java.ul4 by LivingLogic.
the class UL4ONTest method roundtrip.
@Test
public void roundtrip() {
Template template = getTemplate("<?for i in range(10)?>[<?print i?>]<?end for?>");
checkRoundtrip(null);
checkRoundtrip(true);
checkRoundtrip(false);
checkRoundtrip(42);
checkRoundtrip(42.666);
checkRoundtrip("gurk<>'\"");
checkRoundtrip(new Color(0x66, 0x99, 0xcc, 0xff));
checkRoundtrip(LocalDate.now());
checkRoundtrip(LocalDateTime.now());
checkRoundtrip(new TimeDelta(-1, 1, 1));
checkRoundtrip(new MonthDelta(-1));
checkRoundtrip(new Slice(false, false, -1, -1));
checkRoundtrip(new Slice(false, true, -1, 3));
checkRoundtrip(new Slice(true, false, 1, -1));
checkRoundtrip(new Slice(true, true, 1, 3));
checkRoundtrip(asList(1, 2, 3));
checkRoundtrip(makeMap("eins", 1, "zwei", 2, "drei", 3));
checkRoundtrip(makeSet());
checkRoundtrip(makeSet(1, 2, 3));
checkRoundtrip(template);
checkRoundtrip(asList(asList(1, 2, 3), asList(4, 5, 6), asList(7, 8, 9)));
}
use of org.hl7.elm.r1.Slice in project LivingLogic.Java.ul4 by LivingLogic.
the class Decoder method load.
/**
* Reads a object in the UL4ON dump from the reader and returns it.
* This is called by implementations of {@link UL4ONSerializable}, but should
* not be called from outside, as {@code reader} may not be set in this case.
*
* @return the object read from the stream
* @throws IOException if reading from the any underying {@link java.io.Reader} fails
*/
public Object load() throws IOException {
char typecode = nextChar();
if (typecode == '^') {
int position = (Integer) readInt();
return objects.get(position);
} else if (typecode == 'n' || typecode == 'N') {
if (typecode == 'N')
loading(null);
return null;
} else if (typecode == 'b' || typecode == 'B') {
int data = readChar();
Boolean result;
if (data == 'T')
result = true;
else if (data == 'F')
result = false;
else
throw new DecoderException(position, path(), "expected 'T' or 'F', got " + charRepr(data));
if (typecode == 'B')
loading(result);
++position;
return result;
} else if (typecode == 'i' || typecode == 'I') {
StringBuilder buffer = new StringBuilder();
Object result = null;
while (true) {
int c = readChar();
if (c == '-' || Character.isDigit(c))
buffer.append((char) c);
else {
String string = buffer.toString();
try {
result = Integer.parseInt(string);
} catch (NumberFormatException ex1) {
try {
result = Long.parseLong(string);
} catch (NumberFormatException ex2) {
result = new BigInteger(string);
}
}
break;
}
}
if (typecode == 'I')
loading(result);
return result;
} else if (typecode == 'f' || typecode == 'F') {
double result = readFloat();
if (typecode == 'F')
loading(result);
return result;
} else if (typecode == 's' || typecode == 'S') {
String result = Utils.parseUL4StringFromReader(reader);
if (typecode == 'S')
loading(result);
return result;
} else if (typecode == 'c' || typecode == 'C') {
int oldpos = -1;
if (typecode == 'C')
oldpos = beginFakeLoading();
pushType("color");
try {
int r = (Integer) load();
int g = (Integer) load();
int b = (Integer) load();
int a = (Integer) load();
Color result = new Color(r, g, b, a);
if (typecode == 'C')
endFakeLoading(oldpos, result);
return result;
} finally {
popType();
}
} else if (typecode == 'z' || typecode == 'Z') {
int oldpos = -1;
if (typecode == 'Z')
oldpos = beginFakeLoading();
pushType("datetime");
try {
int year = (Integer) load();
int month = (Integer) load();
int day = (Integer) load();
int hour = (Integer) load();
int minute = (Integer) load();
int second = (Integer) load();
int microsecond = (Integer) load();
LocalDateTime result = LocalDateTime.of(year, month, day, hour, minute, second, 1000 * microsecond);
if (typecode == 'Z')
endFakeLoading(oldpos, result);
return result;
} finally {
popType();
}
} else if (typecode == 'x' || typecode == 'X') {
int oldpos = -1;
if (typecode == 'X')
oldpos = beginFakeLoading();
pushType("date");
try {
int year = (Integer) load();
int month = (Integer) load();
int day = (Integer) load();
LocalDate result = LocalDate.of(year, month, day);
if (typecode == 'X')
endFakeLoading(oldpos, result);
return result;
} finally {
popType();
}
} else if (typecode == 't' || typecode == 'T') {
int oldpos = -1;
if (typecode == 'T')
oldpos = beginFakeLoading();
pushType("timedelta");
try {
int days = (Integer) load();
int seconds = (Integer) load();
int microseconds = (Integer) load();
TimeDelta result = new TimeDelta(days, seconds, microseconds);
if (typecode == 'T')
endFakeLoading(oldpos, result);
return result;
} finally {
popType();
}
} else if (typecode == 'm' || typecode == 'M') {
int oldpos = -1;
if (typecode == 'M')
oldpos = beginFakeLoading();
pushType("monthdelta");
try {
int months = (Integer) load();
MonthDelta result = new MonthDelta(months);
if (typecode == 'M')
endFakeLoading(oldpos, result);
return result;
} finally {
popType();
}
} else if (typecode == 'l' || typecode == 'L') {
List result = new ArrayList();
if (typecode == 'L')
loading(result);
pushType("list");
try {
while (true) {
typecode = nextChar();
if (typecode == ']')
return result;
else {
pushbackChar(typecode);
result.add(load());
}
}
} finally {
popType();
}
} else if (typecode == 'd' || typecode == 'D' || typecode == 'e' || typecode == 'E') {
Map result = (typecode == 'e' || typecode == 'E') ? new LinkedHashMap() : new HashMap();
if (typecode == 'D' || typecode == 'E')
loading(result);
pushType("list");
try {
while (true) {
typecode = nextChar();
if (typecode == '}')
return result;
else {
pushbackChar(typecode);
Object key = load();
Object value = load();
if (key instanceof String) {
Object oldKey = keys.get(key);
if (oldKey == null)
keys.put(key, key);
else
key = oldKey;
}
result.put(key, value);
}
}
} finally {
popType();
}
} else if (typecode == 'y' || typecode == 'Y') {
Set result = new HashSet();
if (typecode == 'Y')
loading(result);
pushType("set");
try {
while (true) {
typecode = nextChar();
if (typecode == '}')
return result;
else {
pushbackChar(typecode);
Object item = load();
result.add(item);
}
}
} finally {
popType();
}
} else if (typecode == 'r' || typecode == 'R') {
int oldpos = -1;
if (typecode == 'R')
oldpos = beginFakeLoading();
pushType("set");
Object start;
Object stop;
try {
start = load();
stop = load();
} finally {
popType();
}
boolean hasStart = (start != null);
boolean hasStop = (stop != null);
int startIndex = hasStart ? com.livinglogic.ul4.Utils.toInt(start) : -1;
int stopIndex = hasStop ? com.livinglogic.ul4.Utils.toInt(stop) : -1;
Slice result = new Slice(hasStart, hasStop, startIndex, stopIndex);
if (typecode == 'R')
endFakeLoading(oldpos, result);
return result;
} else if (typecode == 'o' || typecode == 'O') {
int oldpos = -1;
if (typecode == 'O')
oldpos = beginFakeLoading();
String name = (String) load();
UL4ONSerializable result = createObject(name, null);
if (result == null)
throw new DecoderException(position, path(), com.livinglogic.ul4.Utils.formatMessage("can't load object of type {!r}", name));
if (typecode == 'O')
endFakeLoading(oldpos, result);
pushType(name);
try {
result.loadUL4ON(this);
int nextTypecode = nextChar();
if (nextTypecode != ')')
throw new DecoderException(position, path(), "object terminator ')' expected, got " + charRepr(nextTypecode));
return result;
} finally {
popType();
}
} else if (typecode == 'p' || typecode == 'P') {
int oldpos = -1;
if (typecode == 'P')
oldpos = beginFakeLoading();
String name = (String) load();
String id = (String) load();
UL4ONSerializable result = createObject(name, id);
if (result == null) {
throw new DecoderException(position, path(), com.livinglogic.ul4.Utils.formatMessage("can't load object of type {!r} with id {!r}", name, id));
}
if (typecode == 'P')
endFakeLoading(oldpos, result);
pushType(name);
try {
result.loadUL4ON(this);
int nextTypecode = nextChar();
if (nextTypecode != ')')
throw new DecoderException(position, path(), "object terminator ')' expected, got " + charRepr(nextTypecode));
return result;
} finally {
popType();
}
} else
throw new DecoderException(position, path(), "unknown typecode " + charRepr(typecode));
}
use of org.hl7.elm.r1.Slice in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method testSlicingExtensionComplex.
/**
* we're going to slice Patient.extension and refer to extension by profile. one of the extensions is complex, and we're going to walk into
* it and make it must support
*
* implicit: whether to rely on implicit extension slicing
*/
private void testSlicingExtensionComplex(boolean implicit) 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());
// set the slice up
ElementDefinition id;
if (!implicit) {
id = focus.getDifferential().addElement();
id.setPath("Patient.extension");
id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator("url");
}
// first slice - a simple one to get us going:
id = focus.getDifferential().addElement();
id.setPath("Patient.extension");
id.setName("simple");
id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/patient-birthTime");
// second slice - the complex one
// we walk into this and fix properties on the inner extensions
id = focus.getDifferential().addElement();
id.setPath("Patient.extension");
id.setName("complex");
id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality");
if (!implicit) {
id = focus.getDifferential().addElement();
id.setPath("Patient.extension.extension");
id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator("url");
}
id = focus.getDifferential().addElement();
id.setPath("Patient.extension.extension");
id.setName("code");
id.setMustSupport(true);
id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality#code");
id = focus.getDifferential().addElement();
id.setPath("Patient.extension.extension");
id.setName("period");
id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality#period");
// prohibit this one....
id.setMax("0");
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
// ok, there's going to 1 (simple) + complex: 1 + id + extnesion.slice + extension.code + (4 inside from that) + extension.period + (4 inside from that) + value + url = 16
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 16;
// custom checks
ok = ok && rule(focus.getSnapshot().getElement().get(7).getPath().equals("Patient.extension"), "element 7 (base) path");
ok = ok && rule(focus.getSnapshot().getElement().get(7).hasSlicing(), "element 7 slicing");
ok = ok && rule(focus.getSnapshot().getElement().get(8).getPath().equals("Patient.extension"), "element 8 (1st slice) path");
ok = ok && rule(focus.getSnapshot().getElement().get(8).getName().equals("simple"), "element 8 (1st slice) name");
ok = ok && rule(focus.getSnapshot().getElement().get(8).getType().get(0).getProfile().get(0).getValue().equals("http://hl7.org/fhir/StructureDefinition/patient-birthTime"), "element 9 (2nd slice) profile name");
ok = ok && rule(focus.getSnapshot().getElement().get(9).getPath().equals("Patient.extension"), "element 9 (2nd slice) path");
ok = ok && rule(focus.getSnapshot().getElement().get(9).getName().equals("complex"), "element 8 (1st slice) name");
ok = ok && rule(focus.getSnapshot().getElement().get(9).getType().get(0).getProfile().get(0).getValue().equals("http://hl7.org/fhir/StructureDefinition/patient-nationality"), "element 9 (2nd slice) profile name");
ok = ok && rule(focus.getSnapshot().getElement().get(10).getPath().equals("Patient.extension.id"), "element 10 (2nd slice).id path");
ok = ok && rule(focus.getSnapshot().getElement().get(11).getPath().equals("Patient.extension.extension"), "element 11 (2nd slice).extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(12).getPath().equals("Patient.extension.extension"), "element 12 (2nd slice).extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(12).getMustSupport(), "element 12 (2nd slice).extension must support");
ok = ok && rule(focus.getSnapshot().getElement().get(13).getPath().equals("Patient.extension.extension.id"), "element 13 (2nd slice).extension.id path");
ok = ok && rule(focus.getSnapshot().getElement().get(14).getPath().equals("Patient.extension.extension.extension"), "element 14 (2nd slice).extension.extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(15).getPath().equals("Patient.extension.extension.url"), "element 15 (2nd slice).extension.url path");
ok = ok && rule(focus.getSnapshot().getElement().get(16).getPath().equals("Patient.extension.extension.valueCodeableConcept"), "element 16 (2nd slice).extension.valueCodeableConcept path");
ok = ok && rule(focus.getSnapshot().getElement().get(17).getPath().equals("Patient.extension.extension"), "element 17 (2nd slice).extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(17).getMax().equals("0"), "element 17 (2nd slice).extension cardinality");
ok = ok && rule(focus.getSnapshot().getElement().get(18).getPath().equals("Patient.extension.extension.id"), "element 18 (2nd slice).extension.id path");
ok = ok && rule(focus.getSnapshot().getElement().get(19).getPath().equals("Patient.extension.extension.extension"), "element 19 (2nd slice).extension.extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(20).getPath().equals("Patient.extension.extension.url"), "element 20 (2nd slice).extension.url path");
ok = ok && rule(focus.getSnapshot().getElement().get(21).getPath().equals("Patient.extension.extension.valuePeriod"), "element 21 (2nd slice).extension.valuePeriod path");
ok = ok && rule(focus.getSnapshot().getElement().get(22).getPath().equals("Patient.extension.url"), "element 22 (2nd slice).url path");
ok = ok && rule(focus.getSnapshot().getElement().get(23).getPath().equals("Patient.extension.value[x]"), "element 23 (2nd slice).url path");
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 <= 7 ? i : i + 16);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
if (f.getPath().equals("Patient.extension")) {
ok = f.hasSlicing();
if (ok)
f.setSlicing(null);
}
if (// no compare that because the definitions get overwritten
!f.getPath().equals("Patient.extension"))
ok = Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation slicing extensions complex (" + (implicit ? "implicit" : "not implicit") + ") failed");
} else
System.out.println("Snap shot generation slicing extensions complex (" + (implicit ? "implicit" : "not implicit") + ") passed");
}
Aggregations