← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13855: csd: use 'Status' orgunitgroupset for setting record status

 

------------------------------------------------------------
revno: 13855
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-01-27 14:30:28 +0700
message:
  csd: use 'Status' orgunitgroupset for setting record status
modified:
  dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/csd/webapi/CsdController.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/csd/webapi/CsdController.java'
--- dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/csd/webapi/CsdController.java	2014-01-23 16:54:20 +0000
+++ dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/csd/webapi/CsdController.java	2014-01-27 07:30:28 +0000
@@ -28,20 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import org.hisp.dhis.attribute.AttributeValue;
 import org.hisp.dhis.attribute.comparator.AttributeValueSortOrderComparator;
 import org.hisp.dhis.dataset.DataSet;
@@ -78,20 +66,34 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @Controller
-@RequestMapping( value = "/csd" )
+@RequestMapping(value = "/csd")
 public class CsdController
 {
     private static final String SOAP_CONTENT_TYPE = "application/soap+xml";
 
     // Name of group
-    private static final String FACILITY_TYPE_DISCRIMINATOR = "Health Facility";
+    private static final String FACILITY_DISCRIMINATOR = "Health Facility";
+
+    private static final String FACILITY_TYPE_DISCRIMINATOR = "Type";
+
+    private static final String FACILITY_STATUS_DISCRIMINATOR = "Status";
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -128,7 +130,7 @@
     // POST
     // -------------------------------------------------------------------------
 
-    @RequestMapping( value = "", method = RequestMethod.POST, consumes = MediaType.ALL_VALUE, produces = MediaType.ALL_VALUE )
+    @RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.ALL_VALUE, produces = MediaType.ALL_VALUE)
     public void careServicesRequest( HttpServletRequest request, HttpServletResponse response ) throws IOException, JAXBException
     {
         Object o = unmarshaller.unmarshal( request.getInputStream() );
@@ -235,7 +237,7 @@
 
             for ( OrganisationUnitGroup group : organisationUnit.getGroups() )
             {
-                if ( group.getName().equals( FACILITY_TYPE_DISCRIMINATOR ) )
+                if ( group.getName().equals( FACILITY_DISCRIMINATOR ) )
                 {
                     isFacility = true;
                     break;
@@ -283,8 +285,16 @@
                 facility.getContacts().add( contact );
             }
 
+            String facilityStatus = "Open";
+
             for ( OrganisationUnitGroup organisationUnitGroup : organisationUnit.getGroups() )
             {
+                if ( organisationUnitGroup.getGroupSet().getName().equals( FACILITY_STATUS_DISCRIMINATOR ) )
+                {
+                    facilityStatus = organisationUnitGroup.getName();
+                    continue;
+                }
+
                 if ( organisationUnitGroup.getCode() == null )
                 {
                     continue;
@@ -294,6 +304,7 @@
                 codedType.setCode( organisationUnitGroup.getCode() );
 
                 codedType.setCodingSchema( "Unknown" );
+
                 for ( AttributeValue attributeValue : organisationUnitGroup.getAttributeValues() )
                 {
                     if ( attributeValue.getAttribute().getName().equals( "code_system" ) )
@@ -314,25 +325,25 @@
             for ( DataSet dataSet : organisationUnit.getDataSets() )
             {
                 String oid = null;
-                
+
                 for ( AttributeValue attributeValue : dataSet.getAttributeValues() )
                 {
                     if ( attributeValue.getAttribute().getName().equals( "service_oid" ) )
                     {
-                        oid = attributeValue.getValue() ;
+                        oid = attributeValue.getValue();
                         break;
                     }
                 }
 
                 // skip if dataset doesn't have a service oid
-                if (oid == null)
+                if ( oid == null )
                 {
                     continue;
                 }
-                
+
                 Service service = new Service();
                 service.setOid( oid );
-    
+
                 service.getNames().add( new Name( new CommonName( dataSet.getDisplayName() ) ) );
 
                 organization.getServices().add( service );
@@ -359,15 +370,7 @@
             Record record = new Record();
             record.setCreated( organisationUnit.getCreated() );
             record.setUpdated( organisationUnit.getLastUpdated() );
-
-            if ( organisationUnit.isActive() )
-            {
-                record.setStatus( "Active" );
-            }
-            else
-            {
-                record.setStatus( "Inactive" );
-            }
+            record.setStatus( facilityStatus );
 
             facility.setRecord( record );