use of org.molgenis.api.metadata.v3.model.Range in project molgenis by molgenis.
the class AttributeResponseMapperImpl method mapInternal.
private AttributeResponseData mapInternal(Attribute attr, boolean i18n) {
Builder builder = AttributeResponseData.builder();
builder.setId(attr.getIdentifier());
builder.setName(attr.getName());
builder.setSequenceNr(attr.getSequenceNumber());
builder.setType(getValueString(attr.getDataType()));
Optional.ofNullable(attr.getMaxLength()).ifPresent(builder::setMaxLength);
builder.setIdAttribute(attr.isIdAttribute());
builder.setLabelAttribute(attr.isLabelAttribute());
builder.setLookupAttributeIndex(attr.getLookupAttributeIndex());
if (EntityTypeUtils.isReferenceType(attr)) {
builder.setRefEntityType(LinksResponse.create(null, createEntityTypeResponseUri(attr.getRefEntity()), null));
}
builder.setCascadeDelete(attr.getCascadeDelete());
builder.setMappedBy(attr.getMappedBy() != null ? toAttributeResponse(attr.getMappedBy(), i18n) : null);
if (attr.getDataType() == ONE_TO_MANY && attr.isMappedBy()) {
builder.setOrderBy(map(attr));
}
builder.setLabel(attr.getLabel(LocaleContextHolder.getLocale().getLanguage()));
builder.setDescription(attr.getDescription(LocaleContextHolder.getLocale().getLanguage()));
if (i18n) {
builder.setLabelI18n(getI18nAttrLabel(attr));
getI18nAttrDesc(attr).ifPresent(builder::setDescriptionI18n);
}
builder.setNullable(attr.isNillable());
builder.setAuto(attr.isAuto());
builder.setVisible(attr.isVisible());
builder.setUnique(attr.isUnique());
builder.setReadOnly(attr.isReadOnly());
builder.setAggregatable(attr.isAggregatable());
builder.setExpression(attr.getExpression());
if (attr.getDataType() == AttributeType.ENUM) {
builder.setEnumOptions(attr.getEnumOptions());
}
if (attr.getDataType() == AttributeType.CATEGORICAL || attr.getDataType() == AttributeType.CATEGORICAL_MREF) {
builder.setCategoricalOptions(getCategories(attr.getRefEntity()));
}
org.molgenis.data.Range range = attr.getRange();
if (range != null) {
builder.setRange(Range.create(range.getMin(), range.getMax()));
}
Attribute parent = attr.getParent();
builder.setParentAttributeId(parent != null ? parent.getIdentifier() : null);
builder.setNullableExpression(attr.getNullableExpression());
builder.setVisibleExpression(attr.getVisibleExpression());
builder.setValidationExpression(attr.getValidationExpression());
builder.setDefaultValue(attr.getDefaultValue());
return builder.build();
}
use of org.molgenis.api.metadata.v3.model.Range in project FAAAST-Service by FraunhoferIOSB.
the class TypeExtractor method extractTypeInfo.
public static TypeInfo extractTypeInfo(Object obj) {
if (obj == null) {
return null;
}
Class<?> type = obj.getClass();
if (SubmodelElement.class.isAssignableFrom(type)) {
ElementValueTypeInfo.Builder builder = ElementValueTypeInfo.builder();
SubmodelElement submodelElement = (SubmodelElement) obj;
builder.type(ElementValueMapper.getValueClass(submodelElement.getClass()));
if (AnnotatedRelationshipElement.class.isAssignableFrom(type)) {
AnnotatedRelationshipElement annotatedRelationshipElement = (AnnotatedRelationshipElement) obj;
annotatedRelationshipElement.getAnnotations().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
} else if (SubmodelElementCollection.class.isAssignableFrom(type)) {
SubmodelElementCollection submodelElementCollection = (SubmodelElementCollection) obj;
submodelElementCollection.getValues().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
} else if (Entity.class.isAssignableFrom(type)) {
Entity entity = (Entity) obj;
entity.getStatements().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
} else if (Property.class.isAssignableFrom(obj.getClass())) {
Property property = (Property) obj;
builder.datatype(Datatype.fromName(property.getValueType()));
} else if (Range.class.isAssignableFrom(obj.getClass())) {
Range range = (Range) obj;
builder.datatype(Datatype.fromName(range.getValueType()));
}
return builder.build();
}
if (Submodel.class.isAssignableFrom(type)) {
Submodel submodel = (Submodel) obj;
ContainerTypeInfo.Builder<Object> builder = ContainerTypeInfo.<Object>builder();
builder.type(Submodel.class);
submodel.getSubmodelElements().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
return builder.build();
}
if (Collection.class.isAssignableFrom(type)) {
Collection collection = (Collection) obj;
ContainerTypeInfo.Builder<Integer> builder = ContainerTypeInfo.<Integer>builder();
builder.type(Collection.class);
builder.contentType(TypeToken.of(type).resolveType(COLLECTION_GENERIC_TOKEN).getRawType());
Iterator iterator = collection.iterator();
int i = 0;
while (iterator.hasNext()) {
builder.element(i, extractTypeInfo(iterator.next()));
i++;
}
return builder.build();
}
if (Map.class.isAssignableFrom(type)) {
Map map = (Map) obj;
ContainerTypeInfo.Builder<String> builder = ContainerTypeInfo.<String>builder();
builder.type(Map.class);
builder.contentType(TypeToken.of(type).resolveType(MAP_GENERIC_TOKEN).getRawType());
map.forEach((key, value) -> builder.element(key.toString(), extractTypeInfo(value)));
return builder.build();
}
if (type.isArray()) {
Object[] array = (Object[]) obj;
ContainerTypeInfo.Builder<Integer> builder = ContainerTypeInfo.<Integer>builder();
builder.type(Array.class);
builder.contentType(type.getComponentType());
for (int i = 0; i < array.length; i++) {
builder.element(i, extractTypeInfo(array[i]));
}
return builder.build();
}
return ContainerTypeInfo.<Object>builder().build();
}
use of org.molgenis.api.metadata.v3.model.Range in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MedicationRequestFHIRConversionTest method dosageInstructionTestDoseRangeRXE.
@Test
void dosageInstructionTestDoseRangeRXE() {
// Test dosageInstruction.DoseRange using RXE segment WITH a range
String hl7message = "MSH|^~\\&||||||S1|RDE^O11||T|2.6|||||||||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "ORC|NW|||||E|||||||||||||||||||||||I\n" + // RXE.6 through RXE.44 not used.
"RXE||DUONEB3INH^3 ML PLAS CONT : IPRATROPIUM-ALBUTEROL 0.5-2.5 (3) MG/3ML IN SOLN^ADS|3|6|mL||||||||||||||||||||||||||||||||||\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(RXE.3)
// RXE.3
assertThat(doseRange.getLow().getValue()).hasToString("3.0");
// RXE.5
assertThat(doseRange.getLow().getUnit()).isEqualTo("mL");
// Defaulted
assertThat(doseRange.getLow().getSystem()).isEqualTo("http://unitsofmeasure.org");
// doseRange.high(RXE.4)
assertThat(doseRange.getHigh().getValue()).hasToString("6.0");
// RXE.5
assertThat(doseRange.getHigh().getUnit()).isEqualTo("mL");
assertThat(doseRange.getHigh().getSystem()).isEqualTo("http://unitsofmeasure.org");
// Verify no extraneous resources
// Expect MedicationRequest, Patient
assertThat(e).hasSize(2);
}
use of org.molgenis.api.metadata.v3.model.Range in project quality-measure-and-cohort-service by Alvearie.
the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.
public static Parameter toCohortParameter(Extension extension) {
Parameter parameter;
Type extensionValue = extension.getValue();
if (extensionValue instanceof Base64BinaryType) {
parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
} else if (extensionValue instanceof BooleanType) {
parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
} else if (extensionValue instanceof DateType) {
parameter = new DateParameter(((DateType) extensionValue).asStringValue());
} else if (extensionValue instanceof DateTimeType) {
parameter = convertDateTimeType((DateTimeType) extensionValue);
} else if (extensionValue instanceof DecimalType) {
parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
} else if (extensionValue instanceof InstantType) {
parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
} else if (extensionValue instanceof IntegerType) {
parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
} else if (extensionValue instanceof StringType) {
parameter = new StringParameter(((StringType) extensionValue).getValue());
} else if (extensionValue instanceof TimeType) {
parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
} else if (extensionValue instanceof UriType) {
parameter = new StringParameter(((UriType) extensionValue).getValue());
} else if (extensionValue instanceof Coding) {
parameter = convertCoding((Coding) extensionValue);
} else if (extensionValue instanceof CodeableConcept) {
parameter = convertCodeableConcept((CodeableConcept) extensionValue);
} else if (extensionValue instanceof Period) {
Period castValue = (Period) extensionValue;
parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
} else if (extensionValue instanceof Quantity) {
parameter = convertQuantity((Quantity) extensionValue);
} else if (extensionValue instanceof Range) {
Range castValue = (Range) extensionValue;
parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
} else if (extensionValue instanceof Ratio) {
Ratio castValue = (Ratio) extensionValue;
parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
} else {
throw new UnsupportedFhirTypeException(extensionValue);
}
return parameter;
}
use of org.molgenis.api.metadata.v3.model.Range in project quality-measure-and-cohort-service by Alvearie.
the class FHIRRestUtils method complicatedTypeValueConstructor.
static String complicatedTypeValueConstructor(ParameterDefinition parameterDefinition) {
FhirContext context = FhirContext.forCached(FhirVersionEnum.R4);
IParser parser = context.newJsonParser();
String valueKey;
// In order to use the hapi parser, we cannot translate an extension by itself. The patient object wraps the extension
Patient patient = new Patient();
Extension extension = new Extension();
switch(parameterDefinition.getType()) {
case "Period":
Period period = (Period) parameterDefinition.getExtension().get(0).getValue();
extension.setValue(period);
patient.addExtension(extension);
valueKey = "valuePeriod";
break;
case "Range":
Range range = (Range) parameterDefinition.getExtension().get(0).getValue();
extension.setValue(range);
patient.addExtension(extension);
valueKey = "valueRange";
break;
case "Quantity":
Quantity quantity = (Quantity) parameterDefinition.getExtension().get(0).getValue();
extension.setValue(quantity);
patient.addExtension(extension);
valueKey = "valueQuantity";
break;
default:
throw new RuntimeException("Complicated Type" + parameterDefinition.getType() + " not yet implemented");
}
String intermediateValue = parser.encodeResourceToString(patient);
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode root = mapper.readTree(intermediateValue);
JsonNode nameNode = root.path("extension");
return nameNode.get(0).path(valueKey).toString();
} catch (JsonProcessingException e) {
throw new RuntimeException("There was an issue with json translation", e);
}
}
Aggregations