use of org.hl7.fhir.dstu2016may.model.SimpleQuantity in project kindling by HL7.
the class JsonLDGenerator method generateElement.
private void generateElement(ElementDefn root, String name, ElementDefn e, JsonObject base, Set<String> types) throws Exception {
if ((e.getTypes().size() == 1 && e.getTypes().get(0).isWildcardType())) {
if (!e.getName().contains("[x]"))
throw new Exception("Element " + e.getName() + " in " + root.getName() + " has multiple types as a choice doesn't have a [x] in the element name");
for (TypeRef tr : datatypes) {
String tn = tr.getName();
if (tn.equals("SimpleQuantity"))
tn = "Quantity";
else
tn = Utilities.capitalize(tn);
String en = e.getName().substring(0, e.getName().length() - 3) + tn;
JsonObject property = new JsonObject();
base.add(name + "." + en, property);
property.addProperty("@id", "http://hl7.org/fhir/" + name + "." + en);
}
// if (e.getTypes().size() == 1)
// generateAny(root, e, e.getName().replace("[x]", ""), props, relative);
// else {
// for (TypeRef t : e.getTypes()) {
// JsonObject property = new JsonObject();
// JsonObject property_ = null;
// String en = e.getName().replace("[x]", "");
// props.add(en+upFirst(t.getName()), property);
// property.addProperty("description", e.getDefinition());
// String tref = null;
// String type = null;
// String pattern = null;
// if (definitions.getPrimitives().containsKey(t.getName())) {
// DefinedCode def = definitions.getPrimitives().get(t.getName());
// type = def.getJsonType();
// pattern = def.getRegex();
// if (!Utilities.noString(pattern))
// property.addProperty("pattern", pattern);
//
// property.addProperty("type", type);
// property_ = new JsonObject();
// props.add("_"+en+upFirst(t.getName()), property_);
// property_.addProperty("description", "Extensions for "+en+upFirst(t.getName()));
// tref = (relative ? "#" : "Element.schema.json#") +"/definitions/Element";
// property_.addProperty("$ref", tref);
// } else {
// String tn = encodeType(e, t, true);
// tref = (relative ? "#" : tn.replace(".", "_")+".schema.json#") +"/definitions/"+tn.replace(".", "_");
// property.addProperty("$ref", tref);
// }
// }
// }
} else if (e.getName().endsWith("[x]")) {
for (TypeRef tr : e.getTypes()) {
String tn = tr.getName();
if (tn.equals("SimpleQuantity"))
tn = "Quantity";
else
tn = Utilities.capitalize(tn);
String en = e.getName().substring(0, e.getName().length() - 3) + tn;
JsonObject property = new JsonObject();
base.add(name + "." + en, property);
property.addProperty("@id", "http://hl7.org/fhir/" + name + "." + en);
}
} else {
JsonObject property = new JsonObject();
base.add(name + "." + e.getName(), property);
if (e.getPath() == null)
property.addProperty("@id", "http://hl7.org/fhir/" + name + "." + e.getName());
else
property.addProperty("@id", "http://hl7.org/fhir/" + e.getPath());
// if we're using lists:
// if (e.unbounded())
// property.addProperty("@container", "@list");
// property.addProperty("fhir-@type", "http://hl7.org/fhir/"+e.typeCode());
// String tref = null;
// String type = null;
// String pattern = null;
//
// if (e.usesCompositeType()/* && types.containsKey(root.getElementByName(e.typeCode().substring(1)))*/) {
// ElementDefn ref = root.getElementByName(definitions, e.typeCode().substring(1), true, false);
// String rtn = types.get(ref);
// if (rtn == null)
// throw new Exception("logic error in schema generator (null composite reference in "+types.toString()+")");
//
// if(rtn == "Type")
// rtn = "Element";
// type=rtn;
// tref = "#/definitions/"+rtn.replace(".", "_");
// } else if (e.getTypes().size() == 0 && e.getElements().size() > 0){
// tref = "#/definitions/"+types.get(e).replace(".", "_");
// type=types.get(e).replace(".", "_");
// } else if (e.getTypes().size() == 1) {
// String tn = encodeType(e, e.getTypes().get(0), true);
// type=tn;
// if (definitions.getPrimitives().containsKey(e.typeCode())) {
// DefinedCode def = definitions.getPrimitives().get(e.typeCode());
// type = def.getJsonType();
// pattern = def.getRegex();
// property_ = new JsonObject();
// props.add("_"+e.getName(), property_);
// property_.addProperty("description", "Extensions for "+e.getName());
// tref = (relative ? "#" : "Element.schema.json#") +"/definitions/Element";
// BindingSpecification cd = e.getBinding();
//
// if (cd != null && (cd.getBinding() == BindingSpecification.BindingMethod.CodeList)) {
// ValueSet vs = cd.getValueSet();
// if (vs!= null) {
// ValueSet ex = workerContext.expandVS(vs, true, false).getValueset();
// JsonArray enums = new JsonArray();
// for (ValueSetExpansionContainsComponent cc : ex.getExpansion().getContains()) {
// enums.add(new JsonPrimitive(cc.getCode()));
// }
// property.add("enum", enums);
// pattern = null;
// }
// }
// } else {
// tref = (relative ? "#" : tn.replace(".", "_")+".schema.json#") +"/definitions/"+tn.replace(".", "_");
// }
// } else
// throw new Exception("how do we get here? "+e.getName()+" in "+root.getName()+" "+Integer.toString(e.getTypes().size()));
//
// if (e.unbounded()) {
// property.addProperty("type", "array");
// if (property_ != null) {
// property_.addProperty("type", "array");
// JsonObject items = new JsonObject();
// property.add("items", items);
// items.addProperty("type", type);
// if (!Utilities.noString(pattern))
// items.addProperty("pattern", pattern);
//
// items = new JsonObject();
// property_.add("items", items);
// items.addProperty("$ref", tref);
// } else {
// JsonObject items = new JsonObject();
// property.add("items", items);
// items.addProperty("$ref", tref);
// }
// } else {
// if (property_ != null) {
// property.addProperty("type", type);
// if (!Utilities.noString(pattern))
// property.addProperty("pattern", pattern);
//
// property_.addProperty("$ref", tref);
// } else if("div".equals(e.getName()) && "xhtml".equals(type)) {
// // Is there a better type, or ref for html?
// property.addProperty("type", "string");
// } else {
// property.addProperty("$ref", tref);
// }
// }
// if (e.getMinCardinality() > 0 && property_ == null)
// required.add(e.getName());
}
}
use of org.hl7.fhir.dstu2016may.model.SimpleQuantity 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));
}
}
use of org.hl7.fhir.dstu2016may.model.SimpleQuantity in project org.hl7.fhir.core by hapifhir.
the class MedicationAdministration30_40 method convertMedicationAdministrationDosageComponent.
public static org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent convertMedicationAdministrationDosageComponent(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationDosageComponent src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent tgt = new org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent();
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
if (src.hasText())
tgt.setTextElement(String30_40.convertString(src.getTextElement()));
if (src.hasSite())
tgt.setSite(CodeableConcept30_40.convertCodeableConcept(src.getSite()));
if (src.hasRoute())
tgt.setRoute(CodeableConcept30_40.convertCodeableConcept(src.getRoute()));
if (src.hasMethod())
tgt.setMethod(CodeableConcept30_40.convertCodeableConcept(src.getMethod()));
if (src.hasDose())
tgt.setDose(SimpleQuantity30_40.convertSimpleQuantity(src.getDose()));
if (src.hasRate()) {
if (src.hasRateQuantity()) {
tgt.setRate(new SimpleQuantity());
Quantity30_40.copyQuantity(src.getRateQuantity(), tgt.getRateSimpleQuantity());
} else {
tgt.setRate(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getRate()));
}
}
return tgt;
}
use of org.hl7.fhir.dstu2016may.model.SimpleQuantity in project org.hl7.fhir.core by hapifhir.
the class FluentPathTests method testDecimalRA.
@Test
public void testDecimalRA() throws FileNotFoundException, IOException, FHIRException {
RiskAssessment r = new RiskAssessment();
SimpleQuantity sq = new SimpleQuantity();
sq.setValue(0.2);
sq.setUnit("%");
sq.setCode("%");
sq.setSystem("http://unitsofmeasure.org");
SimpleQuantity sq1 = new SimpleQuantity();
sq1.setValue(0.4);
sq1.setUnit("%");
sq1.setCode("%");
sq1.setSystem("http://unitsofmeasure.org");
r.addPrediction().setProbability(new Range().setLow(sq).setHigh(sq1));
testBoolean(r, r.getPrediction().get(0).getProbability(), "RiskAssessment.prediction.probabilityRange", "(low.empty() or ((low.code = '%') and (low.system = %ucum))) and (high.empty() or ((high.code = '%') and (high.system = %ucum)))", true);
testBoolean(r, r.getPrediction().get(0), "RiskAssessment.prediction", "probability is decimal implies probability.as(decimal) <= 100", true);
r.getPrediction().get(0).setProbability(new DecimalType(80));
testBoolean(r, r.getPrediction().get(0), "RiskAssessment.prediction", "probability.as(decimal) <= 100", true);
}
use of org.hl7.fhir.dstu2016may.model.SimpleQuantity in project nia-patient-switching-standard-adaptor by NHSDigital.
the class MedicationMapperUtils method buildDosageQuantity.
public static Optional<SimpleQuantity> buildDosageQuantity(PQ quantitySupplied) {
SimpleQuantity quantity = new SimpleQuantity();
quantity.setValue(Double.parseDouble(quantitySupplied.getValue()));
if (quantitySupplied.hasTranslation() && quantitySupplied.getTranslation().get(0).hasOriginalText()) {
quantity.setUnit(quantitySupplied.getTranslation().get(0).getOriginalText());
}
return Optional.of(quantity);
}
Aggregations