← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12162: added write support Person.relationships, added displayName property to attribute, identity, rela...

 

------------------------------------------------------------
revno: 12162
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-09-19 11:40:29 +0200
message:
  added write support Person.relationships, added displayName property to attribute, identity, relationship
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Attribute.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Identifier.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Relationship.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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java	2013-09-19 08:51:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java	2013-09-19 09:40:29 +0000
@@ -45,6 +45,8 @@
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.relationship.Relationship;
 import org.hisp.dhis.relationship.RelationshipService;
+import org.hisp.dhis.relationship.RelationshipType;
+import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
@@ -84,6 +86,9 @@
     private RelationshipService relationshipService;
 
     @Autowired
+    private RelationshipTypeService relationshipTypeService;
+
+    @Autowired
     private IdentifiableObjectManager manager;
 
     // -------------------------------------------------------------------------
@@ -222,6 +227,7 @@
         for ( Relationship relationshipPatient : relationshipsForPatient )
         {
             org.hisp.dhis.dxf2.events.person.Relationship relationship = new org.hisp.dhis.dxf2.events.person.Relationship();
+            relationship.setDisplayName( relationshipPatient.getRelationshipType().getDisplayName() );
             relationship.setPerson( relationshipPatient.getPatientA().getUid() );
             relationship.setType( relationshipPatient.getRelationshipType().getUid() );
 
@@ -233,6 +239,7 @@
             String identifierType = patientIdentifier.getIdentifierType() == null ? null : patientIdentifier.getIdentifierType().getUid();
 
             Identifier identifier = new Identifier( identifierType, patientIdentifier.getIdentifier() );
+            identifier.setDisplayName( patientIdentifier.getIdentifierType() != null ? patientIdentifier.getIdentifierType().getDisplayName() : null );
             person.getIdentifiers().add( identifier );
         }
 
@@ -241,6 +248,7 @@
         for ( PatientAttributeValue patientAttributeValue : patientAttributeValues )
         {
             Attribute attribute = new Attribute();
+            attribute.setDisplayName( patientAttributeValue.getPatientAttribute().getDisplayName() );
             attribute.setType( patientAttributeValue.getPatientAttribute().getUid() );
             attribute.setValue( patientAttributeValue.getValue() );
 
@@ -311,8 +319,8 @@
         importSummary.setDataValueCount( null );
 
         List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
-        importConflicts.addAll( checkForRequiredIdentifiers( person ) );
-        importConflicts.addAll( checkForRequiredAttributes( person ) );
+        importConflicts.addAll( checkIdentifiers( person ) );
+        importConflicts.addAll( checkAttributes( person ) );
 
         importSummary.setConflicts( importConflicts );
 
@@ -349,8 +357,9 @@
         importSummary.setDataValueCount( null );
 
         List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
-        importConflicts.addAll( checkForRequiredIdentifiers( person ) );
-        importConflicts.addAll( checkForRequiredAttributes( person ) );
+        importConflicts.addAll( checkRelationships( person ) );
+        importConflicts.addAll( checkIdentifiers( person ) );
+        importConflicts.addAll( checkAttributes( person ) );
 
         Patient patient = manager.get( Patient.class, person.getPerson() );
 
@@ -404,10 +413,12 @@
         patient.setBirthDate( dateOfBirth.getDate() );
 
         updateSystemIdentifier( person );
+        removeRelationships( patient );
         removeIdentifiers( patient );
         removeAttributeValues( patient );
         patientService.updatePatient( patient );
 
+        updateRelationships( person, patient );
         updateIdentifiers( person, patient );
         updateAttributeValues( person, patient );
         patientService.updatePatient( patient );
@@ -442,7 +453,7 @@
     // HELPERS
     // -------------------------------------------------------------------------
 
-    private List<ImportConflict> checkForRequiredIdentifiers( Person person )
+    private List<ImportConflict> checkIdentifiers( Person person )
     {
         List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
         Collection<PatientIdentifierType> patientIdentifierTypes = manager.getAll( PatientIdentifierType.class );
@@ -486,10 +497,21 @@
             }
         }
 
+        for ( Identifier identifier : person.getIdentifiers() )
+        {
+            PatientIdentifierType patientIdentifierType = manager.get( PatientIdentifierType.class, identifier.getType() );
+
+            if ( patientIdentifierType == null )
+            {
+                importConflicts.add(
+                    new ImportConflict( "Identifier.type", "Invalid type " + identifier.getType() ) );
+            }
+        }
+
         return importConflicts;
     }
 
-    private List<ImportConflict> checkForRequiredAttributes( Person person )
+    private List<ImportConflict> checkAttributes( Person person )
     {
         List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
         Collection<PatientAttribute> patientAttributes = manager.getAll( PatientAttribute.class );
@@ -510,13 +532,51 @@
                 if ( !cache.contains( patientAttribute.getUid() ) )
                 {
                     importConflicts.add(
-                        new ImportConflict( "Identifier.type", "Missing required attribute type " + patientAttribute.getUid() ) );
+                        new ImportConflict( "Attribute.type", "Missing required attribute type " + patientAttribute.getUid() ) );
                 }
             }
         }
 
-        return importConflicts;
-    }
+        for ( Attribute attribute : person.getAttributes() )
+        {
+            PatientAttribute patientAttribute = manager.get( PatientAttribute.class, attribute.getType() );
+
+            if ( patientAttribute == null )
+            {
+                importConflicts.add(
+                    new ImportConflict( "Attribute.type", "Invalid type " + attribute.getType() ) );
+            }
+        }
+
+        return importConflicts;
+    }
+
+    private List<ImportConflict> checkRelationships( Person person )
+    {
+        List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
+
+        for ( org.hisp.dhis.dxf2.events.person.Relationship relationship : person.getRelationships() )
+        {
+            RelationshipType relationshipType = manager.get( RelationshipType.class, relationship.getType() );
+
+            if ( relationshipType == null )
+            {
+                importConflicts.add(
+                    new ImportConflict( "Relationship.type", "Invalid type " + relationship.getType() ) );
+            }
+
+            Patient patient = manager.get( Patient.class, relationship.getPerson() );
+
+            if ( patient == null )
+            {
+                importConflicts.add(
+                    new ImportConflict( "Relationship.person", "Invalid person " + relationship.getPerson() ) );
+            }
+        }
+
+        return importConflicts;
+    }
+
 
     private void updateAttributeValues( Person person, Patient patient )
     {
@@ -629,6 +689,32 @@
         }
     }
 
+    private void updateRelationships( Person person, Patient patient )
+    {
+        for ( org.hisp.dhis.dxf2.events.person.Relationship relationship : person.getRelationships() )
+        {
+            Patient patientB = manager.get( Patient.class, relationship.getPerson() );
+            RelationshipType relationshipType = manager.get( RelationshipType.class, relationship.getType() );
+
+            Relationship relationshipPatient = new Relationship();
+            relationshipPatient.setPatientA( patient );
+            relationshipPatient.setPatientB( patientB );
+            relationshipPatient.setRelationshipType( relationshipType );
+
+            relationshipService.saveRelationship( relationshipPatient );
+        }
+    }
+
+    private void removeRelationships( Patient patient )
+    {
+        Collection<Relationship> relationshipsForPatient = relationshipService.getRelationshipsForPatient( patient );
+
+        for ( Relationship relationship : relationshipsForPatient )
+        {
+            relationshipService.deleteRelationship( relationship );
+        }
+    }
+
     private void removeIdentifiers( Patient patient )
     {
         for ( PatientIdentifier patientIdentifier : patient.getIdentifiers() )

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Attribute.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Attribute.java	2013-09-17 12:15:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Attribute.java	2013-09-19 09:40:29 +0000
@@ -39,6 +39,8 @@
 @JacksonXmlRootElement( localName = "attribute", namespace = DxfNamespaces.DXF_2_0 )
 public class Attribute
 {
+    private String displayName;
+
     private String type;
 
     private String value;
@@ -60,6 +62,18 @@
 
     @JsonProperty
     @JacksonXmlProperty( isAttribute = true )
+    public String getDisplayName()
+    {
+        return displayName;
+    }
+
+    public void setDisplayName( String name )
+    {
+        this.displayName = name;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( isAttribute = true )
     public String getType()
     {
         return type;
@@ -90,6 +104,7 @@
 
         Attribute attribute = (Attribute) o;
 
+        if ( displayName != null ? !displayName.equals( attribute.displayName ) : attribute.displayName != null ) return false;
         if ( type != null ? !type.equals( attribute.type ) : attribute.type != null ) return false;
         if ( value != null ? !value.equals( attribute.value ) : attribute.value != null ) return false;
 
@@ -99,15 +114,18 @@
     @Override
     public int hashCode()
     {
-        int result = type != null ? type.hashCode() : 0;
+        int result = displayName != null ? displayName.hashCode() : 0;
+        result = 31 * result + (type != null ? type.hashCode() : 0);
         result = 31 * result + (value != null ? value.hashCode() : 0);
         return result;
     }
 
-    @Override public String toString()
+    @Override
+    public String toString()
     {
         return "Attribute{" +
-            "type='" + type + '\'' +
+            "displayName='" + displayName + '\'' +
+            ", type='" + type + '\'' +
             ", value='" + value + '\'' +
             '}';
     }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Identifier.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Identifier.java	2013-09-17 12:15:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Identifier.java	2013-09-19 09:40:29 +0000
@@ -39,6 +39,8 @@
 @JacksonXmlRootElement( localName = "identifier", namespace = DxfNamespaces.DXF_2_0 )
 public class Identifier
 {
+    private String displayName;
+
     private String type;
 
     private String value;
@@ -60,6 +62,18 @@
 
     @JsonProperty
     @JacksonXmlProperty( isAttribute = true )
+    public String getDisplayName()
+    {
+        return displayName;
+    }
+
+    public void setDisplayName( String name )
+    {
+        this.displayName = name;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( isAttribute = true )
     public String getType()
     {
         return type;
@@ -90,6 +104,7 @@
 
         Identifier that = (Identifier) o;
 
+        if ( displayName != null ? !displayName.equals( that.displayName ) : that.displayName != null ) return false;
         if ( type != null ? !type.equals( that.type ) : that.type != null ) return false;
         if ( value != null ? !value.equals( that.value ) : that.value != null ) return false;
 
@@ -99,16 +114,17 @@
     @Override
     public int hashCode()
     {
-        int result = type != null ? type.hashCode() : 0;
+        int result = displayName != null ? displayName.hashCode() : 0;
+        result = 31 * result + (type != null ? type.hashCode() : 0);
         result = 31 * result + (value != null ? value.hashCode() : 0);
         return result;
     }
 
-    @Override
-    public String toString()
+    @Override public String toString()
     {
         return "Identifier{" +
-            "type='" + type + '\'' +
+            "displayName='" + displayName + '\'' +
+            ", type='" + type + '\'' +
             ", value='" + value + '\'' +
             '}';
     }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Relationship.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Relationship.java	2013-09-19 08:51:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/Relationship.java	2013-09-19 09:40:29 +0000
@@ -39,6 +39,8 @@
 @JacksonXmlRootElement( localName = "relationship", namespace = DxfNamespaces.DXF_2_0 )
 public class Relationship
 {
+    private String displayName;
+
     private String person;
 
     private String type;
@@ -49,6 +51,18 @@
 
     @JsonProperty
     @JacksonXmlProperty( isAttribute = true )
+    public String getDisplayName()
+    {
+        return displayName;
+    }
+
+    public void setDisplayName( String name )
+    {
+        this.displayName = name;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( isAttribute = true )
     public String getPerson()
     {
         return person;
@@ -79,6 +93,7 @@
 
         Relationship that = (Relationship) o;
 
+        if ( displayName != null ? !displayName.equals( that.displayName ) : that.displayName != null ) return false;
         if ( person != null ? !person.equals( that.person ) : that.person != null ) return false;
         if ( type != null ? !type.equals( that.type ) : that.type != null ) return false;
 
@@ -88,15 +103,18 @@
     @Override
     public int hashCode()
     {
-        int result = person != null ? person.hashCode() : 0;
+        int result = displayName != null ? displayName.hashCode() : 0;
+        result = 31 * result + (person != null ? person.hashCode() : 0);
         result = 31 * result + (type != null ? type.hashCode() : 0);
         return result;
     }
 
-    @Override public String toString()
+    @Override
+    public String toString()
     {
         return "Relationship{" +
-            "person='" + person + '\'' +
+            "displayName='" + displayName + '\'' +
+            ", person='" + person + '\'' +
             ", type='" + type + '\'' +
             '}';
     }