use of org.hl7.fhir.r4.model.Quantity in project beneficiary-fhir-data by CMSgov.
the class PartDEventTransformerV2Test method shouldHaveLineItemQuantity.
@Test
public void shouldHaveLineItemQuantity() {
Quantity quantity = eob.getItemFirstRep().getQuantity();
Quantity compare = new Quantity(60);
assertTrue(compare.equalsDeep(quantity));
}
use of org.hl7.fhir.r4.model.Quantity in project kindling by HL7.
the class SpreadSheetReloader method parseType.
private void parseType(ElementDefinition ed, String value, String hierarchy) throws Exception {
ed.getType().clear();
ed.setContentReferenceElement(null);
if (ed.getPath().equals("Resource.id")) {
ed.addType().setCode("http://hl7.org/fhirpath/System.String").addExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type", new UriType("id"));
} else {
if (Utilities.noString(value)) {
if (ed.getPath().contains(".")) {
ed.addType().setCode("BackboneElement");
}
} else if (value.startsWith("#")) {
ed.setContentReference(value);
} else {
List<TypeRef> tl = new TypeParser(version).parse(value, false, null, context, false);
for (TypeRef tr : tl) {
TypeRefComponent t = ed.addType().setCode(tr.getName());
if ("SimpleQuantity".equals(t.getCode())) {
t.setCode("Quantity");
t.addProfile("http://hl7.org/fhir/StructureDefinition/SimpleQuantity");
}
for (String p : tr.getParams()) {
if (p.equals("Definition")) {
t.addExtension(BuildExtensions.EXT_PATTERN, new CanonicalType("http://hl7.org/fhir/StructureDefinition/Definition"));
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/ActivityDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EventDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EvidenceVariable");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Measure");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/OperationDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/PlanDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Questionnaire");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/SubscriptionTopic");
} else {
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
}
}
if (Utilities.existsInList(tr.getName(), "canonical", "Reference") && !Utilities.noString(hierarchy)) {
t.addExtension(BuildExtensions.EXT_HIERARCHY, new BooleanType(Utilities.existsInList(hierarchy, "true", "True", "TRUE", "1", "y", "Y")));
}
}
}
}
}
use of org.hl7.fhir.r4.model.Quantity in project kindling by HL7.
the class ResourceParser method parseED.
private void parseED(ProfileUtilities pu, ElementDefn ed, ElementDefinition focus, StructureDefinition sd, String parentName) throws IOException {
ed.setMinCardinality(focus.getMin());
ed.setMaxCardinality("*".equals(focus.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(focus.getMax()));
ed.setIsModifier(focus.getIsModifier());
ed.setModifierReason(focus.getIsModifierReason());
ed.setMustSupport(focus.getMustSupport());
ed.setSummaryItem(focus.getIsSummary());
ed.setRegex(ToolingExtensions.readStringExtension(focus, ToolingExtensions.EXT_REGEX));
ed.setXmlAttribute(focus.hasRepresentation(PropertyRepresentation.XMLATTR));
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_DIR)) {
ed.setUmlDir(ToolingExtensions.readStringExtension(focus, BuildExtensions.EXT_UML_DIR));
}
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_BREAK)) {
ed.setUmlBreak(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_UML_BREAK));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_SVG)) {
String svg = BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_SVG);
if (svg.contains("w=")) {
ed.setSvgWidth(Integer.parseInt(svg.substring(svg.indexOf("w=") + 2)));
svg = svg.substring(0, svg.indexOf(";"));
}
ed.setSvgLeft(Integer.parseInt(svg.substring(0, svg.indexOf(","))));
ed.setSvgTop(Integer.parseInt(svg.substring(svg.indexOf(",") + 1)));
}
ed.setName(tail(focus.getPath()));
ed.setShortDefn(focus.getShort());
ed.setDefinition(focus.getDefinition());
ed.setRequirements(focus.getRequirements());
ed.setComments(focus.getComment());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_TODO)) {
ed.setTodo(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_TODO));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES)) {
ed.setCommitteeNotes(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_HINT)) {
ed.setDisplayHint(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_HINT));
}
if (focus.hasExtension(BuildExtensions.EXT_NO_BINDING)) {
ed.setNoBindingAllowed(focus.getExtensionString(BuildExtensions.EXT_NO_BINDING).equals("true"));
}
for (StringType t : focus.getAlias()) {
ed.getAliases().add(t.getValue());
}
if (focus.hasMaxLength()) {
ed.setMaxLength(Integer.toString(focus.getMaxLength()));
}
ed.setExample(focus.getExampleFirstRep().getValue());
ed.setMeaningWhenMissing(focus.getMeaningWhenMissing());
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_TRANSLATABLE)) {
ed.setTranslatable(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_TRANSLATABLE));
}
ed.setOrderMeaning(focus.getOrderMeaning());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)) {
ed.setStandardsStatus(StandardsStatus.fromCode(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION)) {
ed.setNormativeVersion(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION));
}
for (ElementDefinitionConstraintComponent cst : focus.getConstraint()) {
Invariant inv = new Invariant();
inv.setContext(focus.getPath());
inv.setEnglish(cst.getHuman());
if (cst.hasExtension(BuildExtensions.EXT_OCL)) {
inv.setOcl(cst.getExtensionString(BuildExtensions.EXT_OCL));
}
inv.setXpath(cst.getXpath());
inv.setId(cst.getKey());
if (cst.hasExtension(BuildExtensions.EXT_FIXED_NAME)) {
inv.setFixedName(cst.getExtensionString(BuildExtensions.EXT_FIXED_NAME));
}
inv.setSeverity(cst.getSeverity().toCode());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE)) {
inv.setSeverity("best-practice");
}
if (cst.hasExtension(BuildExtensions.EXT_TURTLE)) {
inv.setTurtle(cst.getExtensionString(BuildExtensions.EXT_TURTLE));
}
inv.setRequirements(cst.getRequirements());
inv.setExpression(cst.getExpression());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION)) {
inv.setExplanation(cst.getExtensionString(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION));
}
ed.getInvariants().put(inv.getId(), inv);
invariants.put(inv.getId(), inv);
}
for (IdType cnd : focus.getCondition()) {
Invariant inv = invariants.get(cnd.primitiveValue());
if (inv == null) {
System.out.println("Unable to find invariant " + cnd.primitiveValue());
} else {
ed.getStatedInvariants().add(inv);
}
}
for (ElementDefinitionMappingComponent map : focus.getMapping()) {
String uri = getMappingUri(sd, map.getIdentity());
if ("http://hl7.org/fhir/fivews".equals(uri)) {
ed.setW5(reverseW5(map.getMap()));
} else {
ed.getMappings().put(uri, map.getMap());
}
}
if (focus.hasContentReference()) {
ed.getTypes().add(new TypeRef("@" + focus.getContentReference().substring(1)));
} else {
for (TypeRefComponent tr : focus.getType()) {
if (!Utilities.existsInList(tr.getCode(), "Element", "BackboneElement")) {
TypeRef t = new TypeRef();
ed.getTypes().add(t);
if (tr.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")) {
t.setName(tr.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type"));
} else {
t.setName(tr.getCode());
}
if (ToolingExtensions.hasExtension(tr, BuildExtensions.EXT_HIERARCHY)) {
ed.setHierarchy(ToolingExtensions.readBoolExtension(tr, BuildExtensions.EXT_HIERARCHY));
}
for (CanonicalType u : tr.getProfile()) {
t.setProfile(u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
}
for (CanonicalType u : tr.getTargetProfile()) {
String s = u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", "");
if ("Resource".equals(s)) {
t.getParams().add("Any");
} else {
t.getParams().add(s);
}
}
if (t.getName().equals("Quantity") && "SimpleQuantity".equals(t.getProfile())) {
t.setName("SimpleQuantity");
t.setProfile(null);
}
if ("Resource".equals(t.getProfile())) {
t.setProfile("Any");
}
if (t.getParams().toString().equals("[ActivityDefinition, EventDefinition, EvidenceVariable, Measure, OperationDefinition, PlanDefinition, Questionnaire, SubscriptionTopic]")) {
t.getParams().clear();
t.getParams().add("Definition");
}
}
}
if (ed.getTypes().size() == STAR_TYPES_COUNT) {
ed.getTypes().clear();
ed.getTypes().add(new TypeRef("*"));
}
}
String name = parentName + Utilities.capitalize(ed.getName());
if (focus.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
ed.setStatedType(focus.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name"));
ed.setDeclaredTypeName(ed.getStatedType());
} else if (ed.getTypes().isEmpty() && !focus.hasContentReference()) {
ed.setDeclaredTypeName(name + "Component");
}
if (focus.hasBinding()) {
ed.setBinding(parseBinding(focus.getBinding()));
}
for (ElementDefinition child : pu.getChildList(sd, focus, true, false)) {
ElementDefn c = new ElementDefn();
ed.getElements().add(c);
parseED(pu, c, child, sd, name);
}
// todo:
// private ElementDefinition derivation;
}
use of org.hl7.fhir.r4.model.Quantity in project kindling by HL7.
the class FhirTurtleGenerator method processTypes.
private void processTypes(String baseResourceName, FHIRResource baseResource, ElementDefn td, String predicateBase, boolean innerIsBackbone) throws Exception {
for (ElementDefn ed : td.getElements()) {
String predicateName = predicateBase + "." + (ed.getName().endsWith("[x]") ? ed.getName().substring(0, ed.getName().length() - 3) : ed.getName());
FHIRResource predicateResource;
if (ed.getName().endsWith("[x]")) {
predicateResource = fact.fhir_objectProperty(predicateName);
// Choice entry
if (ed.typeCode().equals("*")) {
// Wild card -- any element works (probably should be more restrictive but...)
Resource targetResource = RDFNamespace.FHIR.resourceRef("Element");
baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource, targetResource, ed.getMinCardinality(), ed.getMaxCardinality()));
predicateResource.domain(baseResource);
predicateResource.range(targetResource);
} else {
// Create a restriction on the union of possible types
List<Resource> typeOpts = new ArrayList<Resource>();
for (TypeRef tr : ed.getTypes()) {
// TODO: Figure out how to get the type reference code
String trName = tr.getName();
if (trName.equals("SimpleQuantity"))
trName = "Quantity";
String qualifiedPredicateName = predicateName + Utilities.capitalize(trName);
Resource targetRes = fact.fhir_class(tr.getName()).resource;
FHIRResource qualifiedPredicate = fact.fhir_objectProperty(qualifiedPredicateName, predicateResource.resource).domain(baseResource).range(targetRes);
typeOpts.add(fact.fhir_cardinality_restriction(qualifiedPredicate.resource, targetRes, ed.getMinCardinality(), ed.getMaxCardinality()));
}
baseResource.restriction(fact.fhir_union(typeOpts));
}
} else {
FHIRResource baseDef;
if (ed.getTypes().isEmpty()) {
predicateResource = fact.fhir_objectProperty(predicateName);
String targetClassName = mapComponentName(baseResourceName, ed.getDeclaredTypeName());
baseDef = fact.fhir_class(targetClassName, innerIsBackbone ? "BackboneElement" : "Element").addDefinition(ed.getDefinition());
processTypes(targetClassName, baseDef, ed, predicateName, innerIsBackbone);
} else {
TypeRef targetType = ed.getTypes().get(0);
String targetName = targetType.getName();
if (targetName.startsWith("@")) {
// Link to earlier definition
ElementDefn targetRef = getElementForPath(targetName.substring(1));
String targetRefName = targetRef.getName();
String targetClassName = baseResourceName + Character.toUpperCase(targetRefName.charAt(0)) + targetRefName.substring(1);
baseDef = fact.fhir_class(targetClassName, innerIsBackbone ? "BackboneElement" : "Element").addDefinition(ed.getDefinition()).addTitle(ed.getShortDefn());
if (!processing.contains(targetRefName)) {
processing.add(targetRefName);
processTypes(targetClassName, baseDef, targetRef, predicateName, innerIsBackbone);
processing.remove(targetRefName);
}
} else {
// A placeholder entry. The rest of the information will be supplied elsewhere
baseDef = fact.fhir_class(targetName);
}
// XHTML the exception, in that the html doesn't derive from Primitive
if (targetName.equals("xhtml"))
predicateResource = fact.fhir_dataProperty(predicateName);
else
predicateResource = fact.fhir_objectProperty(predicateName);
}
predicateResource.addTitle(ed.getShortDefn()).addDefinition(ed.getDefinition()).domain(baseResource);
baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource, baseDef.resource, ed.getMinCardinality(), ed.getMaxCardinality()));
predicateResource.range(baseDef.resource);
if (!Utilities.noString(ed.getW5()))
predicateResource.addObjectProperty(RDFS.subPropertyOf, RDFNamespace.W5.resourceRef(ed.getW5()));
}
}
}
use of org.hl7.fhir.r4.model.Quantity in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ObservationFHIRConversionTest method testObservationSN_valueQuantity_missing_comparator_result.
@Test
void testObservationSN_valueQuantity_missing_comparator_result() throws IOException {
String hl7message = baseMessage + "OBX|1|SN|1554-5^GLUCOSE||^182|mg/dl|70_105||||F";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obsResource).hasSize(1);
Observation obs = (Observation) obsResource.get(0);
// Check valueQuantity
assertNotNull(obs.getValueQuantity());
Quantity q = obs.getValueQuantity();
// code only set if system exists
assertNull(q.getCode());
assertEquals("mg/dl", q.getUnit());
assertNull(q.getSystem());
assertEquals(182, q.getValue().floatValue());
// no comparator passed in
assertNull(q.getComparator());
// Check referenceRange
assertTrue(obs.hasReferenceRange());
assertThat(obs.getReferenceRange()).hasSize(1);
ObservationReferenceRangeComponent range = obs.getReferenceRangeFirstRep();
assertNotNull(range);
assertTrue(range.hasHigh());
assertTrue(range.hasLow());
Quantity high = range.getHigh();
// uses OBX.6.1 for units not text in string
assertEquals("mg/dl", high.getUnit());
assertEquals(105f, high.getValue().floatValue());
Quantity low = range.getLow();
// uses OBX.6.1 for units not text in string
assertEquals("mg/dl", low.getUnit());
assertEquals(70f, low.getValue().floatValue());
assertEquals("70_105", range.getText());
}
Aggregations