dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24574
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12074: write support for attributes in person
------------------------------------------------------------
revno: 12074
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-09-13 12:42:46 +0200
message:
write support for attributes in person
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValue.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/AbstractPersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Person.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/patientattributevalue/PatientAttributeValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValue.java 2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValue.java 2013-09-13 10:42:46 +0000
@@ -117,6 +117,17 @@
return result;
}
+ @Override
+ public String toString()
+ {
+ return "PatientAttributeValue{" +
+ "patientAttribute=" + patientAttribute +
+ ", patient=" + patient +
+ ", value='" + value + '\'' +
+ ", patientAttributeOption=" + patientAttributeOption +
+ '}';
+ }
+
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/AbstractPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/AbstractPersonService.java 2013-09-13 09:21:02 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/AbstractPersonService.java 2013-09-13 10:42:46 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.dxf2.importsummary.ImportConflict;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientAttribute;
@@ -268,16 +269,17 @@
patient.setRegistrationDate( person.getDateOfRegistration() );
- Iterator<Identifier> iterator = person.getIdentifiers().iterator();
-
- // remove systemId from Person object
- while ( iterator.hasNext() )
+ for ( Identifier identifier : person.getIdentifiers() )
{
- Identifier identifier = iterator.next();
-
if ( identifier.getType() == null )
{
- iterator.remove();
+ PatientIdentifier patientIdentifier = new PatientIdentifier();
+ patientIdentifier.setIdentifier( identifier.getValue().trim() );
+ patientIdentifier.setIdentifierType( null );
+ patientIdentifier.setPatient( patient );
+
+ patient.getIdentifiers().add( patientIdentifier );
+
continue;
}
@@ -304,14 +306,89 @@
@Override
public Person savePerson( Person person )
{
+ checkForRequiredIdentifiers( person );
+ checkForRequiredAttributes( person );
+ addSystemIdentifier( person );
+
Patient patient = getPatient( person );
- addSystemIdentifier( patient );
-
patientService.savePatient( patient );
+ addAttributes( patient, person );
+ patientService.updatePatient( patient );
+
return getPerson( patient );
}
+ private ImportConflict checkForRequiredIdentifiers( Person person )
+ {
+ return null;
+ }
+
+ private ImportConflict checkForRequiredAttributes( Person person )
+ {
+ return null;
+ }
+
+ private void addAttributes( Patient patient, Person person )
+ {
+ for ( Attribute attribute : person.getAttributes() )
+ {
+ PatientAttribute patientAttribute = manager.get( PatientAttribute.class, attribute.getType() );
+
+ if ( patientAttribute != null )
+ {
+ PatientAttributeValue patientAttributeValue = new PatientAttributeValue();
+ patientAttributeValue.setPatient( patient );
+ patientAttributeValue.setValue( attribute.getValue() );
+ patientAttributeValue.setPatientAttribute( patientAttribute );
+
+ patientAttributeValueService.savePatientAttributeValue( patientAttributeValue );
+
+ patient.getAttributes().add( patientAttribute );
+ }
+ }
+ }
+
+ private void addSystemIdentifier( Person person )
+ {
+ Date birthDate = person.getDateOfBirth() != null ? person.getDateOfBirth().getDate() : null;
+ String gender = person.getGender() != null ? person.getGender().getValue() : null;
+
+ if ( birthDate == null || gender == null )
+ {
+ birthDate = new Date();
+ gender = "F";
+ }
+
+ Iterator<Identifier> iterator = person.getIdentifiers().iterator();
+
+ // remove any old system identifiers
+ while ( iterator.hasNext() )
+ {
+ Identifier identifier = iterator.next();
+
+ if ( identifier.getType() == null )
+ {
+ iterator.remove();
+ }
+ }
+
+ String systemId = PatientIdentifierGenerator.getNewIdentifier( birthDate, gender );
+
+ PatientIdentifier patientIdentifier = patientIdentifierService.get( null, systemId );
+
+ while ( patientIdentifier != null )
+ {
+ systemId = PatientIdentifierGenerator.getNewIdentifier( birthDate, gender );
+ patientIdentifier = patientIdentifierService.get( null, systemId );
+ }
+
+ Identifier identifier = new Identifier();
+ identifier.setValue( systemId );
+
+ person.getIdentifiers().add( identifier );
+ }
+
// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@@ -344,33 +421,4 @@
throw new IllegalArgumentException();
}
}
-
- private void addSystemIdentifier( Patient patient )
- {
- Date birthDate = patient.getBirthDate();
- String gender = patient.getGender();
-
- if ( birthDate == null || gender == null )
- {
- birthDate = new Date();
- gender = "F";
- }
-
- String systemId = PatientIdentifierGenerator.getNewIdentifier( birthDate, gender );
-
- PatientIdentifier patientIdentifier = patientIdentifierService.get( null, systemId );
-
- while ( patientIdentifier != null )
- {
- systemId = PatientIdentifierGenerator.getNewIdentifier( birthDate, gender );
- patientIdentifier = patientIdentifierService.get( null, systemId );
- }
-
- patientIdentifier = new PatientIdentifier();
- patientIdentifier.setPatient( patient );
- patientIdentifier.setIdentifier( systemId );
- patientIdentifier.setIdentifierType( null );
-
- patient.getIdentifiers().add( patientIdentifier );
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Person.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Person.java 2013-09-13 09:21:02 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Person.java 2013-09-13 10:42:46 +0000
@@ -210,6 +210,7 @@
Person person1 = (Person) o;
if ( deceased != person1.deceased ) return false;
+ if ( attributes != null ? !attributes.equals( person1.attributes ) : person1.attributes != null ) return false;
if ( contact != null ? !contact.equals( person1.contact ) : person1.contact != null ) return false;
if ( dateOfBirth != null ? !dateOfBirth.equals( person1.dateOfBirth ) : person1.dateOfBirth != null ) return false;
if ( dateOfDeath != null ? !dateOfDeath.equals( person1.dateOfDeath ) : person1.dateOfDeath != null ) return false;
@@ -237,11 +238,11 @@
result = 31 * result + (dateOfRegistration != null ? dateOfRegistration.hashCode() : 0);
result = 31 * result + (contact != null ? contact.hashCode() : 0);
result = 31 * result + (identifiers != null ? identifiers.hashCode() : 0);
+ result = 31 * result + (attributes != null ? attributes.hashCode() : 0);
return result;
}
- @Override
- public String toString()
+ @Override public String toString()
{
return "Person{" +
"person='" + person + '\'' +
@@ -254,6 +255,7 @@
", dateOfRegistration=" + dateOfRegistration +
", contact=" + contact +
", identifiers=" + identifiers +
+ ", attributes=" + attributes +
'}';
}
}