← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16404: Updated csd support:

 

------------------------------------------------------------
revno: 16404
committer: Bob Jolliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-08-13 16:52:44 +0100
message:
  Updated csd support:
  1.  introduced urn:x-dhis:xxxx to replace horrible oids
  2.  Let Ownership groupset be proxy for organisation
  3.  Improved datset proxy for service
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java
  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-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java	2014-05-13 08:33:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java	2014-08-13 15:52:44 +0000
@@ -340,6 +340,11 @@
     {
         this.displayName = displayName;
     }
+    
+    public String getUrn()
+    {
+        return "urn:x-dhis:" + getUid();
+    }
 
     // -------------------------------------------------------------------------
     // hashCode and equals

=== 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-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-ohie/src/main/java/org/hisp/dhis/web/ohie/csd/webapi/CsdController.java	2014-08-13 15:52:44 +0000
@@ -80,6 +80,7 @@
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import java.io.BufferedInputStream;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -88,21 +89,27 @@
 @RequestMapping(value = "/csd")
 public class CsdController
 {
+
     private static final String SOAP_CONTENT_TYPE = "application/soap+xml";
 
     // Name of group all facilities belong to
     private static final String FACILITY_DISCRIMINATOR_GROUP = "Health Facility";
-    
+
     // groupset for status codelist - open, closed, etc
     private static final String FACILITY_STATUS_GROUPSET = "Status";
-    
+
     // groupset for facility type codelist
     private static final String FACILITY_TYPE_GROUPSET = "Type";
 
+    // groupset for facility ownership (proxy for organisation)
+    private static final String FACILITY_OWNERSHIP_GROUPSET = "Facility Ownership";
+
+    // attribute on dataset (indicating proxy for service)
+    private static final String DATASET_SERVICE_ATTRIBUTE = "Service";
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
-
     @Autowired
     private OrganisationUnitService organisationUnitService;
 
@@ -114,7 +121,8 @@
     {
         try
         {
-            Class<?>[] classes = new Class<?>[]{
+            Class<?>[] classes = new Class<?>[]
+            {
                 Envelope.class
             };
 
@@ -123,8 +131,7 @@
 
             marshaller = jaxbContext.createMarshaller();
             unmarshaller = jaxbContext.createUnmarshaller();
-        }
-        catch ( JAXBException ex )
+        } catch ( JAXBException ex )
         {
             ex.printStackTrace();
         }
@@ -133,11 +140,10 @@
     // -------------------------------------------------------------------------
     // POST
     // -------------------------------------------------------------------------
-
     @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() );
+        Object o = unmarshaller.unmarshal( new BufferedInputStream( request.getInputStream() ) );
         Envelope env = (Envelope) o;
 
         validateRequest( env );
@@ -164,11 +170,9 @@
         marshaller.marshal( envelope, response.getOutputStream() );
     }
 
-
     // -------------------------------------------------------------------------
     // Helpers
     // -------------------------------------------------------------------------
-
     private void validateRequest( Envelope envelope )
     {
         try
@@ -178,8 +182,7 @@
             {
                 throw new MissingGetDirectoryModificationsRequestException();
             }
-        }
-        catch ( NullPointerException ex )
+        } catch ( NullPointerException ex )
         {
             throw new SoapException();
         }
@@ -190,8 +193,7 @@
             {
                 throw new MissingGetModificationsRequestException();
             }
-        }
-        catch ( NullPointerException ex )
+        } catch ( NullPointerException ex )
         {
             throw new SoapException();
         }
@@ -202,8 +204,7 @@
             {
                 throw new MissingLastModifiedException();
             }
-        }
-        catch ( NullPointerException ex )
+        } catch ( NullPointerException ex )
         {
             throw new SoapException();
         }
@@ -255,16 +256,9 @@
             }
 
             Facility facility = new Facility();
-            facility.setOid( "No oid, please provide facility_oid attribute value" );
 
-            for ( AttributeValue attributeValue : organisationUnit.getAttributeValues() )
-            {
-                if ( attributeValue.getAttribute().getName().equals( "facility_oid" ) )
-                {
-                    facility.setOid( attributeValue.getValue() );
-                    break;
-                }
-            }
+            // facility.setOid( organisationUnit.getUrn() );
+            facility.setOid( "urn:x-dhis:facility." + organisationUnit.getUid() );
 
             facility.getOtherID().add( new OtherID( organisationUnit.getUid(), "dhis2-uid" ) );
 
@@ -289,6 +283,7 @@
                 facility.getContacts().add( contact );
             }
 
+            // TODO: this needs to be added to domain model?
             String facilityStatus = "Open";
 
             for ( OrganisationUnitGroup organisationUnitGroup : organisationUnit.getGroups() )
@@ -298,16 +293,15 @@
                     continue;
                 }
 
-                if ( organisationUnitGroup.getGroupSet() != null &&
-                    FACILITY_STATUS_GROUPSET.equals( organisationUnitGroup.getGroupSet().getName() ) )
+                if ( organisationUnitGroup.getGroupSet() != null
+                    && FACILITY_STATUS_GROUPSET.equals( organisationUnitGroup.getGroupSet().getName() ) )
                 {
                     facilityStatus = organisationUnitGroup.getCode();
                     continue;
                 }
 
-                
-                if ( organisationUnitGroup.getGroupSet() != null &&
-                    FACILITY_TYPE_GROUPSET.equals( organisationUnitGroup.getGroupSet().getName() ) )
+                if ( organisationUnitGroup.getGroupSet() != null
+                    && FACILITY_TYPE_GROUPSET.equals( organisationUnitGroup.getGroupSet().getName() ) )
                 {
                     if ( organisationUnitGroup.getCode() == null )
                     {
@@ -332,36 +326,35 @@
 
                     facility.getCodedTypes().add( codedType );
                 }
-            }
-
-            Organization organization = new Organization( "No oid, please provide organisation_oid attribute value." );
-            facility.getOrganizations().add( organization );
-
-            for ( DataSet dataSet : organisationUnit.getDataSets() )
-            {
-                String oid = null;
-
-                for ( AttributeValue attributeValue : dataSet.getAttributeValues() )
+
+                if ( organisationUnitGroup.getGroupSet() != null
+                    && FACILITY_OWNERSHIP_GROUPSET.equals( organisationUnitGroup.getGroupSet().getName() ) )
                 {
-                    if ( attributeValue.getAttribute().getName().equals( "service_oid" ) )
+
+                    Organization organization = new Organization( "urn:x-dhis:ownership." + organisationUnitGroup.getUid() );
+                    facility.getOrganizations().add( organization );
+
+                    for ( DataSet dataSet : organisationUnit.getDataSets() )
                     {
-                        oid = attributeValue.getValue();
-                        break;
+
+                        for ( AttributeValue attributeValue : dataSet.getAttributeValues() )
+                        {
+                            if ( attributeValue.getAttribute().getName().equals( DATASET_SERVICE_ATTRIBUTE ) )
+                            {
+                                Service service = new Service();
+                                service.setOid( "urn:x-dhis:dataSet." + dataSet.getUid() );
+
+                                service.getNames().add( new Name( new CommonName( attributeValue.getValue() ) ) );
+
+                                organization.getServices().add( service );
+                                break;
+                            }
+                        }
+
                     }
-                }
-
-                // skip if dataset doesn't have a service oid
-                if ( oid == null )
-                {
-                    continue;
-                }
-
-                Service service = new Service();
-                service.setOid( oid );
-
-                service.getNames().add( new Name( new CommonName( dataSet.getDisplayName() ) ) );
-
-                organization.getServices().add( service );
+
+                }
+
             }
 
             if ( OrganisationUnit.FEATURETYPE_POINT.equals( organisationUnit.getFeatureType() ) )
@@ -376,8 +369,7 @@
                     geocode.setLatitude( coordinates.lat );
 
                     facility.setGeocode( geocode );
-                }
-                catch ( NumberFormatException ignored )
+                } catch ( NumberFormatException ignored )
                 {
                 }
             }
@@ -416,10 +408,6 @@
 
                     addressLines.get( attributeSplit[1] ).add( addressLine );
                 }
-                else if ( attributeValue.getAttribute().getName().equals( "organisation_oid" ) )
-                {
-                    organization.setOid( attributeValue.getValue() );
-                }
             }
 
             for ( String key : addressLines.keySet() )