use of io.adminshell.aas.v3.model.Range in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MedicationRequestFHIRConversionTest method dosageInstructionTestDoseRangeRXO.
@Test
void dosageInstructionTestDoseRangeRXO() {
// Test dosageInstruction.DoseRange using RXO segment WITH a range (RXO.2 exists and RXO.3 exists)
String hl7message = "MSH|^~\\\\&|||||20210101000000||OMP^O09|MSGID|T|2.6\n" + "PID|||1234||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|OP||||||||||||||||||||||\n" + // RXO.5 through RXO.35 not used.
"RXO|00054418425^Dexamethasone 4 MG Oral Tablet^NDC^^^^^^dexamethasone (DECADRON) 4 MG TABS|100|150|CC||||||||||||||||||||||||||\n";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
List<Resource> medicationRequestList = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
// Confirm that one medicationRequest was created.
assertThat(medicationRequestList).hasSize(1);
MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequestList.get(0), ResourceUtils.context);
Range doseRange = medicationRequest.getDosageInstructionFirstRep().getDoseAndRateFirstRep().getDoseRange();
// doseRange.low(RXO.2)
assertThat(doseRange.getLow().getValue()).hasToString("100.0");
// RXO.4
assertThat(doseRange.getLow().getUnit()).isEqualTo("CC");
// Defaulted
assertThat(doseRange.getLow().getSystem()).isEqualTo("http://unitsofmeasure.org");
// doseRange.high(RXO.3)
assertThat(doseRange.getHigh().getValue()).hasToString("150.0");
// RXO.4
assertThat(doseRange.getHigh().getUnit()).isEqualTo("CC");
// Defaulted
assertThat(doseRange.getHigh().getSystem()).isEqualTo("http://unitsofmeasure.org");
// Verify no extraneous resources
// Expect MedicationRequest and Patient
assertThat(e).hasSize(2);
}
use of io.adminshell.aas.v3.model.Range in project molgenis by molgenis.
the class AttributeRequestMapperImpl method toAttribute.
private Attribute toAttribute(CreateAttributeRequest attributeRequest, EntityType entityType, @Nullable @CheckForNull Integer index) {
Attribute attribute = attributeFactory.create();
// set id/label/lookupIndex before setting other properties
attribute.setIdAttribute(attributeRequest.getIdAttribute());
attribute.setLabelAttribute(attributeRequest.getLabelAttribute());
attribute.setLookupAttributeIndex(attributeRequest.getLookupAttributeIndex());
String id = attributeRequest.getId();
if (id != null) {
attribute.setIdentifier(id);
}
attribute.setName(attributeRequest.getName());
attribute.setEntity(entityType);
Integer sequenceNumber = attributeRequest.getSequenceNr();
if (sequenceNumber == null) {
sequenceNumber = index;
}
if (sequenceNumber != null) {
attribute.setSequenceNumber(sequenceNumber);
}
String type = attributeRequest.getType();
if (type != null) {
attribute.setDataType(AttributeType.toEnum(type));
}
Optional.ofNullable(attributeRequest.getMaxLength()).ifPresent(attribute::setMaxLength);
EntityType refEntityType;
String refEntityTypeId = attributeRequest.getRefEntityType();
if (refEntityTypeId != null) {
refEntityType = (EntityType) entityManager.getReference(entityTypeMetadata, refEntityTypeId);
attribute.setRefEntity(refEntityType);
}
if (attributeRequest.getCascadeDelete() != null) {
attribute.setCascadeDelete(attributeRequest.getCascadeDelete());
}
ImmutableList<Order> orderBy = attributeRequest.getOrderBy();
attribute.setOrderBy(orderBy != null ? sortMapper.map(Sort.create(orderBy), entityType) : null);
attribute.setExpression(attributeRequest.getExpression());
Boolean nullable = attributeRequest.getNullable();
if (nullable != null) {
attribute.setNillable(nullable);
}
Boolean auto = attributeRequest.getAuto();
if (auto != null) {
attribute.setAuto(auto);
}
Boolean visible = attributeRequest.getVisible();
if (visible != null) {
attribute.setVisible(visible);
}
processI18nLabel(attributeRequest.getLabel(), attribute);
processI18nDescription(attributeRequest.getDescription(), attribute);
Boolean aggregatable = attributeRequest.getAggregatable();
if (aggregatable != null) {
attribute.setAggregatable(aggregatable);
}
List<String> enumOptions = attributeRequest.getEnumOptions();
if (enumOptions != null) {
attribute.setEnumOptions(enumOptions);
}
Range range = attributeRequest.getRange();
if (range != null) {
attribute.setRange(map(range));
}
Boolean readonly = attributeRequest.getReadonly();
if (readonly != null) {
attribute.setReadOnly(readonly);
}
Boolean unique = attributeRequest.getUnique();
if (unique != null) {
attribute.setUnique(unique);
}
attribute.setNullableExpression(attributeRequest.getNullableExpression());
attribute.setVisibleExpression(attributeRequest.getVisibleExpression());
attribute.setValidationExpression(attributeRequest.getValidationExpression());
attribute.setDefaultValue(attributeRequest.getDefaultValue());
return attribute;
}
use of io.adminshell.aas.v3.model.Range in project molgenis by molgenis.
the class AttributeRequestMapperImpl method updateAttributeValue.
private void updateAttributeValue(Attribute attribute, String key, Object value) {
switch(key) {
case "id":
attribute.setIdentifier(getStringValue(value));
break;
case "name":
attribute.setName(getStringValue(value));
break;
case "sequenceNr":
setSequenceNumber(attribute, value);
break;
case "type":
setAttributeType(attribute, value);
break;
case "refEntityType":
setRefEntityType(attribute, value);
break;
case "cascadeDelete":
String cascadeValue = getStringValue(value);
Boolean isCascade = cascadeValue != null ? Boolean.valueOf(cascadeValue) : null;
attribute.setCascadeDelete(isCascade);
break;
case "orderBy":
mapOrderBy(value).ifPresent(attribute::setOrderBy);
break;
case "expression":
attribute.setExpression(getStringValue(value));
break;
case "nullable":
String nullableValue = getStringValue(value);
attribute.setNillable(Boolean.parseBoolean(nullableValue));
break;
case "auto":
String autoValue = getStringValue(value);
attribute.setAuto(Boolean.parseBoolean(autoValue));
break;
case "visible":
String visibleValue = getStringValue(value);
attribute.setVisible(Boolean.parseBoolean(visibleValue));
break;
case "label":
I18nValue i18Label = I18nValueMapper.toI18nValue(value);
processI18nLabel(i18Label, attribute);
break;
case "description":
I18nValue i18Description = I18nValueMapper.toI18nValue(value);
processI18nDescription(i18Description, attribute);
break;
case "aggregatable":
attribute.setAggregatable(Boolean.parseBoolean(value.toString()));
break;
case "enumOptions":
setEnumOptions(attribute, value);
break;
case "range":
Range range = mapRange(value);
if (range != null) {
attribute.setRange(map(range));
}
break;
case "readonly":
setBooleanValue(attribute, value, IS_READ_ONLY);
break;
case "unique":
setBooleanValue(attribute, value, IS_UNIQUE);
break;
case "defaultValue":
attribute.setDefaultValue(getStringValue(value));
break;
case "nullableExpression":
attribute.setNullableExpression(getStringValue(value));
break;
case "visibleExpression":
attribute.setVisibleExpression(getStringValue(value));
break;
case "validationExpression":
attribute.setValidationExpression(getStringValue(value));
break;
case "mappedByAttribute":
case "parent":
// Skip now and process after all attributes in the request have been processed
break;
case "tags":
throw new UnsupportedFieldException(key);
case "idAttribute":
attribute.setIdAttribute(DataConverter.toBoolean(value));
break;
case "labelAttribute":
attribute.setLabelAttribute(DataConverter.toBoolean(value));
break;
case "lookupAttributeIndex":
attribute.setLookupAttributeIndex(DataConverter.toInt(value));
break;
default:
throw new InvalidKeyException("attribute", key);
}
}
use of io.adminshell.aas.v3.model.Range in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testReadValueFromAssetConnectionAndUpdatePersistence.
@Test
public void testReadValueFromAssetConnectionAndUpdatePersistence() throws AssetConnectionException, ResourceNotFoundException {
RequestHandler requestHandler = new DeleteSubmodelByIdRequestHandler(persistence, messageBus, assetConnectionManager);
Reference parentRef = new DefaultReference.Builder().key(new DefaultKey.Builder().value("sub").idType(KeyType.IRI).type(KeyElements.SUBMODEL).build()).build();
SubmodelElement prop1 = new DefaultProperty.Builder().idShort("prop1").value("test").valueType("string").build();
SubmodelElement range = new DefaultRange.Builder().idShort("range1").max("1.0").min("0").valueType("double").build();
SubmodelElement prop2 = new DefaultProperty.Builder().idShort("prop2").value("test").valueType("string").build();
SubmodelElementCollection collection = new DefaultSubmodelElementCollection.Builder().idShort("col1").value(prop2).build();
SubmodelElement prop1_new = new DefaultProperty.Builder().idShort("prop1").value("testNew").valueType("string").build();
SubmodelElement range_new = new DefaultRange.Builder().idShort("range1").max("1.0").min("0").valueType("double").build();
SubmodelElement prop2_new = new DefaultProperty.Builder().idShort("prop2").value("testNew").valueType("string").build();
List<SubmodelElement> submodelElements = List.of(prop1, range, collection);
AssetValueProvider provider_prop1 = mock(AssetValueProvider.class);
AssetValueProvider provider_prop2 = mock(AssetValueProvider.class);
AssetValueProvider provider_range1 = mock(AssetValueProvider.class);
when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
// mock value prop1
when(assetConnectionManager.getValueProvider(AasUtils.toReference(parentRef, prop1))).thenReturn(provider_prop1);
when(provider_prop1.getValue()).thenReturn(ElementValueMapper.toValue(prop1_new));
// mock value prop2
when(assetConnectionManager.getValueProvider(AasUtils.toReference(AasUtils.toReference(parentRef, collection), prop2))).thenReturn(provider_prop2);
when(provider_prop2.getValue()).thenReturn(ElementValueMapper.toValue(prop2_new));
// mock value range
when(assetConnectionManager.getValueProvider(AasUtils.toReference(parentRef, range))).thenReturn(provider_range1);
when(provider_range1.getValue()).thenReturn(ElementValueMapper.toValue(range_new));
requestHandler.readValueFromAssetConnectionAndUpdatePersistence(parentRef, submodelElements);
verify(persistence).put(null, AasUtils.toReference(parentRef, prop1), prop1_new);
verify(persistence).put(null, AasUtils.toReference(AasUtils.toReference(parentRef, collection), prop2), prop2_new);
Assert.assertEquals(prop1_new, prop1);
Assert.assertEquals(prop2_new, prop2);
Assert.assertEquals(range_new, range);
}
use of io.adminshell.aas.v3.model.Range in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setRangeValueAndType.
/**
* Adds the min and max properties to the UA range object and sets the values
*
* @param aasRange The AAS range object
* @param range The corresponding UA range object
* @param submodel The corresponding submodel
* @param rangeRef The AAS reference to the Range
*/
private void setRangeValueAndType(Range aasRange, AASRangeType range, Submodel submodel, Reference rangeRef) {
try {
String minValue = aasRange.getMin();
String maxValue = aasRange.getMax();
NodeId myPropertyIdMin = new NodeId(getNamespaceIndex(), range.getNodeId().getValue().toString() + "." + AASRangeType.MIN);
NodeId myPropertyIdMax = new NodeId(getNamespaceIndex(), range.getNodeId().getValue().toString() + "." + AASRangeType.MAX);
String valueType = aasRange.getValueType();
QualifiedName browseNameMin = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRangeType.getNamespaceUri(), AASRangeType.MIN).toQualifiedName(getNamespaceTable());
LocalizedText displayNameMin = LocalizedText.english(AASRangeType.MIN);
QualifiedName browseNameMax = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRangeType.getNamespaceUri(), AASRangeType.MAX).toQualifiedName(getNamespaceTable());
LocalizedText displayNameMax = LocalizedText.english(AASRangeType.MAX);
submodelElementAasMap.put(myPropertyIdMin, new SubmodelElementData(aasRange, submodel, SubmodelElementData.Type.RANGE_MIN, rangeRef));
submodelElementAasMap.put(myPropertyIdMax, new SubmodelElementData(aasRange, submodel, SubmodelElementData.Type.RANGE_MAX, rangeRef));
submodelElementOpcUAMap.put(rangeRef, range);
TypedValue minTypedValue = TypedValueFactory.create(valueType, minValue);
TypedValue maxTypedValue = TypedValueFactory.create(valueType, maxValue);
AASValueTypeDataType valueDataType;
if (minTypedValue != null) {
valueDataType = ValueConverter.datatypeToValueType(minTypedValue.getDataType());
} else {
valueDataType = ValueConverter.stringToValueType(valueType);
}
range.setValueType(valueDataType);
switch(valueDataType) {
//
case Boolean:
if (minValue != null) {
PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myBoolProperty.setDataTypeId(Identifiers.Boolean);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myBoolProperty.setValue(minTypedValue.getValue());
}
myBoolProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myBoolProperty);
}
if (maxValue != null) {
PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myBoolProperty.setDataTypeId(Identifiers.Boolean);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myBoolProperty.setValue(maxTypedValue.getValue());
}
myBoolProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myBoolProperty);
}
break;
// break;
case Int32:
if (minValue != null) {
PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myIntProperty.setDataTypeId(Identifiers.Int32);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myIntProperty.setValue(minTypedValue.getValue());
}
myIntProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myIntProperty);
}
if (maxValue != null) {
PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myIntProperty.setDataTypeId(Identifiers.Int32);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myIntProperty.setValue(maxTypedValue.getValue());
}
myIntProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myIntProperty);
}
break;
case Int64:
if (minValue != null) {
PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myLongProperty.setDataTypeId(Identifiers.Int64);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
Object obj = minTypedValue.getValue();
if (!(obj instanceof Long)) {
obj = Long.parseLong(obj.toString());
}
myLongProperty.setValue(obj);
}
myLongProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myLongProperty);
}
if (maxValue != null) {
PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myLongProperty.setDataTypeId(Identifiers.Int64);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
Object obj = maxTypedValue.getValue();
if (!(obj instanceof Long)) {
obj = Long.parseLong(obj.toString());
}
myLongProperty.setValue(obj);
}
myLongProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myLongProperty);
}
break;
case Int16:
if (minValue != null) {
PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myInt16Property.setDataTypeId(Identifiers.Int16);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myInt16Property.setValue(minTypedValue.getValue());
}
myInt16Property.setDescription(new LocalizedText("", ""));
range.addProperty(myInt16Property);
}
if (maxValue != null) {
PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myInt16Property.setDataTypeId(Identifiers.Int16);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myInt16Property.setValue(maxTypedValue.getValue());
}
myInt16Property.setDescription(new LocalizedText("", ""));
range.addProperty(myInt16Property);
}
break;
case SByte:
if (minValue != null) {
PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
mySByteProperty.setDataTypeId(Identifiers.SByte);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
mySByteProperty.setValue(minTypedValue.getValue());
}
mySByteProperty.setDescription(new LocalizedText("", ""));
range.addProperty(mySByteProperty);
}
if (maxValue != null) {
PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
mySByteProperty.setDataTypeId(Identifiers.SByte);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
mySByteProperty.setValue(maxTypedValue.getValue());
}
mySByteProperty.setDescription(new LocalizedText("", ""));
range.addProperty(mySByteProperty);
}
break;
//
case Double:
if (minValue != null) {
PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myDoubleProperty.setDataTypeId(Identifiers.Double);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myDoubleProperty.setValue(minTypedValue.getValue());
}
myDoubleProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myDoubleProperty);
}
if (maxValue != null) {
PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myDoubleProperty.setDataTypeId(Identifiers.Double);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myDoubleProperty.setValue(maxTypedValue.getValue());
}
myDoubleProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myDoubleProperty);
}
break;
case Float:
if (minValue != null) {
PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myFloatProperty.setDataTypeId(Identifiers.Float);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myFloatProperty.setValue(minTypedValue.getValue());
}
myFloatProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myFloatProperty);
}
if (maxValue != null) {
PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myFloatProperty.setDataTypeId(Identifiers.Float);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myFloatProperty.setValue(maxTypedValue.getValue());
}
myFloatProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myFloatProperty);
}
break;
//
case String:
if (minValue != null) {
PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myStringProperty.setDataTypeId(Identifiers.String);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myStringProperty.setValue(minTypedValue.getValue());
}
myStringProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myStringProperty);
}
if (maxValue != null) {
PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myStringProperty.setDataTypeId(Identifiers.String);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myStringProperty.setValue(maxTypedValue.getValue());
}
myStringProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myStringProperty);
}
break;
// break;
default:
logger.warn("setRangeValueAndType: Range " + range.getBrowseName().getName() + ": Unknown type: " + valueType + "; use string as default");
if (minValue != null) {
PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myStringProperty.setDataTypeId(Identifiers.String);
myStringProperty.setValue(minValue);
myStringProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myStringProperty);
}
if (maxValue != null) {
PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myStringProperty.setDataTypeId(Identifiers.String);
myStringProperty.setValue(maxValue);
myStringProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myStringProperty);
}
break;
}
} catch (Throwable ex) {
logger.error("setRangeValueAndType Exception", ex);
}
}
Aggregations