dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24622
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12103: moved dxf2.event.person to dxf2.person
------------------------------------------------------------
revno: 12103
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-09-16 15:13:14 +0200
message:
moved dxf2.event.person to dxf2.person
removed:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/
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/Attribute.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Contact.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirth.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirthType.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Gender.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Identifier.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/JacksonPersonService.java
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/PersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Persons.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks/
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks/ImportEventTask.java
added:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/ImportEventTask.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/AbstractPersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Attribute.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Contact.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/DateOfBirth.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/DateOfBirthType.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Gender.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Identifier.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/JacksonPersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Person.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/PersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Persons.java
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java
dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/event/ImportEventAction.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/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.java 2013-09-05 14:06:15 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.java 2013-09-16 13:13:14 +0000
@@ -185,16 +185,24 @@
}
else if ( program.getType() == Program.SINGLE_EVENT_WITH_REGISTRATION )
{
- return saveSingleEventWithRegistration( program, organisationUnit, event );
+ return saveEventWithRegistration( program, organisationUnit, event, importOptions );
}
else if ( program.getType() == Program.MULTIPLE_EVENTS_WITH_REGISTRATION )
{
- return saveMultipleEventsWithRegistration( program, organisationUnit, event );
+ return saveEventWithRegistration( program, organisationUnit, event, importOptions );
}
return new ImportSummary();
}
+ private ImportSummary saveEventWithRegistration( Program program, OrganisationUnit organisationUnit, Event event, ImportOptions importOptions )
+ {
+ ImportSummary importSummary = new ImportSummary();
+ importSummary.setStatus( ImportStatus.SUCCESS );
+
+ return importSummary;
+ }
+
private ImportSummary saveSingleEventWithoutRegistration( Program program, OrganisationUnit organisationUnit, Event event, ImportOptions importOptions )
{
try
@@ -222,7 +230,9 @@
if ( importOptions == null || !importOptions.isDryRun() )
{
- programStageInstance = saveEventDate( program, organisationUnit, eventDate,
+ ProgramInstance programInstance = programInstanceService.getProgramInstances( program ).iterator().next();
+
+ programStageInstance = saveEventDate( programInstance, organisationUnit, eventDate,
event.getCompleted(), event.getCoordinate(), storedBy );
importSummary.setReference( programStageInstance.getUid() );
@@ -299,11 +309,10 @@
return new ImportSummary();
}
- private ProgramStageInstance saveEventDate( Program program, OrganisationUnit organisationUnit, Date date, Boolean completed,
+ private ProgramStageInstance saveEventDate( ProgramInstance programInstance, OrganisationUnit organisationUnit, Date date, Boolean completed,
Coordinate coordinate, String storedBy )
{
- ProgramStage programStage = program.getProgramStages().iterator().next();
- ProgramInstance programInstance = programInstanceService.getProgramInstances( program ).iterator().next();
+ ProgramStage programStage = programInstance.getProgram().getProgramStageByStage( 1 );
ProgramStageInstance programStageInstance = new ProgramStageInstance();
programStageInstance.setProgramInstance( programInstance );
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/ImportEventTask.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/ImportEventTask.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/ImportEventTask.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,95 @@
+package org.hisp.dhis.dxf2.event;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.dxf2.event.EventService;
+import org.hisp.dhis.dxf2.metadata.ImportOptions;
+import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.user.User;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class ImportEventTask
+ implements Runnable
+{
+ private final InputStream inputStream;
+
+ private final EventService eventService;
+
+ private final ImportOptions importOptions;
+
+ private final TaskId taskId;
+
+ private final boolean jsonInput;
+
+ private final Authentication authentication;
+
+ public ImportEventTask( InputStream inputStream, EventService eventService, ImportOptions importOptions, TaskId taskId, boolean jsonInput )
+ {
+ this.inputStream = inputStream;
+ this.eventService = eventService;
+ this.importOptions = importOptions;
+ this.taskId = taskId;
+ this.jsonInput = jsonInput;
+ this.authentication = SecurityContextHolder.getContext().getAuthentication();
+ }
+
+ @Override
+ public void run()
+ {
+ SecurityContextHolder.getContext().setAuthentication( authentication );
+
+ if ( jsonInput )
+ {
+ try
+ {
+ eventService.saveEventsJson( inputStream, taskId, importOptions );
+ }
+ catch ( IOException ignored )
+ {
+ }
+ }
+ else
+ {
+ try
+ {
+ eventService.saveEventsXml( inputStream, taskId, importOptions );
+ }
+ catch ( IOException ignored )
+ {
+ }
+ }
+ }
+}
=== removed directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person'
=== removed 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-16 12:41:18 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/AbstractPersonService.java 1970-01-01 00:00:00 +0000
@@ -1,630 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.dxf2.importsummary.ImportConflict;
-import org.hisp.dhis.dxf2.importsummary.ImportStatus;
-import org.hisp.dhis.dxf2.importsummary.ImportSummary;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.patient.Patient;
-import org.hisp.dhis.patient.PatientAttribute;
-import org.hisp.dhis.patient.PatientIdentifier;
-import org.hisp.dhis.patient.PatientIdentifierService;
-import org.hisp.dhis.patient.PatientIdentifierType;
-import org.hisp.dhis.patient.PatientService;
-import org.hisp.dhis.patient.util.PatientIdentifierGenerator;
-import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
-import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
-import org.hisp.dhis.program.Program;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.Assert;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@Transactional
-public abstract class AbstractPersonService implements PersonService
-{
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- @Autowired
- private PatientService patientService;
-
- @Autowired
- private PatientIdentifierService patientIdentifierService;
-
- @Autowired
- private PatientAttributeValueService patientAttributeValueService;
-
- @Autowired
- private IdentifiableObjectManager manager;
-
- // -------------------------------------------------------------------------
- // Implementation
- // -------------------------------------------------------------------------
-
- // -------------------------------------------------------------------------
- // READ
- // -------------------------------------------------------------------------
-
- @Override
- public Persons getPersons()
- {
- List<Patient> patients = new ArrayList<Patient>( patientService.getAllPatients() );
- return getPersons( patients );
- }
-
- @Override
- public Persons getPersons( OrganisationUnit organisationUnit )
- {
- List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( organisationUnit ) );
- return getPersons( patients );
- }
-
- @Override
- public Persons getPersons( Gender gender )
- {
- List<Patient> patients = new ArrayList<Patient>( patientService.getPatiensByGender( gender.getValue() ) );
- return getPersons( patients );
- }
-
- @Override
- public Persons getPersons( Program program )
- {
- List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( program ) );
- return getPersons( patients );
- }
-
- @Override
- public Persons getPersons( Program program, Gender gender )
- {
- List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( program, gender.getValue() ) );
- return getPersons( patients );
- }
-
- @Override
- public Persons getPersons( OrganisationUnit organisationUnit, Program program )
- {
- List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( organisationUnit, program ) );
- return getPersons( patients );
- }
-
- @Override
- public Persons getPersons( OrganisationUnit organisationUnit, Gender gender )
- {
- List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( organisationUnit, gender.getValue() ) );
- return getPersons( patients );
- }
-
- @Override
- public Persons getPersons( OrganisationUnit organisationUnit, Program program, Gender gender )
- {
- List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( organisationUnit, program, gender.getValue() ) );
- return getPersons( patients );
- }
-
- @Override
- public Persons getPersons( Collection<Patient> patients )
- {
- Persons persons = new Persons();
-
- for ( Patient patient : patients )
- {
- persons.getPersons().add( getPerson( patient ) );
- }
-
- return persons;
- }
-
- @Override
- public Person getPerson( String uid )
- {
- return getPerson( patientService.getPatient( uid ) );
- }
-
- @Override
- public Person getPerson( Patient patient )
- {
- Person person = new Person();
- person.setPerson( patient.getUid() );
- person.setOrgUnit( patient.getOrganisationUnit().getUid() );
-
- person.setName( patient.getName() );
- person.setGender( Gender.fromString( patient.getGender() ) );
-
- person.setDeceased( patient.getIsDead() );
- person.setDateOfDeath( patient.getDeathDate() );
-
- Contact contact = new Contact();
- contact.setPhoneNumber( nullIfEmpty( patient.getPhoneNumber() ) );
-
- if ( contact.getPhoneNumber() != null )
- {
- person.setContact( contact );
- }
-
- DateOfBirth dateOfBirth;
-
- Character dobType = patient.getDobType();
-
- if ( dobType != null && patient.getBirthDate() != null )
- {
- if ( dobType.equals( Patient.DOB_TYPE_VERIFIED ) || dobType.equals( Patient.DOB_TYPE_DECLARED ) )
- {
- dateOfBirth = new DateOfBirth( patient.getBirthDate(),
- DateOfBirthType.fromString( String.valueOf( dobType ) ) );
- }
- else
- {
- // assume APPROXIMATE
- dateOfBirth = new DateOfBirth( patient.getIntegerValueOfAge() );
- }
-
- person.setDateOfBirth( dateOfBirth );
- }
-
- person.setDateOfRegistration( patient.getRegistrationDate() );
-
- for ( PatientIdentifier patientIdentifier : patient.getIdentifiers() )
- {
- String identifierType = patientIdentifier.getIdentifierType() == null ? null : patientIdentifier.getIdentifierType().getUid();
-
- Identifier identifier = new Identifier( identifierType, patientIdentifier.getIdentifier() );
- person.getIdentifiers().add( identifier );
- }
-
- for ( PatientAttribute patientAttribute : patient.getAttributes() )
- {
- PatientAttributeValue patientAttributeValue = patientAttributeValueService.getPatientAttributeValue( patient, patientAttribute );
-
- Attribute attribute = new Attribute();
- attribute.setType( patientAttribute.getUid() );
- attribute.setValue( patientAttributeValue.getValue() );
-
- person.getAttributes().add( attribute );
- }
-
- return person;
- }
-
- public Patient getPatient( Person person )
- {
- Assert.hasText( person.getOrgUnit() );
-
- Patient patient = new Patient();
- patient.setName( person.getName() );
- patient.setGender( person.getGender().getValue() );
-
- OrganisationUnit organisationUnit = manager.get( OrganisationUnit.class, person.getOrgUnit() );
- Assert.notNull( organisationUnit );
-
- patient.setOrganisationUnit( organisationUnit );
-
- DateOfBirth dateOfBirth = person.getDateOfBirth();
-
- if ( dateOfBirth != null )
- {
- if ( dateOfBirth.getDate() != null && (dateOfBirth.getType().equals( DateOfBirthType.DECLARED ) ||
- dateOfBirth.getType().equals( DateOfBirthType.VERIFIED )) )
- {
- char dobType = dateOfBirth.getType().getValue().charAt( 0 );
- patient.setDobType( dobType );
- patient.setBirthDate( dateOfBirth.getDate() );
- }
- else if ( dateOfBirth.getAge() != null && dateOfBirth.getType().equals( DateOfBirthType.APPROXIMATE ) )
- {
- char dobType = dateOfBirth.getType().getValue().charAt( 0 );
- patient.setDobType( dobType );
- patient.setBirthDateFromAge( dateOfBirth.getAge(), dobType );
- }
- }
-
- if ( person.getContact() != null && person.getContact().getPhoneNumber() != null )
- {
- patient.setPhoneNumber( person.getContact().getPhoneNumber() );
- }
-
- patient.setIsDead( person.isDeceased() );
-
- if ( person.isDeceased() && person.getDateOfDeath() != null )
- {
- patient.setDeathDate( person.getDateOfDeath() );
- }
-
- patient.setRegistrationDate( person.getDateOfRegistration() );
- updateIdentifiers( person, patient );
-
- return patient;
- }
-
- // -------------------------------------------------------------------------
- // CREATE
- // -------------------------------------------------------------------------
-
- @Override
- public ImportSummary savePerson( Person person )
- {
- ImportSummary importSummary = new ImportSummary();
- importSummary.setDataValueCount( null );
-
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
- importConflicts.addAll( checkForRequiredIdentifiers( person ) );
- importConflicts.addAll( checkForRequiredAttributes( person ) );
-
- importSummary.setConflicts( importConflicts );
-
- if ( !importConflicts.isEmpty() )
- {
- importSummary.setStatus( ImportStatus.ERROR );
- importSummary.getImportCount().incrementIgnored();
- return importSummary;
- }
-
- updateSystemIdentifier( person );
-
- Patient patient = getPatient( person );
- patientService.savePatient( patient );
-
- updateAttributeValues( person, patient );
- patientService.updatePatient( patient );
-
- importSummary.setStatus( ImportStatus.SUCCESS );
- importSummary.setReference( patient.getUid() );
- importSummary.getImportCount().incrementImported();
-
- return importSummary;
- }
-
- // -------------------------------------------------------------------------
- // UPDATE
- // -------------------------------------------------------------------------
-
- @Override
- public ImportSummary updatePerson( Person person )
- {
- ImportSummary importSummary = new ImportSummary();
- importSummary.setDataValueCount( null );
-
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
- importConflicts.addAll( checkForRequiredIdentifiers( person ) );
- importConflicts.addAll( checkForRequiredAttributes( person ) );
-
- Patient patient = manager.get( Patient.class, person.getPerson() );
-
- if ( patient == null )
- {
- importConflicts.add(
- new ImportConflict( "Person", "person " + person.getPerson() + " does not point to valid person" ) );
- }
-
- OrganisationUnit organisationUnit = manager.get( OrganisationUnit.class, person.getOrgUnit() );
-
- if ( organisationUnit == null )
- {
- importConflicts.add(
- new ImportConflict( "OrganisationUnit", "orgUnit " + person.getOrgUnit() + " does not point to valid organisation unit" ) );
- }
-
- DateOfBirth dateOfBirth = person.getDateOfBirth();
-
- if ( dateOfBirth == null )
- {
- importConflicts.add(
- new ImportConflict( "DateOfBirth", "dateOfBirth is not present" ) );
- }
-
- importSummary.setConflicts( importConflicts );
-
- if ( !importConflicts.isEmpty() )
- {
- importSummary.setStatus( ImportStatus.ERROR );
- importSummary.getImportCount().incrementIgnored();
- return importSummary;
- }
-
- patient.setName( person.getName() );
- patient.setGender( person.getGender().getValue() );
- patient.setIsDead( person.isDeceased() );
- patient.setDeathDate( person.getDateOfDeath() );
- // TODO should we allow update of this property?
- patient.setRegistrationDate( person.getDateOfRegistration() );
-
- String phoneNumber = person.getContact() != null ? person.getContact().getPhoneNumber() : null;
- patient.setPhoneNumber( phoneNumber );
-
- if ( DateOfBirthType.APPROXIMATE.equals( dateOfBirth.getType() ) )
- {
- dateOfBirth = new DateOfBirth( dateOfBirth.getAge() );
- }
-
- patient.setDobType( dateOfBirth.getType().getValue().charAt( 0 ) );
- patient.setBirthDate( dateOfBirth.getDate() );
-
- updateSystemIdentifier( person );
- removeIdentifiers( patient );
- removeAttributeValues( patient );
- patientService.updatePatient( patient );
-
- updateIdentifiers( person, patient );
- updateAttributeValues( person, patient );
- patientService.updatePatient( patient );
-
- importSummary.setStatus( ImportStatus.SUCCESS );
- importSummary.setReference( patient.getUid() );
- importSummary.getImportCount().incrementImported();
-
- return importSummary;
- }
-
- // -------------------------------------------------------------------------
- // DELETE
- // -------------------------------------------------------------------------
-
- @Override
- public void deletePerson( Person person )
- {
- Patient patient = patientService.getPatient( person.getPerson() );
-
- if ( patient != null )
- {
- patientService.deletePatient( patient );
- }
- else
- {
- throw new IllegalArgumentException();
- }
- }
-
- // -------------------------------------------------------------------------
- // HELPERS
- // -------------------------------------------------------------------------
-
- private List<ImportConflict> checkForRequiredIdentifiers( Person person )
- {
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
- Collection<PatientIdentifierType> patientIdentifierTypes = manager.getAll( PatientIdentifierType.class );
- Map<String, String> cacheMap = new HashMap<String, String>();
- Patient patient = manager.get( Patient.class, person.getPerson() );
-
- for ( Identifier identifier : person.getIdentifiers() )
- {
- if ( identifier.getValue() != null )
- {
- cacheMap.put( identifier.getType(), identifier.getValue() );
- }
- }
-
- for ( PatientIdentifierType patientIdentifierType : patientIdentifierTypes )
- {
- if ( patientIdentifierType.isMandatory() )
- {
- if ( !cacheMap.keySet().contains( patientIdentifierType.getUid() ) )
- {
- importConflicts.add(
- new ImportConflict( "Identifier.type", "Missing required identifier type " + patientIdentifierType.getUid() ) );
- }
- }
-
- List<PatientIdentifier> patientIdentifiers = new ArrayList<PatientIdentifier>( patientIdentifierService.getAll(
- patientIdentifierType, cacheMap.get( patientIdentifierType.getUid() ) ) );
-
- if ( !patientIdentifiers.isEmpty() )
- {
- // if .size() > 1, there is something wrong with the db.. but we for-loop for now
- for ( PatientIdentifier patientIdentifier : patientIdentifiers )
- {
- if ( !patientIdentifier.getPatient().equals( patient ) )
- {
- importConflicts.add(
- new ImportConflict( "Identifier.value", "Value already exists for patient " + patientIdentifier.getPatient().getUid()
- + " with identifier type " + patientIdentifierType.getUid() ) );
- }
- }
- }
- }
-
- return importConflicts;
- }
-
- private List<ImportConflict> checkForRequiredAttributes( Person person )
- {
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
- Collection<PatientAttribute> patientAttributes = manager.getAll( PatientAttribute.class );
- Set<String> cache = new HashSet<String>();
-
- for ( Identifier identifier : person.getIdentifiers() )
- {
- if ( identifier.getValue() != null )
- {
- cache.add( identifier.getType() );
- }
- }
-
- for ( PatientAttribute patientAttribute : patientAttributes )
- {
- if ( patientAttribute.isMandatory() )
- {
- if ( !cache.contains( patientAttribute.getUid() ) )
- {
- importConflicts.add(
- new ImportConflict( "Identifier.type", "Missing required attribute type " + patientAttribute.getUid() ) );
- }
- }
- }
-
- return importConflicts;
- }
-
- private void updateAttributeValues( Person person, Patient patient )
- {
- 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 updateSystemIdentifier( 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();
- }
- }
-
- Identifier identifier = generateSystemIdentifier( birthDate, gender );
-
- if ( person.getPerson() != null )
- {
- identifier = generateSystemIdentifier( birthDate, gender );
- Patient patient = manager.get( Patient.class, person.getPerson() );
-
- for ( PatientIdentifier patientIdentifier : patient.getIdentifiers() )
- {
- if ( patientIdentifier.getIdentifierType() == null && patientIdentifier.getIdentifier() != null )
- {
- identifier = new Identifier( patientIdentifier.getIdentifier() );
- break;
- }
- }
- }
-
- person.getIdentifiers().add( identifier );
- }
-
- private Identifier generateSystemIdentifier( Date birthDate, String gender )
- {
- 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 );
-
- return identifier;
- }
-
- // add identifiers from person => patient
- private void updateIdentifiers( Person person, Patient patient )
- {
- for ( Identifier identifier : person.getIdentifiers() )
- {
- if ( identifier.getType() == null )
- {
- PatientIdentifier patientIdentifier = new PatientIdentifier();
- patientIdentifier.setIdentifier( identifier.getValue().trim() );
- patientIdentifier.setIdentifierType( null );
- patientIdentifier.setPatient( patient );
-
- patient.getIdentifiers().add( patientIdentifier );
-
- continue;
- }
-
- PatientIdentifierType type = manager.get( PatientIdentifierType.class, identifier.getType() );
-
- if ( type != null && nullIfEmpty( identifier.getValue() ) != null )
- {
- PatientIdentifier patientIdentifier = new PatientIdentifier();
- patientIdentifier.setIdentifier( identifier.getValue().trim() );
- patientIdentifier.setIdentifierType( type );
- patientIdentifier.setPatient( patient );
-
- patient.getIdentifiers().add( patientIdentifier );
- }
- }
- }
-
- private void removeIdentifiers( Patient patient )
- {
- for ( PatientIdentifier patientIdentifier : patient.getIdentifiers() )
- {
- patientIdentifierService.deletePatientIdentifier( patientIdentifier );
- }
-
- patient.setIdentifiers( new HashSet<PatientIdentifier>() );
- patientService.updatePatient( patient );
- }
-
- private void removeAttributeValues( Patient patient )
- {
- patientAttributeValueService.deletePatientAttributeValue( patient );
- patient.setAttributes( new HashSet<PatientAttribute>() );
- patientService.updatePatient( patient );
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Attribute.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Attribute.java 2013-09-13 09:21:02 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Attribute.java 1970-01-01 00:00:00 +0000
@@ -1,114 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "attribute", namespace = DxfNamespaces.DXF_2_0 )
-public class Attribute
-{
- private String type;
-
- private String value;
-
- public Attribute()
- {
- }
-
- public Attribute( String value )
- {
- this.value = value;
- }
-
- public Attribute( String type, String value )
- {
- this.type = type;
- this.value = value;
- }
-
- @JsonProperty
- @JacksonXmlProperty( isAttribute = true )
- public String getType()
- {
- return type;
- }
-
- public void setType( String type )
- {
- this.type = type;
- }
-
- @JsonProperty
- @JacksonXmlProperty( isAttribute = true )
- public String getValue()
- {
- return value;
- }
-
- public void setValue( String value )
- {
- this.value = value;
- }
-
- @Override
- public boolean equals( Object o )
- {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- Attribute attribute = (Attribute) o;
-
- if ( type != null ? !type.equals( attribute.type ) : attribute.type != null ) return false;
- if ( value != null ? !value.equals( attribute.value ) : attribute.value != null ) return false;
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result = type != null ? type.hashCode() : 0;
- result = 31 * result + (value != null ? value.hashCode() : 0);
- return result;
- }
-
- @Override public String toString()
- {
- return "Attribute{" +
- "type='" + type + '\'' +
- ", value='" + value + '\'' +
- '}';
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Contact.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Contact.java 2013-09-12 11:20:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Contact.java 1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "contact", namespace = DxfNamespaces.DXF_2_0 )
-public class Contact
-{
- private String phoneNumber;
-
- public Contact()
- {
- }
-
- @JsonProperty( required = true )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public String getPhoneNumber()
- {
- return phoneNumber;
- }
-
- public void setPhoneNumber( String phoneNumber )
- {
- this.phoneNumber = phoneNumber;
- }
-
- @Override
- public boolean equals( Object o )
- {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- Contact contact = (Contact) o;
-
- if ( phoneNumber != null ? !phoneNumber.equals( contact.phoneNumber ) : contact.phoneNumber != null ) return false;
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- return phoneNumber != null ? phoneNumber.hashCode() : 0;
- }
-
- @Override
- public String toString()
- {
- return "Contact{" +
- "phoneNumber='" + phoneNumber + '\'' +
- '}';
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirth.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirth.java 2013-09-16 10:10:25 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirth.java 1970-01-01 00:00:00 +0000
@@ -1,132 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.patient.Patient;
-
-import java.util.Date;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "dateOfBirth", namespace = DxfNamespaces.DXF_2_0 )
-public class DateOfBirth
-{
- private Date date;
-
- private DateOfBirthType type;
-
- private Integer age;
-
- public DateOfBirth()
- {
- this.type = DateOfBirthType.APPROXIMATE;
- this.age = 0;
- }
-
- public DateOfBirth( Date date )
- {
- this.type = DateOfBirthType.VERIFIED;
- this.age = Patient.getIntegerValueOfAge( date );
- this.date = date;
- }
-
- public DateOfBirth( Date date, DateOfBirthType type )
- {
- this.type = type;
- this.age = Patient.getIntegerValueOfAge( date );
- this.date = date;
- }
-
- public DateOfBirth( Integer age )
- {
- this.type = DateOfBirthType.APPROXIMATE;
- this.age = age;
- this.date = Patient.getBirthFromAge( age, Patient.AGE_TYPE_YEAR );
- }
-
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
- public Date getDate()
- {
- return date;
- }
-
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
- public DateOfBirthType getType()
- {
- return type;
- }
-
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
- public Integer getAge()
- {
- return age;
- }
-
- @Override
- public boolean equals( Object o )
- {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- DateOfBirth that = (DateOfBirth) o;
-
- if ( age != null ? !age.equals( that.age ) : that.age != null ) return false;
- if ( date != null ? !date.equals( that.date ) : that.date != null ) return false;
- if ( type != that.type ) return false;
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result = date != null ? date.hashCode() : 0;
- result = 31 * result + (type != null ? type.hashCode() : 0);
- result = 31 * result + (age != null ? age.hashCode() : 0);
- return result;
- }
-
- @Override
- public String toString()
- {
- return "DateOfBirth{" +
- "date=" + date +
- ", type=" + type +
- ", age=" + age +
- '}';
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirthType.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirthType.java 2013-09-10 14:11:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirthType.java 1970-01-01 00:00:00 +0000
@@ -1,64 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public enum DateOfBirthType
-{
- VERIFIED( "V" ),
- DECLARED( "D" ),
- APPROXIMATE( "A" );
-
- private final String value;
-
- private DateOfBirthType( String value )
- {
- this.value = value;
- }
-
- public String getValue()
- {
- return value;
- }
-
- public static DateOfBirthType fromString( String text )
- {
- for ( DateOfBirthType dateOfBirthType : DateOfBirthType.values() )
- {
- if ( text.equals( dateOfBirthType.getValue() ) )
- {
- return dateOfBirthType;
- }
- }
-
- throw new IllegalArgumentException();
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Gender.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Gender.java 2013-09-10 14:11:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Gender.java 1970-01-01 00:00:00 +0000
@@ -1,66 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "gender", namespace = DxfNamespaces.DXF_2_0 )
-public enum Gender
-{
- MALE( "M" ), FEMALE( "F" ), TRANSGENDER( "T" );
-
- private final String value;
-
- private Gender( String value )
- {
- this.value = value;
- }
-
- public String getValue()
- {
- return value;
- }
-
- public static Gender fromString( String text )
- {
- for ( Gender gender : Gender.values() )
- {
- if ( text.equals( gender.getValue() ) )
- {
- return gender;
- }
- }
-
- throw new IllegalArgumentException();
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Identifier.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Identifier.java 2013-09-12 11:20:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Identifier.java 1970-01-01 00:00:00 +0000
@@ -1,115 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "identifier", namespace = DxfNamespaces.DXF_2_0 )
-public class Identifier
-{
- private String type;
-
- private String value;
-
- public Identifier()
- {
- }
-
- public Identifier( String value )
- {
- this.value = value;
- }
-
- public Identifier( String type, String value )
- {
- this.type = type;
- this.value = value;
- }
-
- @JsonProperty
- @JacksonXmlProperty( isAttribute = true )
- public String getType()
- {
- return type;
- }
-
- public void setType( String type )
- {
- this.type = type;
- }
-
- @JsonProperty
- @JacksonXmlProperty( isAttribute = true )
- public String getValue()
- {
- return value;
- }
-
- public void setValue( String value )
- {
- this.value = value;
- }
-
- @Override
- public boolean equals( Object o )
- {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- Identifier that = (Identifier) o;
-
- if ( type != null ? !type.equals( that.type ) : that.type != null ) return false;
- if ( value != null ? !value.equals( that.value ) : that.value != null ) return false;
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result = type != null ? type.hashCode() : 0;
- result = 31 * result + (value != null ? value.hashCode() : 0);
- return result;
- }
-
- @Override
- public String toString()
- {
- return "Identifier{" +
- "type='" + type + '\'' +
- ", value='" + value + '\'' +
- '}';
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/JacksonPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/JacksonPersonService.java 2013-09-16 07:42:02 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/JacksonPersonService.java 1970-01-01 00:00:00 +0000
@@ -1,170 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.xml.XmlMapper;
-import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
-import org.hisp.dhis.dxf2.importsummary.ImportSummary;
-import org.hisp.dhis.system.notification.Notifier;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.StreamUtils;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class JacksonPersonService extends AbstractPersonService
-{
- @Autowired
- private Notifier notifier;
-
- // -------------------------------------------------------------------------
- // Implementation
- // -------------------------------------------------------------------------
-
- private static ObjectMapper xmlMapper = new XmlMapper();
- private static ObjectMapper jsonMapper = new ObjectMapper();
-
- @SuppressWarnings( "unchecked" )
- private static <T> T fromXml( InputStream inputStream, Class<?> clazz ) throws IOException
- {
- return (T) xmlMapper.readValue( inputStream, clazz );
- }
-
- @SuppressWarnings( "unchecked" )
- private static <T> T fromXml( String input, Class<?> clazz ) throws IOException
- {
- return (T) xmlMapper.readValue( input, clazz );
- }
-
- @SuppressWarnings( "unchecked" )
- private static <T> T fromJson( InputStream inputStream, Class<?> clazz ) throws IOException
- {
- return (T) jsonMapper.readValue( inputStream, clazz );
- }
-
- @SuppressWarnings( "unchecked" )
- private static <T> T fromJson( String input, Class<?> clazz ) throws IOException
- {
- return (T) jsonMapper.readValue( input, clazz );
- }
-
- static
- {
- xmlMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true );
- xmlMapper.configure( DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true );
- xmlMapper.configure( DeserializationFeature.WRAP_EXCEPTIONS, true );
- jsonMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true );
- jsonMapper.configure( DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true );
- jsonMapper.configure( DeserializationFeature.WRAP_EXCEPTIONS, true );
- }
-
- // -------------------------------------------------------------------------
- // CREATE
- // -------------------------------------------------------------------------
-
- @Override
- public ImportSummaries savePersonXml( InputStream inputStream ) throws IOException
- {
- ImportSummaries importSummaries = new ImportSummaries();
- String input = StreamUtils.copyToString( inputStream, Charset.forName( "UTF-8" ) );
-
- try
- {
- Persons persons = fromXml( input, Persons.class );
-
- for ( Person person : persons.getPersons() )
- {
- person.setPerson( null );
- importSummaries.addImportSummary( savePerson( person ) );
- }
- }
- catch ( Exception ex )
- {
- Person person = fromXml( input, Person.class );
- person.setPerson( null );
- importSummaries.addImportSummary( savePerson( person ) );
- }
-
- return importSummaries;
- }
-
- @Override
- public ImportSummaries savePersonJson( InputStream inputStream ) throws IOException
- {
- ImportSummaries importSummaries = new ImportSummaries();
- String input = StreamUtils.copyToString( inputStream, Charset.forName( "UTF-8" ) );
-
- try
- {
- Persons persons = fromJson( input, Persons.class );
-
- for ( Person person : persons.getPersons() )
- {
- person.setPerson( null );
- importSummaries.addImportSummary( savePerson( person ) );
- }
- }
- catch ( Exception ex )
- {
- Person person = fromJson( input, Person.class );
- person.setPerson( null );
- importSummaries.addImportSummary( savePerson( person ) );
- }
-
- return importSummaries;
- }
-
- // -------------------------------------------------------------------------
- // UPDATE
- // -------------------------------------------------------------------------
-
- @Override
- public ImportSummary updatePersonXml( String id, InputStream inputStream ) throws IOException
- {
- Person person = fromXml( inputStream, Person.class );
- person.setPerson( id );
-
- return updatePerson( person );
- }
-
- @Override
- public ImportSummary updatePersonJson( String id, InputStream inputStream ) throws IOException
- {
- Person person = fromJson( inputStream, Person.class );
- person.setPerson( id );
-
- return updatePerson( person );
- }
-}
=== removed 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 10:42:46 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Person.java 1970-01-01 00:00:00 +0000
@@ -1,261 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement(localName = "person", namespace = DxfNamespaces.DXF_2_0)
-public class Person
-{
- private String person;
-
- private String orgUnit;
-
- private String name;
-
- private Gender gender;
-
- private DateOfBirth dateOfBirth;
-
- private boolean deceased;
-
- private Date dateOfDeath;
-
- private Date dateOfRegistration = new Date();
-
- private Contact contact;
-
- private List<Identifier> identifiers = new ArrayList<Identifier>();
-
- private List<Attribute> attributes = new ArrayList<Attribute>();
-
- public Person()
- {
- }
-
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
- public String getPerson()
- {
- return person;
- }
-
- public void setPerson( String person )
- {
- this.person = person;
- }
-
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
- public String getOrgUnit()
- {
- return orgUnit;
- }
-
- public void setOrgUnit( String orgUnit )
- {
- this.orgUnit = orgUnit;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public String getName()
- {
- return name;
- }
-
- public void setName( String name )
- {
- this.name = name;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public Gender getGender()
- {
- return gender;
- }
-
- public void setGender( Gender gender )
- {
- this.gender = gender;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public DateOfBirth getDateOfBirth()
- {
- return dateOfBirth;
- }
-
- public void setDateOfBirth( DateOfBirth dateOfBirth )
- {
- this.dateOfBirth = dateOfBirth;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public boolean isDeceased()
- {
- return deceased;
- }
-
- public void setDeceased( boolean deceased )
- {
- this.deceased = deceased;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public Date getDateOfDeath()
- {
- return dateOfDeath;
- }
-
- public void setDateOfDeath( Date dateOfDeath )
- {
- this.dateOfDeath = dateOfDeath;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public Date getDateOfRegistration()
- {
- return dateOfRegistration;
- }
-
- public void setDateOfRegistration( Date dateOfRegistration )
- {
- this.dateOfRegistration = dateOfRegistration;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public Contact getContact()
- {
- return contact;
- }
-
- public void setContact( Contact contact )
- {
- this.contact = contact;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public List<Identifier> getIdentifiers()
- {
- return identifiers;
- }
-
- public void setIdentifiers( List<Identifier> identifiers )
- {
- this.identifiers = identifiers;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public List<Attribute> getAttributes()
- {
- return attributes;
- }
-
- public void setAttributes( List<Attribute> attributes )
- {
- this.attributes = attributes;
- }
-
- @Override
- public boolean equals( Object o )
- {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- 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;
- if ( dateOfRegistration != null ? !dateOfRegistration.equals( person1.dateOfRegistration ) : person1.dateOfRegistration != null )
- return false;
- if ( gender != person1.gender ) return false;
- if ( identifiers != null ? !identifiers.equals( person1.identifiers ) : person1.identifiers != null ) return false;
- if ( name != null ? !name.equals( person1.name ) : person1.name != null ) return false;
- if ( orgUnit != null ? !orgUnit.equals( person1.orgUnit ) : person1.orgUnit != null ) return false;
- if ( person != null ? !person.equals( person1.person ) : person1.person != null ) return false;
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result = person != null ? person.hashCode() : 0;
- result = 31 * result + (orgUnit != null ? orgUnit.hashCode() : 0);
- result = 31 * result + (name != null ? name.hashCode() : 0);
- result = 31 * result + (gender != null ? gender.hashCode() : 0);
- result = 31 * result + (dateOfBirth != null ? dateOfBirth.hashCode() : 0);
- result = 31 * result + (deceased ? 1 : 0);
- result = 31 * result + (dateOfDeath != null ? dateOfDeath.hashCode() : 0);
- 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()
- {
- return "Person{" +
- "person='" + person + '\'' +
- ", orgUnit='" + orgUnit + '\'' +
- ", name='" + name + '\'' +
- ", gender=" + gender +
- ", dateOfBirth=" + dateOfBirth +
- ", deceased=" + deceased +
- ", dateOfDeath=" + dateOfDeath +
- ", dateOfRegistration=" + dateOfRegistration +
- ", contact=" + contact +
- ", identifiers=" + identifiers +
- ", attributes=" + attributes +
- '}';
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/PersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/PersonService.java 2013-09-13 13:06:54 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/PersonService.java 1970-01-01 00:00:00 +0000
@@ -1,97 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
-import org.hisp.dhis.dxf2.importsummary.ImportSummary;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.patient.Patient;
-import org.hisp.dhis.program.Program;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface PersonService
-{
- // -------------------------------------------------------------------------
- // READ
- // -------------------------------------------------------------------------
-
- Persons getPersons();
-
- Persons getPersons( OrganisationUnit organisationUnit );
-
- Persons getPersons( Gender gender );
-
- Persons getPersons( Program program );
-
- Persons getPersons( Program program, Gender gender );
-
- Persons getPersons( OrganisationUnit organisationUnit, Program program );
-
- Persons getPersons( OrganisationUnit organisationUnit, Gender gender );
-
- Persons getPersons( OrganisationUnit organisationUnit, Program program, Gender gender );
-
- Persons getPersons( Collection<Patient> patients );
-
- Person getPerson( String uid );
-
- Person getPerson( Patient patient );
-
- // -------------------------------------------------------------------------
- // CREATE
- // -------------------------------------------------------------------------
-
- ImportSummaries savePersonXml( InputStream inputStream ) throws IOException;
-
- ImportSummaries savePersonJson( InputStream inputStream ) throws IOException;
-
- ImportSummary savePerson( Person person );
-
- // -------------------------------------------------------------------------
- // UPDATE
- // -------------------------------------------------------------------------
-
- ImportSummary updatePersonXml( String id, InputStream inputStream ) throws IOException;
-
- ImportSummary updatePersonJson( String id, InputStream inputStream ) throws IOException;
-
- ImportSummary updatePerson( Person person );
-
- // -------------------------------------------------------------------------
- // DELETE
- // -------------------------------------------------------------------------
-
- void deletePerson( Person person );
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Persons.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Persons.java 2013-09-10 14:11:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Persons.java 1970-01-01 00:00:00 +0000
@@ -1,72 +0,0 @@
-package org.hisp.dhis.dxf2.event.person;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "persons", namespace = DxfNamespaces.DXF_2_0 )
-public class Persons
-{
- private List<Person> persons = new ArrayList<Person>();
-
- public Persons()
- {
- }
-
- @JsonProperty( "personList" )
- @JacksonXmlElementWrapper( localName = "personList", namespace = DxfNamespaces.DXF_2_0 )
- @JacksonXmlProperty( localName = "person", namespace = DxfNamespaces.DXF_2_0 )
- public List<Person> getPersons()
- {
- return persons;
- }
-
- public void setPersons( List<Person> persons )
- {
- this.persons = persons;
- }
-
- @Override
- public String toString()
- {
- return "Persons{" +
- "persons=" + persons +
- '}';
- }
-}
=== removed directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks'
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks/ImportEventTask.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks/ImportEventTask.java 2013-09-04 12:31:29 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks/ImportEventTask.java 1970-01-01 00:00:00 +0000
@@ -1,95 +0,0 @@
-package org.hisp.dhis.dxf2.event.tasks;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.dxf2.event.EventService;
-import org.hisp.dhis.dxf2.metadata.ImportOptions;
-import org.hisp.dhis.scheduling.TaskId;
-import org.hisp.dhis.user.User;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class ImportEventTask
- implements Runnable
-{
- private final InputStream inputStream;
-
- private final EventService eventService;
-
- private final ImportOptions importOptions;
-
- private final TaskId taskId;
-
- private final boolean jsonInput;
-
- private final Authentication authentication;
-
- public ImportEventTask( InputStream inputStream, EventService eventService, ImportOptions importOptions, TaskId taskId, boolean jsonInput )
- {
- this.inputStream = inputStream;
- this.eventService = eventService;
- this.importOptions = importOptions;
- this.taskId = taskId;
- this.jsonInput = jsonInput;
- this.authentication = SecurityContextHolder.getContext().getAuthentication();
- }
-
- @Override
- public void run()
- {
- SecurityContextHolder.getContext().setAuthentication( authentication );
-
- if ( jsonInput )
- {
- try
- {
- eventService.saveEventsJson( inputStream, taskId, importOptions );
- }
- catch ( IOException ignored )
- {
- }
- }
- else
- {
- try
- {
- eventService.saveEventsXml( inputStream, taskId, importOptions );
- }
- catch ( IOException ignored )
- {
- }
- }
- }
-}
=== added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person'
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/AbstractPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/AbstractPersonService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/AbstractPersonService.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,630 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.dxf2.importsummary.ImportConflict;
+import org.hisp.dhis.dxf2.importsummary.ImportStatus;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientIdentifier;
+import org.hisp.dhis.patient.PatientIdentifierService;
+import org.hisp.dhis.patient.PatientIdentifierType;
+import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patient.util.PatientIdentifierGenerator;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
+import org.hisp.dhis.program.Program;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.Assert;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Transactional
+public abstract class AbstractPersonService implements PersonService
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private PatientService patientService;
+
+ @Autowired
+ private PatientIdentifierService patientIdentifierService;
+
+ @Autowired
+ private PatientAttributeValueService patientAttributeValueService;
+
+ @Autowired
+ private IdentifiableObjectManager manager;
+
+ // -------------------------------------------------------------------------
+ // Implementation
+ // -------------------------------------------------------------------------
+
+ // -------------------------------------------------------------------------
+ // READ
+ // -------------------------------------------------------------------------
+
+ @Override
+ public Persons getPersons()
+ {
+ List<Patient> patients = new ArrayList<Patient>( patientService.getAllPatients() );
+ return getPersons( patients );
+ }
+
+ @Override
+ public Persons getPersons( OrganisationUnit organisationUnit )
+ {
+ List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( organisationUnit ) );
+ return getPersons( patients );
+ }
+
+ @Override
+ public Persons getPersons( Gender gender )
+ {
+ List<Patient> patients = new ArrayList<Patient>( patientService.getPatiensByGender( gender.getValue() ) );
+ return getPersons( patients );
+ }
+
+ @Override
+ public Persons getPersons( Program program )
+ {
+ List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( program ) );
+ return getPersons( patients );
+ }
+
+ @Override
+ public Persons getPersons( Program program, Gender gender )
+ {
+ List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( program, gender.getValue() ) );
+ return getPersons( patients );
+ }
+
+ @Override
+ public Persons getPersons( OrganisationUnit organisationUnit, Program program )
+ {
+ List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( organisationUnit, program ) );
+ return getPersons( patients );
+ }
+
+ @Override
+ public Persons getPersons( OrganisationUnit organisationUnit, Gender gender )
+ {
+ List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( organisationUnit, gender.getValue() ) );
+ return getPersons( patients );
+ }
+
+ @Override
+ public Persons getPersons( OrganisationUnit organisationUnit, Program program, Gender gender )
+ {
+ List<Patient> patients = new ArrayList<Patient>( patientService.getPatients( organisationUnit, program, gender.getValue() ) );
+ return getPersons( patients );
+ }
+
+ @Override
+ public Persons getPersons( Collection<Patient> patients )
+ {
+ Persons persons = new Persons();
+
+ for ( Patient patient : patients )
+ {
+ persons.getPersons().add( getPerson( patient ) );
+ }
+
+ return persons;
+ }
+
+ @Override
+ public Person getPerson( String uid )
+ {
+ return getPerson( patientService.getPatient( uid ) );
+ }
+
+ @Override
+ public Person getPerson( Patient patient )
+ {
+ Person person = new Person();
+ person.setPerson( patient.getUid() );
+ person.setOrgUnit( patient.getOrganisationUnit().getUid() );
+
+ person.setName( patient.getName() );
+ person.setGender( Gender.fromString( patient.getGender() ) );
+
+ person.setDeceased( patient.getIsDead() );
+ person.setDateOfDeath( patient.getDeathDate() );
+
+ Contact contact = new Contact();
+ contact.setPhoneNumber( nullIfEmpty( patient.getPhoneNumber() ) );
+
+ if ( contact.getPhoneNumber() != null )
+ {
+ person.setContact( contact );
+ }
+
+ DateOfBirth dateOfBirth;
+
+ Character dobType = patient.getDobType();
+
+ if ( dobType != null && patient.getBirthDate() != null )
+ {
+ if ( dobType.equals( Patient.DOB_TYPE_VERIFIED ) || dobType.equals( Patient.DOB_TYPE_DECLARED ) )
+ {
+ dateOfBirth = new DateOfBirth( patient.getBirthDate(),
+ DateOfBirthType.fromString( String.valueOf( dobType ) ) );
+ }
+ else
+ {
+ // assume APPROXIMATE
+ dateOfBirth = new DateOfBirth( patient.getIntegerValueOfAge() );
+ }
+
+ person.setDateOfBirth( dateOfBirth );
+ }
+
+ person.setDateOfRegistration( patient.getRegistrationDate() );
+
+ for ( PatientIdentifier patientIdentifier : patient.getIdentifiers() )
+ {
+ String identifierType = patientIdentifier.getIdentifierType() == null ? null : patientIdentifier.getIdentifierType().getUid();
+
+ Identifier identifier = new Identifier( identifierType, patientIdentifier.getIdentifier() );
+ person.getIdentifiers().add( identifier );
+ }
+
+ for ( PatientAttribute patientAttribute : patient.getAttributes() )
+ {
+ PatientAttributeValue patientAttributeValue = patientAttributeValueService.getPatientAttributeValue( patient, patientAttribute );
+
+ Attribute attribute = new Attribute();
+ attribute.setType( patientAttribute.getUid() );
+ attribute.setValue( patientAttributeValue.getValue() );
+
+ person.getAttributes().add( attribute );
+ }
+
+ return person;
+ }
+
+ public Patient getPatient( Person person )
+ {
+ Assert.hasText( person.getOrgUnit() );
+
+ Patient patient = new Patient();
+ patient.setName( person.getName() );
+ patient.setGender( person.getGender().getValue() );
+
+ OrganisationUnit organisationUnit = manager.get( OrganisationUnit.class, person.getOrgUnit() );
+ Assert.notNull( organisationUnit );
+
+ patient.setOrganisationUnit( organisationUnit );
+
+ DateOfBirth dateOfBirth = person.getDateOfBirth();
+
+ if ( dateOfBirth != null )
+ {
+ if ( dateOfBirth.getDate() != null && (dateOfBirth.getType().equals( DateOfBirthType.DECLARED ) ||
+ dateOfBirth.getType().equals( DateOfBirthType.VERIFIED )) )
+ {
+ char dobType = dateOfBirth.getType().getValue().charAt( 0 );
+ patient.setDobType( dobType );
+ patient.setBirthDate( dateOfBirth.getDate() );
+ }
+ else if ( dateOfBirth.getAge() != null && dateOfBirth.getType().equals( DateOfBirthType.APPROXIMATE ) )
+ {
+ char dobType = dateOfBirth.getType().getValue().charAt( 0 );
+ patient.setDobType( dobType );
+ patient.setBirthDateFromAge( dateOfBirth.getAge(), dobType );
+ }
+ }
+
+ if ( person.getContact() != null && person.getContact().getPhoneNumber() != null )
+ {
+ patient.setPhoneNumber( person.getContact().getPhoneNumber() );
+ }
+
+ patient.setIsDead( person.isDeceased() );
+
+ if ( person.isDeceased() && person.getDateOfDeath() != null )
+ {
+ patient.setDeathDate( person.getDateOfDeath() );
+ }
+
+ patient.setRegistrationDate( person.getDateOfRegistration() );
+ updateIdentifiers( person, patient );
+
+ return patient;
+ }
+
+ // -------------------------------------------------------------------------
+ // CREATE
+ // -------------------------------------------------------------------------
+
+ @Override
+ public ImportSummary savePerson( Person person )
+ {
+ ImportSummary importSummary = new ImportSummary();
+ importSummary.setDataValueCount( null );
+
+ List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
+ importConflicts.addAll( checkForRequiredIdentifiers( person ) );
+ importConflicts.addAll( checkForRequiredAttributes( person ) );
+
+ importSummary.setConflicts( importConflicts );
+
+ if ( !importConflicts.isEmpty() )
+ {
+ importSummary.setStatus( ImportStatus.ERROR );
+ importSummary.getImportCount().incrementIgnored();
+ return importSummary;
+ }
+
+ updateSystemIdentifier( person );
+
+ Patient patient = getPatient( person );
+ patientService.savePatient( patient );
+
+ updateAttributeValues( person, patient );
+ patientService.updatePatient( patient );
+
+ importSummary.setStatus( ImportStatus.SUCCESS );
+ importSummary.setReference( patient.getUid() );
+ importSummary.getImportCount().incrementImported();
+
+ return importSummary;
+ }
+
+ // -------------------------------------------------------------------------
+ // UPDATE
+ // -------------------------------------------------------------------------
+
+ @Override
+ public ImportSummary updatePerson( Person person )
+ {
+ ImportSummary importSummary = new ImportSummary();
+ importSummary.setDataValueCount( null );
+
+ List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
+ importConflicts.addAll( checkForRequiredIdentifiers( person ) );
+ importConflicts.addAll( checkForRequiredAttributes( person ) );
+
+ Patient patient = manager.get( Patient.class, person.getPerson() );
+
+ if ( patient == null )
+ {
+ importConflicts.add(
+ new ImportConflict( "Person", "person " + person.getPerson() + " does not point to valid person" ) );
+ }
+
+ OrganisationUnit organisationUnit = manager.get( OrganisationUnit.class, person.getOrgUnit() );
+
+ if ( organisationUnit == null )
+ {
+ importConflicts.add(
+ new ImportConflict( "OrganisationUnit", "orgUnit " + person.getOrgUnit() + " does not point to valid organisation unit" ) );
+ }
+
+ DateOfBirth dateOfBirth = person.getDateOfBirth();
+
+ if ( dateOfBirth == null )
+ {
+ importConflicts.add(
+ new ImportConflict( "DateOfBirth", "dateOfBirth is not present" ) );
+ }
+
+ importSummary.setConflicts( importConflicts );
+
+ if ( !importConflicts.isEmpty() )
+ {
+ importSummary.setStatus( ImportStatus.ERROR );
+ importSummary.getImportCount().incrementIgnored();
+ return importSummary;
+ }
+
+ patient.setName( person.getName() );
+ patient.setGender( person.getGender().getValue() );
+ patient.setIsDead( person.isDeceased() );
+ patient.setDeathDate( person.getDateOfDeath() );
+ // TODO should we allow update of this property?
+ patient.setRegistrationDate( person.getDateOfRegistration() );
+
+ String phoneNumber = person.getContact() != null ? person.getContact().getPhoneNumber() : null;
+ patient.setPhoneNumber( phoneNumber );
+
+ if ( DateOfBirthType.APPROXIMATE.equals( dateOfBirth.getType() ) )
+ {
+ dateOfBirth = new DateOfBirth( dateOfBirth.getAge() );
+ }
+
+ patient.setDobType( dateOfBirth.getType().getValue().charAt( 0 ) );
+ patient.setBirthDate( dateOfBirth.getDate() );
+
+ updateSystemIdentifier( person );
+ removeIdentifiers( patient );
+ removeAttributeValues( patient );
+ patientService.updatePatient( patient );
+
+ updateIdentifiers( person, patient );
+ updateAttributeValues( person, patient );
+ patientService.updatePatient( patient );
+
+ importSummary.setStatus( ImportStatus.SUCCESS );
+ importSummary.setReference( patient.getUid() );
+ importSummary.getImportCount().incrementImported();
+
+ return importSummary;
+ }
+
+ // -------------------------------------------------------------------------
+ // DELETE
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void deletePerson( Person person )
+ {
+ Patient patient = patientService.getPatient( person.getPerson() );
+
+ if ( patient != null )
+ {
+ patientService.deletePatient( patient );
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ // -------------------------------------------------------------------------
+ // HELPERS
+ // -------------------------------------------------------------------------
+
+ private List<ImportConflict> checkForRequiredIdentifiers( Person person )
+ {
+ List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
+ Collection<PatientIdentifierType> patientIdentifierTypes = manager.getAll( PatientIdentifierType.class );
+ Map<String, String> cacheMap = new HashMap<String, String>();
+ Patient patient = manager.get( Patient.class, person.getPerson() );
+
+ for ( Identifier identifier : person.getIdentifiers() )
+ {
+ if ( identifier.getValue() != null )
+ {
+ cacheMap.put( identifier.getType(), identifier.getValue() );
+ }
+ }
+
+ for ( PatientIdentifierType patientIdentifierType : patientIdentifierTypes )
+ {
+ if ( patientIdentifierType.isMandatory() )
+ {
+ if ( !cacheMap.keySet().contains( patientIdentifierType.getUid() ) )
+ {
+ importConflicts.add(
+ new ImportConflict( "Identifier.type", "Missing required identifier type " + patientIdentifierType.getUid() ) );
+ }
+ }
+
+ List<PatientIdentifier> patientIdentifiers = new ArrayList<PatientIdentifier>( patientIdentifierService.getAll(
+ patientIdentifierType, cacheMap.get( patientIdentifierType.getUid() ) ) );
+
+ if ( !patientIdentifiers.isEmpty() )
+ {
+ // if .size() > 1, there is something wrong with the db.. but we for-loop for now
+ for ( PatientIdentifier patientIdentifier : patientIdentifiers )
+ {
+ if ( !patientIdentifier.getPatient().equals( patient ) )
+ {
+ importConflicts.add(
+ new ImportConflict( "Identifier.value", "Value already exists for patient " + patientIdentifier.getPatient().getUid()
+ + " with identifier type " + patientIdentifierType.getUid() ) );
+ }
+ }
+ }
+ }
+
+ return importConflicts;
+ }
+
+ private List<ImportConflict> checkForRequiredAttributes( Person person )
+ {
+ List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
+ Collection<PatientAttribute> patientAttributes = manager.getAll( PatientAttribute.class );
+ Set<String> cache = new HashSet<String>();
+
+ for ( Identifier identifier : person.getIdentifiers() )
+ {
+ if ( identifier.getValue() != null )
+ {
+ cache.add( identifier.getType() );
+ }
+ }
+
+ for ( PatientAttribute patientAttribute : patientAttributes )
+ {
+ if ( patientAttribute.isMandatory() )
+ {
+ if ( !cache.contains( patientAttribute.getUid() ) )
+ {
+ importConflicts.add(
+ new ImportConflict( "Identifier.type", "Missing required attribute type " + patientAttribute.getUid() ) );
+ }
+ }
+ }
+
+ return importConflicts;
+ }
+
+ private void updateAttributeValues( Person person, Patient patient )
+ {
+ 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 updateSystemIdentifier( 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();
+ }
+ }
+
+ Identifier identifier = generateSystemIdentifier( birthDate, gender );
+
+ if ( person.getPerson() != null )
+ {
+ identifier = generateSystemIdentifier( birthDate, gender );
+ Patient patient = manager.get( Patient.class, person.getPerson() );
+
+ for ( PatientIdentifier patientIdentifier : patient.getIdentifiers() )
+ {
+ if ( patientIdentifier.getIdentifierType() == null && patientIdentifier.getIdentifier() != null )
+ {
+ identifier = new Identifier( patientIdentifier.getIdentifier() );
+ break;
+ }
+ }
+ }
+
+ person.getIdentifiers().add( identifier );
+ }
+
+ private Identifier generateSystemIdentifier( Date birthDate, String gender )
+ {
+ 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 );
+
+ return identifier;
+ }
+
+ // add identifiers from person => patient
+ private void updateIdentifiers( Person person, Patient patient )
+ {
+ for ( Identifier identifier : person.getIdentifiers() )
+ {
+ if ( identifier.getType() == null )
+ {
+ PatientIdentifier patientIdentifier = new PatientIdentifier();
+ patientIdentifier.setIdentifier( identifier.getValue().trim() );
+ patientIdentifier.setIdentifierType( null );
+ patientIdentifier.setPatient( patient );
+
+ patient.getIdentifiers().add( patientIdentifier );
+
+ continue;
+ }
+
+ PatientIdentifierType type = manager.get( PatientIdentifierType.class, identifier.getType() );
+
+ if ( type != null && nullIfEmpty( identifier.getValue() ) != null )
+ {
+ PatientIdentifier patientIdentifier = new PatientIdentifier();
+ patientIdentifier.setIdentifier( identifier.getValue().trim() );
+ patientIdentifier.setIdentifierType( type );
+ patientIdentifier.setPatient( patient );
+
+ patient.getIdentifiers().add( patientIdentifier );
+ }
+ }
+ }
+
+ private void removeIdentifiers( Patient patient )
+ {
+ for ( PatientIdentifier patientIdentifier : patient.getIdentifiers() )
+ {
+ patientIdentifierService.deletePatientIdentifier( patientIdentifier );
+ }
+
+ patient.setIdentifiers( new HashSet<PatientIdentifier>() );
+ patientService.updatePatient( patient );
+ }
+
+ private void removeAttributeValues( Patient patient )
+ {
+ patientAttributeValueService.deletePatientAttributeValue( patient );
+ patient.setAttributes( new HashSet<PatientAttribute>() );
+ patientService.updatePatient( patient );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Attribute.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Attribute.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Attribute.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,114 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "attribute", namespace = DxfNamespaces.DXF_2_0 )
+public class Attribute
+{
+ private String type;
+
+ private String value;
+
+ public Attribute()
+ {
+ }
+
+ public Attribute( String value )
+ {
+ this.value = value;
+ }
+
+ public Attribute( String type, String value )
+ {
+ this.type = type;
+ this.value = value;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( isAttribute = true )
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( isAttribute = true )
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue( String value )
+ {
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ Attribute attribute = (Attribute) o;
+
+ if ( type != null ? !type.equals( attribute.type ) : attribute.type != null ) return false;
+ if ( value != null ? !value.equals( attribute.value ) : attribute.value != null ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = type != null ? type.hashCode() : 0;
+ result = 31 * result + (value != null ? value.hashCode() : 0);
+ return result;
+ }
+
+ @Override public String toString()
+ {
+ return "Attribute{" +
+ "type='" + type + '\'' +
+ ", value='" + value + '\'' +
+ '}';
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Contact.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Contact.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Contact.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,86 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "contact", namespace = DxfNamespaces.DXF_2_0 )
+public class Contact
+{
+ private String phoneNumber;
+
+ public Contact()
+ {
+ }
+
+ @JsonProperty( required = true )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public String getPhoneNumber()
+ {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber( String phoneNumber )
+ {
+ this.phoneNumber = phoneNumber;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ Contact contact = (Contact) o;
+
+ if ( phoneNumber != null ? !phoneNumber.equals( contact.phoneNumber ) : contact.phoneNumber != null ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return phoneNumber != null ? phoneNumber.hashCode() : 0;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Contact{" +
+ "phoneNumber='" + phoneNumber + '\'' +
+ '}';
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/DateOfBirth.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/DateOfBirth.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/DateOfBirth.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,132 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.patient.Patient;
+
+import java.util.Date;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "dateOfBirth", namespace = DxfNamespaces.DXF_2_0 )
+public class DateOfBirth
+{
+ private Date date;
+
+ private DateOfBirthType type;
+
+ private Integer age;
+
+ public DateOfBirth()
+ {
+ this.type = DateOfBirthType.APPROXIMATE;
+ this.age = 0;
+ }
+
+ public DateOfBirth( Date date )
+ {
+ this.type = DateOfBirthType.VERIFIED;
+ this.age = Patient.getIntegerValueOfAge( date );
+ this.date = date;
+ }
+
+ public DateOfBirth( Date date, DateOfBirthType type )
+ {
+ this.type = type;
+ this.age = Patient.getIntegerValueOfAge( date );
+ this.date = date;
+ }
+
+ public DateOfBirth( Integer age )
+ {
+ this.type = DateOfBirthType.APPROXIMATE;
+ this.age = age;
+ this.date = Patient.getBirthFromAge( age, Patient.AGE_TYPE_YEAR );
+ }
+
+ @JsonProperty( required = true )
+ @JacksonXmlProperty( isAttribute = true )
+ public Date getDate()
+ {
+ return date;
+ }
+
+ @JsonProperty( required = true )
+ @JacksonXmlProperty( isAttribute = true )
+ public DateOfBirthType getType()
+ {
+ return type;
+ }
+
+ @JsonProperty( required = true )
+ @JacksonXmlProperty( isAttribute = true )
+ public Integer getAge()
+ {
+ return age;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ DateOfBirth that = (DateOfBirth) o;
+
+ if ( age != null ? !age.equals( that.age ) : that.age != null ) return false;
+ if ( date != null ? !date.equals( that.date ) : that.date != null ) return false;
+ if ( type != that.type ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = date != null ? date.hashCode() : 0;
+ result = 31 * result + (type != null ? type.hashCode() : 0);
+ result = 31 * result + (age != null ? age.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "DateOfBirth{" +
+ "date=" + date +
+ ", type=" + type +
+ ", age=" + age +
+ '}';
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/DateOfBirthType.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/DateOfBirthType.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/DateOfBirthType.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,64 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public enum DateOfBirthType
+{
+ VERIFIED( "V" ),
+ DECLARED( "D" ),
+ APPROXIMATE( "A" );
+
+ private final String value;
+
+ private DateOfBirthType( String value )
+ {
+ this.value = value;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public static DateOfBirthType fromString( String text )
+ {
+ for ( DateOfBirthType dateOfBirthType : DateOfBirthType.values() )
+ {
+ if ( text.equals( dateOfBirthType.getValue() ) )
+ {
+ return dateOfBirthType;
+ }
+ }
+
+ throw new IllegalArgumentException();
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Gender.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Gender.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Gender.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,66 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "gender", namespace = DxfNamespaces.DXF_2_0 )
+public enum Gender
+{
+ MALE( "M" ), FEMALE( "F" ), TRANSGENDER( "T" );
+
+ private final String value;
+
+ private Gender( String value )
+ {
+ this.value = value;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public static Gender fromString( String text )
+ {
+ for ( Gender gender : Gender.values() )
+ {
+ if ( text.equals( gender.getValue() ) )
+ {
+ return gender;
+ }
+ }
+
+ throw new IllegalArgumentException();
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Identifier.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Identifier.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Identifier.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,115 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "identifier", namespace = DxfNamespaces.DXF_2_0 )
+public class Identifier
+{
+ private String type;
+
+ private String value;
+
+ public Identifier()
+ {
+ }
+
+ public Identifier( String value )
+ {
+ this.value = value;
+ }
+
+ public Identifier( String type, String value )
+ {
+ this.type = type;
+ this.value = value;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( isAttribute = true )
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( isAttribute = true )
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue( String value )
+ {
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ Identifier that = (Identifier) o;
+
+ if ( type != null ? !type.equals( that.type ) : that.type != null ) return false;
+ if ( value != null ? !value.equals( that.value ) : that.value != null ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = type != null ? type.hashCode() : 0;
+ result = 31 * result + (value != null ? value.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Identifier{" +
+ "type='" + type + '\'' +
+ ", value='" + value + '\'' +
+ '}';
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/JacksonPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/JacksonPersonService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/JacksonPersonService.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,170 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.system.notification.Notifier;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StreamUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class JacksonPersonService extends AbstractPersonService
+{
+ @Autowired
+ private Notifier notifier;
+
+ // -------------------------------------------------------------------------
+ // Implementation
+ // -------------------------------------------------------------------------
+
+ private static ObjectMapper xmlMapper = new XmlMapper();
+ private static ObjectMapper jsonMapper = new ObjectMapper();
+
+ @SuppressWarnings( "unchecked" )
+ private static <T> T fromXml( InputStream inputStream, Class<?> clazz ) throws IOException
+ {
+ return (T) xmlMapper.readValue( inputStream, clazz );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private static <T> T fromXml( String input, Class<?> clazz ) throws IOException
+ {
+ return (T) xmlMapper.readValue( input, clazz );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private static <T> T fromJson( InputStream inputStream, Class<?> clazz ) throws IOException
+ {
+ return (T) jsonMapper.readValue( inputStream, clazz );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private static <T> T fromJson( String input, Class<?> clazz ) throws IOException
+ {
+ return (T) jsonMapper.readValue( input, clazz );
+ }
+
+ static
+ {
+ xmlMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true );
+ xmlMapper.configure( DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true );
+ xmlMapper.configure( DeserializationFeature.WRAP_EXCEPTIONS, true );
+ jsonMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true );
+ jsonMapper.configure( DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true );
+ jsonMapper.configure( DeserializationFeature.WRAP_EXCEPTIONS, true );
+ }
+
+ // -------------------------------------------------------------------------
+ // CREATE
+ // -------------------------------------------------------------------------
+
+ @Override
+ public ImportSummaries savePersonXml( InputStream inputStream ) throws IOException
+ {
+ ImportSummaries importSummaries = new ImportSummaries();
+ String input = StreamUtils.copyToString( inputStream, Charset.forName( "UTF-8" ) );
+
+ try
+ {
+ Persons persons = fromXml( input, Persons.class );
+
+ for ( Person person : persons.getPersons() )
+ {
+ person.setPerson( null );
+ importSummaries.addImportSummary( savePerson( person ) );
+ }
+ }
+ catch ( Exception ex )
+ {
+ Person person = fromXml( input, Person.class );
+ person.setPerson( null );
+ importSummaries.addImportSummary( savePerson( person ) );
+ }
+
+ return importSummaries;
+ }
+
+ @Override
+ public ImportSummaries savePersonJson( InputStream inputStream ) throws IOException
+ {
+ ImportSummaries importSummaries = new ImportSummaries();
+ String input = StreamUtils.copyToString( inputStream, Charset.forName( "UTF-8" ) );
+
+ try
+ {
+ Persons persons = fromJson( input, Persons.class );
+
+ for ( Person person : persons.getPersons() )
+ {
+ person.setPerson( null );
+ importSummaries.addImportSummary( savePerson( person ) );
+ }
+ }
+ catch ( Exception ex )
+ {
+ Person person = fromJson( input, Person.class );
+ person.setPerson( null );
+ importSummaries.addImportSummary( savePerson( person ) );
+ }
+
+ return importSummaries;
+ }
+
+ // -------------------------------------------------------------------------
+ // UPDATE
+ // -------------------------------------------------------------------------
+
+ @Override
+ public ImportSummary updatePersonXml( String id, InputStream inputStream ) throws IOException
+ {
+ Person person = fromXml( inputStream, Person.class );
+ person.setPerson( id );
+
+ return updatePerson( person );
+ }
+
+ @Override
+ public ImportSummary updatePersonJson( String id, InputStream inputStream ) throws IOException
+ {
+ Person person = fromJson( inputStream, Person.class );
+ person.setPerson( id );
+
+ return updatePerson( person );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Person.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Person.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Person.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,261 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement(localName = "person", namespace = DxfNamespaces.DXF_2_0)
+public class Person
+{
+ private String person;
+
+ private String orgUnit;
+
+ private String name;
+
+ private Gender gender;
+
+ private DateOfBirth dateOfBirth;
+
+ private boolean deceased;
+
+ private Date dateOfDeath;
+
+ private Date dateOfRegistration = new Date();
+
+ private Contact contact;
+
+ private List<Identifier> identifiers = new ArrayList<Identifier>();
+
+ private List<Attribute> attributes = new ArrayList<Attribute>();
+
+ public Person()
+ {
+ }
+
+ @JsonProperty( required = true )
+ @JacksonXmlProperty( isAttribute = true )
+ public String getPerson()
+ {
+ return person;
+ }
+
+ public void setPerson( String person )
+ {
+ this.person = person;
+ }
+
+ @JsonProperty( required = true )
+ @JacksonXmlProperty( isAttribute = true )
+ public String getOrgUnit()
+ {
+ return orgUnit;
+ }
+
+ public void setOrgUnit( String orgUnit )
+ {
+ this.orgUnit = orgUnit;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public Gender getGender()
+ {
+ return gender;
+ }
+
+ public void setGender( Gender gender )
+ {
+ this.gender = gender;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public DateOfBirth getDateOfBirth()
+ {
+ return dateOfBirth;
+ }
+
+ public void setDateOfBirth( DateOfBirth dateOfBirth )
+ {
+ this.dateOfBirth = dateOfBirth;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public boolean isDeceased()
+ {
+ return deceased;
+ }
+
+ public void setDeceased( boolean deceased )
+ {
+ this.deceased = deceased;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public Date getDateOfDeath()
+ {
+ return dateOfDeath;
+ }
+
+ public void setDateOfDeath( Date dateOfDeath )
+ {
+ this.dateOfDeath = dateOfDeath;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public Date getDateOfRegistration()
+ {
+ return dateOfRegistration;
+ }
+
+ public void setDateOfRegistration( Date dateOfRegistration )
+ {
+ this.dateOfRegistration = dateOfRegistration;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public Contact getContact()
+ {
+ return contact;
+ }
+
+ public void setContact( Contact contact )
+ {
+ this.contact = contact;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public List<Identifier> getIdentifiers()
+ {
+ return identifiers;
+ }
+
+ public void setIdentifiers( List<Identifier> identifiers )
+ {
+ this.identifiers = identifiers;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public List<Attribute> getAttributes()
+ {
+ return attributes;
+ }
+
+ public void setAttributes( List<Attribute> attributes )
+ {
+ this.attributes = attributes;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ 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;
+ if ( dateOfRegistration != null ? !dateOfRegistration.equals( person1.dateOfRegistration ) : person1.dateOfRegistration != null )
+ return false;
+ if ( gender != person1.gender ) return false;
+ if ( identifiers != null ? !identifiers.equals( person1.identifiers ) : person1.identifiers != null ) return false;
+ if ( name != null ? !name.equals( person1.name ) : person1.name != null ) return false;
+ if ( orgUnit != null ? !orgUnit.equals( person1.orgUnit ) : person1.orgUnit != null ) return false;
+ if ( person != null ? !person.equals( person1.person ) : person1.person != null ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = person != null ? person.hashCode() : 0;
+ result = 31 * result + (orgUnit != null ? orgUnit.hashCode() : 0);
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ result = 31 * result + (gender != null ? gender.hashCode() : 0);
+ result = 31 * result + (dateOfBirth != null ? dateOfBirth.hashCode() : 0);
+ result = 31 * result + (deceased ? 1 : 0);
+ result = 31 * result + (dateOfDeath != null ? dateOfDeath.hashCode() : 0);
+ 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()
+ {
+ return "Person{" +
+ "person='" + person + '\'' +
+ ", orgUnit='" + orgUnit + '\'' +
+ ", name='" + name + '\'' +
+ ", gender=" + gender +
+ ", dateOfBirth=" + dateOfBirth +
+ ", deceased=" + deceased +
+ ", dateOfDeath=" + dateOfDeath +
+ ", dateOfRegistration=" + dateOfRegistration +
+ ", contact=" + contact +
+ ", identifiers=" + identifiers +
+ ", attributes=" + attributes +
+ '}';
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/PersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/PersonService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/PersonService.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,97 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.program.Program;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface PersonService
+{
+ // -------------------------------------------------------------------------
+ // READ
+ // -------------------------------------------------------------------------
+
+ Persons getPersons();
+
+ Persons getPersons( OrganisationUnit organisationUnit );
+
+ Persons getPersons( Gender gender );
+
+ Persons getPersons( Program program );
+
+ Persons getPersons( Program program, Gender gender );
+
+ Persons getPersons( OrganisationUnit organisationUnit, Program program );
+
+ Persons getPersons( OrganisationUnit organisationUnit, Gender gender );
+
+ Persons getPersons( OrganisationUnit organisationUnit, Program program, Gender gender );
+
+ Persons getPersons( Collection<Patient> patients );
+
+ Person getPerson( String uid );
+
+ Person getPerson( Patient patient );
+
+ // -------------------------------------------------------------------------
+ // CREATE
+ // -------------------------------------------------------------------------
+
+ ImportSummaries savePersonXml( InputStream inputStream ) throws IOException;
+
+ ImportSummaries savePersonJson( InputStream inputStream ) throws IOException;
+
+ ImportSummary savePerson( Person person );
+
+ // -------------------------------------------------------------------------
+ // UPDATE
+ // -------------------------------------------------------------------------
+
+ ImportSummary updatePersonXml( String id, InputStream inputStream ) throws IOException;
+
+ ImportSummary updatePersonJson( String id, InputStream inputStream ) throws IOException;
+
+ ImportSummary updatePerson( Person person );
+
+ // -------------------------------------------------------------------------
+ // DELETE
+ // -------------------------------------------------------------------------
+
+ void deletePerson( Person person );
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Persons.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Persons.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/person/Persons.java 2013-09-16 13:13:14 +0000
@@ -0,0 +1,72 @@
+package org.hisp.dhis.dxf2.person;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "persons", namespace = DxfNamespaces.DXF_2_0 )
+public class Persons
+{
+ private List<Person> persons = new ArrayList<Person>();
+
+ public Persons()
+ {
+ }
+
+ @JsonProperty( "personList" )
+ @JacksonXmlElementWrapper( localName = "personList", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "person", namespace = DxfNamespaces.DXF_2_0 )
+ public List<Person> getPersons()
+ {
+ return persons;
+ }
+
+ public void setPersons( List<Person> persons )
+ {
+ this.persons = persons;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Persons{" +
+ "persons=" + persons +
+ '}';
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml 2013-09-10 14:11:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml 2013-09-16 13:13:14 +0000
@@ -18,7 +18,7 @@
<bean id="org.hisp.dhis.dxf2.event.EventService" class="org.hisp.dhis.dxf2.event.JacksonEventService" />
- <bean id="org.hisp.dhis.dxf2.event.PersonService" class="org.hisp.dhis.dxf2.event.person.JacksonPersonService" />
+ <bean id="org.hisp.dhis.dxf2.event.PersonService" class="org.hisp.dhis.dxf2.person.JacksonPersonService" />
<bean id="org.hisp.dhis.dxf2.InputValidationService" class="org.hisp.dhis.dxf2.DefaultInputValidationService" />
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2013-09-04 13:21:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2013-09-16 13:13:14 +0000
@@ -35,7 +35,7 @@
import org.hisp.dhis.dxf2.event.Event;
import org.hisp.dhis.dxf2.event.EventService;
import org.hisp.dhis.dxf2.event.Events;
-import org.hisp.dhis.dxf2.event.tasks.ImportEventTask;
+import org.hisp.dhis.dxf2.event.ImportEventTask;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java 2013-09-16 07:42:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java 2013-09-16 13:13:14 +0000
@@ -32,10 +32,10 @@
import org.hisp.dhis.api.controller.exception.NotFoundException;
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.dxf2.event.person.Gender;
-import org.hisp.dhis.dxf2.event.person.Person;
-import org.hisp.dhis.dxf2.event.person.PersonService;
-import org.hisp.dhis.dxf2.event.person.Persons;
+import org.hisp.dhis.dxf2.person.Gender;
+import org.hisp.dhis.dxf2.person.Person;
+import org.hisp.dhis.dxf2.person.PersonService;
+import org.hisp.dhis.dxf2.person.Persons;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
@@ -235,6 +235,11 @@
}
// -------------------------------------------------------------------------
+ // ENROLLMENT
+ // -------------------------------------------------------------------------
+
+
+ // -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/event/ImportEventAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/event/ImportEventAction.java 2013-09-05 09:25:02 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/event/ImportEventAction.java 2013-09-16 13:13:14 +0000
@@ -30,7 +30,7 @@
import com.opensymphony.xwork2.Action;
import org.hisp.dhis.dxf2.event.EventService;
-import org.hisp.dhis.dxf2.event.tasks.ImportEventTask;
+import org.hisp.dhis.dxf2.event.ImportEventTask;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
import org.hisp.dhis.scheduling.TaskCategory;
import org.hisp.dhis.scheduling.TaskId;