Search in sources :

Example 1 with ProtocolEffectRecord

use of ambit2.base.data.study.ProtocolEffectRecord in project ambit-mirror by ideaconsult.

the class SubstanceDatasetResource method getPropertyProcessors.

protected IProcessor getPropertyProcessors(final boolean removeIdentifiers, final boolean removeStringProperties) {
    IQueryRetrieval<ProtocolEffectRecord<String, String, String>> queryP = getEffectQuery();
    MasterDetailsProcessor<SubstanceRecord, ProtocolEffectRecord<String, String, String>, IQueryCondition> effectReader = new MasterDetailsProcessor<SubstanceRecord, ProtocolEffectRecord<String, String, String>, IQueryCondition>(queryP) {

        /**
         */
        private static final long serialVersionUID = -7354966336095750101L;

        ProtocolEffectRecord2SubstanceProperty processor = new ProtocolEffectRecord2SubstanceProperty();

        @Override
        public SubstanceRecord process(SubstanceRecord target) throws Exception {
            if (target == null || target.getSubstanceUUID() == null)
                return target;
            else
                return super.process(target);
        }

        @Override
        protected SubstanceRecord processDetail(SubstanceRecord master, ProtocolEffectRecord<String, String, String> detail) throws Exception {
            if (master.getIdsubstance() <= 0)
                return master;
            if (detail != null) {
                if (detail.getTextValue() != null && detail.getTextValue().toString().startsWith("{")) {
                    JsonNode node = dx.readTree(new StringReader(detail.getTextValue().toString()));
                    List<String> guideline = detail.getProtocol().getGuideline();
                    ILiteratureEntry ref = LiteratureEntry.getInstance(guideline == null ? null : guideline.size() == 0 ? null : guideline.get(0), guideline == null ? null : guideline.size() == 0 ? null : guideline.get(0));
                    Iterator<Entry<String, JsonNode>> i = node.fields();
                    while (i.hasNext()) {
                        Entry<String, JsonNode> val = i.next();
                        SubstanceProperty key = new SubstanceProperty(detail.getProtocol().getTopCategory(), detail.getProtocol().getCategory(), val.getKey(), detail.getUnit(), ref);
                        try {
                            key.setStudyResultType(_r_flags.valueOf(detail.getStudyResultType().replace(":", "").replace("_", "").replace(" ", "").replace("-", "").replace(")", "").replace("(", "")));
                        } catch (Exception x) {
                            key.setStudyResultType(null);
                        }
                        key.setExtendedURI(true);
                        key.setIdentifier(detail.getSampleID() + "/" + val.getKey());
                        groupProperties.add(key);
                        if (val.getValue().get(EffectRecord._fields.loValue.name()) != null) {
                            Number num = val.getValue().get(EffectRecord._fields.loValue.name()).asDouble();
                            master.setRecordProperty(key, num);
                            key.setClazz(Number.class);
                        } else {
                            master.setRecordProperty(key, val.getValue().textValue());
                            key.setClazz(String.class);
                        }
                    }
                } else {
                    boolean isTextValue = ((detail.getLoValue() == null) && (detail.getUpValue() == null));
                    if (isTextValue && removeStringProperties)
                        return master;
                    /*
						 * JsonNode conditions = detail.getConditions() == null
						 * ? null : dx.readTree(new StringReader(
						 * detail.getConditions()));
						 * 
						 * PropertyAnnotations ann = new PropertyAnnotations();
						 * 
						 * Iterator<Entry<String, JsonNode>> i = conditions ==
						 * null ? null : conditions.getFields();
						 * 
						 * if (i != null) while (i.hasNext()) { Entry<String,
						 * JsonNode> val = i.next(); if (val.getValue()
						 * instanceof NullNode) continue;
						 * 
						 * if (val.getValue().getTextValue() == null) try {
						 * PropertyAnnotation a = new PropertyAnnotation();
						 * String unit =
						 * val.getValue().get(EffectRecord._fields.unit.name())
						 * == null ? null :
						 * val.getValue().get(EffectRecord._fields
						 * .unit.name()).asText(); a.setPredicate(val.getKey());
						 * if (unit == null)
						 * a.setObject(val.getValue().get(EffectRecord
						 * ._fields.loValue.name()) .asText()); else {
						 * a.setObject(String.format("%s %s",
						 * val.getValue().get(
						 * EffectRecord._fields.loValue.name()).asText(),
						 * unit)); } ann.add(a); } catch (Exception x) { } else
						 * { PropertyAnnotation a = new PropertyAnnotation();
						 * a.setPredicate(val.getKey());
						 * a.setObject(val.getValue().getTextValue());
						 * ann.add(a); }
						 * 
						 * }
						 */
                    ProtocolEffectRecord<String, IParams, String> effect = new ProtocolEffectRecord<String, IParams, String>();
                    ProtocolEffectRecord2SubstanceProperty.copyEffectRecordValues(detail, effect);
                    try {
                        JsonNode conditions = detail.getConditions() == null ? null : dx.readTree(new StringReader(detail.getConditions()));
                        if (conditions instanceof ObjectNode) {
                            effect.setConditions(SubstanceStudyParser.parseParams((ObjectNode) conditions));
                        }
                    } catch (Exception x) {
                        logger.log(Level.FINE, x.getMessage());
                    }
                    SubstanceProperty key = processor.process(effect);
                    key.setIdentifier(key.createHashedIdentifier(effect.getConditions()));
                    Object oldValue = master.getRecordProperty(key);
                    groupProperties.add(key);
                    /*
						 * if (isTextValue) { //textvalue if (oldValue == null)
						 * master.setProperty(key, detail.getTextValue()); else
						 * { master.setProperty(key, String.format( "%s, %s",
						 * oldValue instanceof Number ? nf.format((Number)
						 * oldValue) : oldValue .toString(),
						 * detail.getTextValue())); }
						 * key.setClazz(String.class); } else { //numeric
						 */
                    Value value = processValue(detail, isTextValue);
                    if (value != null)
                        ProtocolEffectRecord2SubstanceProperty.addValues(master, key, value, oldValue);
                // }
                }
            }
            return master;
        }
    };
    return effectReader;
}
Also used : IQueryCondition(net.idea.modbcum.i.IQueryCondition) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) ILiteratureEntry(ambit2.base.data.ILiteratureEntry) SubstanceRecord(ambit2.base.data.SubstanceRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) LiteratureEntry(ambit2.base.data.LiteratureEntry) Entry(java.util.Map.Entry) ILiteratureEntry(ambit2.base.data.ILiteratureEntry) ProtocolEffectRecord(ambit2.base.data.study.ProtocolEffectRecord) MasterDetailsProcessor(net.idea.modbcum.p.MasterDetailsProcessor) StringReader(java.io.StringReader) Value(ambit2.base.data.study.Value) IParams(ambit2.base.data.study.IParams) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty)

Example 2 with ProtocolEffectRecord

use of ambit2.base.data.study.ProtocolEffectRecord in project ambit-mirror by ideaconsult.

the class CallableSubstancePropertyCreator method parseForm.

protected SubstanceProperty parseForm(Form form) throws ResourceException {
    String topCategory = null;
    ProtocolEffectRecord<String, IParams, String> detail = new ProtocolEffectRecord<String, IParams, String>();
    String endpointcategory = form.getFirstValue(_param_endpointcategory);
    try {
        topCategory = Protocol._categories.valueOf(endpointcategory.trim()).getTopCategory();
    } catch (Exception x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Unsupported endpoint category");
    }
    detail.setEndpoint(form.getFirstValue(_param_name));
    if (detail.getEndpoint() == null)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Unsupported name");
    detail.setUnit(form.getFirstValue(_param_units));
    try {
        String p_conditions = form.getFirstValue(_param_conditions);
        if (p_conditions != null) {
            JsonNode conditions = mapper.readTree(new StringReader(p_conditions));
            if (conditions instanceof ObjectNode) {
                detail.setConditions(SubstanceStudyParser.parseParams((ObjectNode) conditions));
            }
        }
    } catch (Exception x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "conditions: unexpected format");
    }
    String guideline = form.getFirstValue(_param_protocol);
    if (guideline == null)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "protocol: undefined");
    Protocol protocol = new Protocol(guideline);
    // protocol.addGuideline("Method: other: see below");
    protocol.setCategory(endpointcategory);
    protocol.setTopCategory(topCategory);
    detail.setProtocol(protocol);
    try {
        SubstanceProperty p = processor.process(detail);
        p.setIdentifier(p.createHashedIdentifier(detail.getConditions()));
        return p;
    } catch (ResourceException x) {
        throw x;
    } catch (Exception x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProtocolEffectRecord(ambit2.base.data.study.ProtocolEffectRecord) StringReader(java.io.StringReader) IParams(ambit2.base.data.study.IParams) ResourceException(org.restlet.resource.ResourceException) JsonNode(com.fasterxml.jackson.databind.JsonNode) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) Protocol(ambit2.base.data.study.Protocol) ResourceException(org.restlet.resource.ResourceException)

Example 3 with ProtocolEffectRecord

use of ambit2.base.data.study.ProtocolEffectRecord in project ambit-mirror by ideaconsult.

the class ProtocolEffectRecord2SubstanceProperty method conditions2annotations.

public PropertyAnnotations conditions2annotations(ProtocolEffectRecord<String, IParams, String> detail) throws JsonProcessingException, IOException {
    PropertyAnnotations ann = new PropertyAnnotations();
    /*
		 * works but is a hack if (detail.getStudyResultType() != null) {
		 * PropertyAnnotation a = new PropertyAnnotation();
		 * a.setType("reliability"); a.setPredicate("studyResultType");
		 * a.setObject(detail.getStudyResultType()); ann.add(a); }
		 */
    if (detail.getConditions() == null)
        return ann;
    Iterator<Map.Entry> entries = detail.getConditions().entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry entry = entries.next();
        Object key = entry.getKey();
        Object o = entry.getValue();
        if (o == null)
            continue;
        else if (o instanceof Value) {
            Value value = (Value) o;
            PropertyAnnotation a = new PropertyAnnotation();
            a.setType("conditions");
            a.setPredicate(key.toString());
            if (value.getLoValue() instanceof String) {
                a.setObject(value.getLoValue());
            } else {
                a.setObject(String.format("%s%s %s%s %s", value.getLoQualifier() == null ? "" : value.getLoQualifier(), value.getLoValue() == null ? "" : value.getLoValue(), value.getUpQualifier() == null ? "" : value.getUpQualifier(), value.getUpValue() == null ? "" : value.getUpValue(), value.getUnits() == null ? "" : value.getUnits()));
            }
            ann.add(a);
        } else {
            PropertyAnnotation a = new PropertyAnnotation();
            a.setType("conditions");
            a.setPredicate(key.toString());
            a.setObject(o.toString());
            ann.add(a);
        }
    }
    return ann;
}
Also used : PropertyAnnotations(ambit2.base.data.PropertyAnnotations) LiteratureEntry(ambit2.base.data.LiteratureEntry) ILiteratureEntry(ambit2.base.data.ILiteratureEntry) MultiValue(ambit2.base.data.study.MultiValue) Value(ambit2.base.data.study.Value) Map(java.util.Map) PropertyAnnotation(ambit2.base.data.PropertyAnnotation)

Example 4 with ProtocolEffectRecord

use of ambit2.base.data.study.ProtocolEffectRecord in project ambit-mirror by ideaconsult.

the class ReadEffectRecordBySubstance method getObject.

@Override
public ProtocolEffectRecord<String, String, String> getObject(ResultSet rs) throws AmbitException {
    ProtocolEffectRecord<String, String, String> effect = super.getObject(rs);
    try {
        effect.setIdresult(rs.getInt("idresult"));
    } catch (Exception x) {
        effect.setIdresult(-1);
    }
    try {
        effect.setInterpretationResult(rs.getString("interpretation_result"));
    } catch (Exception x) {
        x.printStackTrace();
        effect.setInterpretationResult(null);
    }
    try {
        effect.setStudyResultType(rs.getString("studyResultType"));
    } catch (Exception x) {
        effect.setStudyResultType(null);
    }
    try {
        try {
            effect.setDocumentUUID(I5Utils.getPrefixedUUID(rs.getString("document_prefix"), rs.getString("u")));
        } catch (Exception xx) {
            effect.setDocumentUUID(null);
        }
        Protocol protocol = new Protocol(rs.getString("pendpoint"));
        protocol.addGuideline(rs.getString("guidance"));
        protocol.setCategory(rs.getString("endpointcategory"));
        protocol.setTopCategory(rs.getString("topcategory"));
        effect.setProtocol(protocol);
    /*
	     * String topcategory = rs.getString("topcategory"); String
	     * endpointcategory = rs.getString("endpointcategory"); String
	     * guidance = rs.getString("guidance"); String conditions =
	     * rs.getString("conditions");
	     * 
	     * String key = (topcategory==null?"":topcategory)+
	     * (endpointcategory==null?"":endpointcategory)+
	     * (guidance==null?"":guidance)+ (conditions==null?"":conditions);
	     * effect
	     * .setSampleID(UUID.nameUUIDFromBytes(key.getBytes()).toString());
	     */
    } catch (Exception x) {
        logger.log(Level.WARNING, x.getMessage());
    }
    return effect;
}
Also used : Protocol(ambit2.base.data.study.Protocol) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 5 with ProtocolEffectRecord

use of ambit2.base.data.study.ProtocolEffectRecord in project ambit-mirror by ideaconsult.

the class ProtocolEffectRecord2SubstanceProperty method getReference.

public ILiteratureEntry getReference(ProtocolEffectRecord<String, IParams, String> detail) {
    List<String> guideline = detail.getProtocol().getGuideline();
    ILiteratureEntry ref = LiteratureEntry.getInstance(guideline == null ? null : guideline.size() == 0 ? null : guideline.get(0), guideline == null ? null : guideline.size() == 0 ? null : guideline.get(0));
    return ref;
}
Also used : ILiteratureEntry(ambit2.base.data.ILiteratureEntry)

Aggregations

SubstanceProperty (ambit2.base.data.substance.SubstanceProperty)4 ILiteratureEntry (ambit2.base.data.ILiteratureEntry)3 IParams (ambit2.base.data.study.IParams)3 Protocol (ambit2.base.data.study.Protocol)3 ProtocolEffectRecord (ambit2.base.data.study.ProtocolEffectRecord)3 Value (ambit2.base.data.study.Value)3 ProtocolEffectRecord2SubstanceProperty (ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty)3 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)3 ResourceException (org.restlet.resource.ResourceException)3 LiteratureEntry (ambit2.base.data.LiteratureEntry)2 MultiValue (ambit2.base.data.study.MultiValue)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 StringReader (java.io.StringReader)2 PropertyAnnotation (ambit2.base.data.PropertyAnnotation)1 PropertyAnnotations (ambit2.base.data.PropertyAnnotations)1 SubstanceRecord (ambit2.base.data.SubstanceRecord)1 Params (ambit2.base.data.study.Params)1 ProtocolEffectRecordMatrix (ambit2.base.data.study.ProtocolEffectRecordMatrix)1 ValueAnnotated (ambit2.base.data.study.ValueAnnotated)1