Skip to content

Commit

Permalink
attributes got by using the program endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ifoche committed Dec 13, 2015
1 parent dc2f91e commit 252a1e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ private void enableMetaDataFlags() {
LoadingController.enableLoading(context, ResourceType.ASSIGNEDPROGRAMS);
LoadingController.enableLoading(context, ResourceType.PROGRAMS);
LoadingController.enableLoading(context, ResourceType.OPTIONSETS);
LoadingController.enableLoading(context, ResourceType.ATTRIBUTEVALUES);
LoadingController.enableLoading(context, ResourceType.EVENTS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@
import org.eyeseetea.malariacare.database.iomodules.dhis.importer.VisitableFromSDK;
import org.eyeseetea.malariacare.database.model.CompositeScore;
import org.hisp.dhis.android.sdk.persistence.models.Attribute;
import org.hisp.dhis.android.sdk.persistence.models.Attribute$Table;
import org.hisp.dhis.android.sdk.persistence.models.AttributeValue;
import org.hisp.dhis.android.sdk.persistence.models.AttributeValue$Table;
import org.hisp.dhis.android.sdk.persistence.models.DataElement;
import org.hisp.dhis.android.sdk.persistence.models.DataElementAttributeValue;
import org.hisp.dhis.android.sdk.persistence.models.DataElementAttributeValue$Table;
import org.hisp.dhis.android.sdk.persistence.models.Program;
import org.hisp.dhis.android.sdk.persistence.models.Program$Table;
import org.hisp.dhis.android.sdk.persistence.models.ProgramStage;
Expand Down Expand Up @@ -192,14 +188,12 @@ public boolean isQuestion() {
* @return
*/
public AttributeValue findAttributeValue(Attribute attribute){
return new Select().from(AttributeValue.class).as("av")
.join(DataElementAttributeValue.class, Join.JoinType.LEFT).as("dea")
.on(
Condition.column(ColumnAlias.columnWithTable("dea", DataElementAttributeValue$Table.ATTRIBUTEVALUE_ATTRIBUTEVALUEID))
.eq(ColumnAlias.columnWithTable("av", AttributeValue$Table.ID)))
.where(Condition.column(ColumnAlias.columnWithTable("dea", DataElementAttributeValue$Table.DATAELEMENTID)).eq(dataElement.getUid()))
//For the given survey
.and(Condition.column(ColumnAlias.columnWithTable("av", AttributeValue$Table.ATTRIBUTE_ATTRIBUTEID)).eq(attribute.getUid())).querySingle();

for (AttributeValue attributeValue: getDataElement().getAttributeValues()){
if (attributeValue.getAttribute().getUid().equals(attribute.getUid()))
return attributeValue;
}
return null;
}


Expand All @@ -211,7 +205,7 @@ public AttributeValue findAttributeValue(Attribute attribute){
public String findAttributeValueByCode(String code){

//Find the right attribute
Attribute attribute= AttributeExtended.findAttributeByCode(code);
Attribute attribute = AttributeExtended.findAttributeByCode(code);
//No such attribute -> done
if(attribute==null){
return null;
Expand All @@ -226,25 +220,18 @@ public String findAttributeValueByCode(String code){
}

/**
* Find the attribute in a dataelement for the given attribute
* Find the attribute in a dataelement for the given code
* @param dataElement
* @param code
* @return
*/
public AttributeValue findAttributeValuefromDataElementCode(String code,DataElement dataElement){
//select * from Attribute join AttributeValue on Attribute.id = attributeValue.attributeId join DataElementAttributeValue on attributeValue.id=DataElementAttributeValue.attributeValueId where DataElementAttributeValue.dataElementId="vWgsPN1RPLl" and code="Order"
return new Select().from(AttributeValue.class).as("av")
.join(Attribute.class, Join.JoinType.LEFT).as("at")
.on(
Condition.column(ColumnAlias.columnWithTable("at", Attribute$Table.ID))
.eq(ColumnAlias.columnWithTable("av", AttributeValue$Table.ATTRIBUTE_ATTRIBUTEID)))
.join(DataElementAttributeValue.class, Join.JoinType.LEFT).as("dea")
.on(
Condition.column(ColumnAlias.columnWithTable("dea", DataElementAttributeValue$Table.ATTRIBUTEVALUE_ATTRIBUTEVALUEID))
.eq(ColumnAlias.columnWithTable("av", AttributeValue$Table.ID)))
.where(Condition.column(ColumnAlias.columnWithTable("dea", DataElementAttributeValue$Table.DATAELEMENTID)).eq(dataElement.getUid()))
//For the given survey
.and(Condition.column(ColumnAlias.columnWithTable("at", Attribute$Table.CODE)).eq(code)).querySingle();
for (AttributeValue attributeValue: dataElement.getAttributeValues()){
if (attributeValue.getAttribute().getCode().equals(code))
return attributeValue;
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@

import org.eyeseetea.malariacare.database.iomodules.dhis.importer.IConvertFromSDKVisitor;
import org.eyeseetea.malariacare.database.iomodules.dhis.importer.VisitableFromSDK;
import org.hisp.dhis.android.sdk.persistence.models.Attribute;
import org.hisp.dhis.android.sdk.persistence.models.Attribute$Table;
import org.hisp.dhis.android.sdk.persistence.models.AttributeValue;
import org.hisp.dhis.android.sdk.persistence.models.AttributeValue$Table;
import org.hisp.dhis.android.sdk.persistence.models.DataElement;
import org.hisp.dhis.android.sdk.persistence.models.DataElementAttributeValue;
import org.hisp.dhis.android.sdk.persistence.models.DataElementAttributeValue$Table;
import org.hisp.dhis.android.sdk.persistence.models.Event;

import java.text.ParseException;
Expand Down

0 comments on commit 252a1e4

Please sign in to comment.