Skip to content

Commit

Permalink
SYNCT-100: Switching on synchronization of nested patient's objects (#…
Browse files Browse the repository at this point in the history
…137)

* SYNCT-100: Added the PERSON_ADDRESS resource and improved the code readability

* SYNCT-100: Changed logic used to extract UUID from resource link

* SYNCT-100: Changed the sync 2.0 default configuration

* SYNCT-100: Added more information to audit log after fail

* SYNCT-100: Fixed issue related to updating the voided objects

* SYNCT-100: Fixed issue with displaying conflicted fields

* SYNCT-100: Changed the Webservices.REST version to the newest

* SYNCT-100: Updated the atomfeed version

* SYNCT-100: Updated the STOP WORDS list

* SYNCT-100: Added support of synchronization PersonName object

* SYNCT-100: Added support of synchronization PatientIdentifier objects

* SYNCT-100: Added extracting the UUID based on preferred client link

* SYNCT-100: Updated the default Sync configuration

* SYNCT-100: Fixed issue with displaying the conflicted fields
  • Loading branch information
areklalo committed Feb 18, 2019
1 parent 4d8de93 commit 127608f
Show file tree
Hide file tree
Showing 23 changed files with 511 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,95 @@ public class SyncCategoryConstants {

public static final String CATEGORY_PATIENT = "patient";

public static final String PATIENT_LABEL = "sync2.log.resource.patient";

public static final String CATEGORY_VISIT = "visit";

public static final String VISIT_LABEL = "Encounter.visit";

public static final String CATEGORY_ENCOUNTER = "encounter";

public static final String ENCOUNTER_LABEL = "Encounter.title";

public static final String CATEGORY_OBSERVATION = "observation";

public static final String OBSERVATION_LABEL = "Obs.title";

public static final String CATEGORY_LOCATION = "location";

public static final String LOCATION_LABEL = "sync2.log.resource.location";

public static final String CATEGORY_PERSON = "person";

public static final String PERSON_LABEL = "sync2.log.resource.person";

public static final String CATEGORY_PRIVILEGE = "privilege";

public static final String PRIVILEGE_LABEL = "sync2.log.resource.privilege";

public static final String CATEGORY_AUDIT_MESSAGE = "audit_message";

public static final String AUDIT_MESSAGE_LABEL = "sync2.log.resource.auditMessage";

public static final String CATEGORY_ALLERGY = "allergy";

public static final String ALLERGY_LABEL = "sync2.log.resource.allergy";

public static final String CATEGORY_FORM = "form";

public static final String FORM_LABEL = "sync2.log.resource.form";

public static final String CATEGORY_COHORT = "cohort";

public static final String COHORT_LABEL = "sync2.log.resource.cohort";

public static final String CATEGORY_DRUG_ORDER = "drug_order";

public static final String DRUG_ORDER_LABEL = "sync2.log.resource.drug_order";

public static final String CATEGORY_TEST_ORDER = "test_order";

public static final String TEST_ORDER_LABEL = "sync2.log.resource.test_order";

public static final String CATEGORY_PERSON_ADDRESS = "person_address";

public static final String PERSON_ADDRESS_LABEL = "sync2.log.resource.person_address";

public static final String ALL = "ALL";

public static final String ALL_LABEL = "sync2.log.resource.all";

public static final String CATEGORY_PROVIDER = "provider";

public static final String PROVIDER_LABEL = "sync2.log.resource.provider";

public static final String CATEGORY_PATIENT_PROGRAM= "patient_program";

public static final String PATIENT_PROGRAM_LABEL = "sync2.log.resource.patient_program";

public static final String CATEGORY_RELATIONSHIP= "relationship";

public static final String RELATIONSHIP_LABEL = "sync2.log.resource.relationship";

public static final String CATEGORY_VISIT_TYPE = "visit_type";

public static final String VISIT_TYPE_LABEL = "sync2.log.resource.visit_type";

public static final String CATEGORY_USER = "user";

public static final String USER_LABEL = "sync2.log.resource.user";

public static final String CATEGORY_PROGRAM = "program";

public static final String PROGRAM_LABEL = "sync2.log.resource.program";

public static final String CATEGORY_PERSON_NAME = "person_name";

public static final String PERSON_NAME_LABEL = "sync2.log.resource.person_name";

public static final String CATEGORY_PATIENT_IDENTIFIER = "patient_identifier";

public static final String PATIENT_IDENTIFIER_LABEL = "sync2.log.resource.patient_identifier";

private SyncCategoryConstants() {}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.openmrs.module.sync2.api.model.audit;

import java.util.Date;
import java.util.Map;
import java.util.Objects;

import org.hibernate.annotations.Persister;
import org.hibernate.persister.entity.SingleTableEntityPersister;
import org.openmrs.BaseOpenmrsData;
import org.openmrs.BaseOpenmrsObject;
import org.openmrs.module.sync2.api.utils.SyncUtils;
import org.openmrs.module.sync2.client.rest.resource.RestResource;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import java.util.Objects;

@Persister(impl = SingleTableEntityPersister.class)
public class AuditMessage extends BaseOpenmrsData implements RestResource {
public class AuditMessage extends BaseOpenmrsData implements RestResource, Serializable {

private static final long serialVersionUID = 6106269076155338045L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import org.openmrs.Location;
import org.openmrs.Obs;
import org.openmrs.Patient;
import org.openmrs.PatientIdentifier;
import org.openmrs.PatientProgram;
import org.openmrs.Person;
import org.openmrs.PersonAddress;
import org.openmrs.PersonName;
import org.openmrs.Privilege;
import org.openmrs.Program;
import org.openmrs.Provider;
Expand All @@ -17,31 +20,34 @@
import org.openmrs.User;
import org.openmrs.Visit;
import org.openmrs.VisitType;
import org.openmrs.module.fhir.api.util.FHIRConstants;
import org.openmrs.module.sync2.SyncCategoryConstants;
import org.openmrs.module.sync2.api.model.audit.AuditMessage;

import java.util.HashMap;
import java.util.Map;

public enum CategoryEnum {
LOCATION(FHIRConstants.CATEGORY_LOCATION, Location.class),
OBSERVATION(FHIRConstants.CATEGORY_OBSERVATION, Obs.class),
ENCOUNTER(FHIRConstants.CATEGORY_ENCOUNTER, Encounter.class),
VISIT(FHIRConstants.CATEGORY_VISIT, Visit.class),
PROVIDER(FHIRConstants.CATEGORY_PROVIDER, Provider.class),
DRUG_ORDER(FHIRConstants.CATEGORY_DRUG_ORDER, DrugOrder.class),
TEST_ORDER(FHIRConstants.CATEGORY_TEST_ORDER, TestOrder.class),
FORM("form", Form.class),
PATIENT_PROGRAM("patient_program", PatientProgram.class),
PERSON(FHIRConstants.CATEGORY_PERSON, Person.class),
PATIENT(FHIRConstants.CATEGORY_PATIENT, Patient.class),
RELATIONSHIP("relationship", Relationship.class),
COHORT(FHIRConstants.CATEGORY_COHORT, Cohort.class),
VISIT_TYPE("visit_type", VisitType.class),
USER("user", User.class),
PROGRAM("program", Program.class),
PRIVILEGE("privilege", Privilege.class),
AUDIT_MESSAGE("audit_message", AuditMessage.class);
LOCATION(SyncCategoryConstants.CATEGORY_LOCATION, Location.class),
OBSERVATION(SyncCategoryConstants.CATEGORY_OBSERVATION, Obs.class),
ENCOUNTER(SyncCategoryConstants.CATEGORY_ENCOUNTER, Encounter.class),
VISIT(SyncCategoryConstants.CATEGORY_VISIT, Visit.class),
PROVIDER(SyncCategoryConstants.CATEGORY_PROVIDER, Provider.class),
DRUG_ORDER(SyncCategoryConstants.CATEGORY_DRUG_ORDER, DrugOrder.class),
TEST_ORDER(SyncCategoryConstants.CATEGORY_TEST_ORDER, TestOrder.class),
FORM(SyncCategoryConstants.CATEGORY_FORM, Form.class),
PATIENT_PROGRAM(SyncCategoryConstants.CATEGORY_PATIENT_PROGRAM, PatientProgram.class),
PERSON(SyncCategoryConstants.CATEGORY_PERSON, Person.class),
PATIENT(SyncCategoryConstants.CATEGORY_PATIENT, Patient.class),
RELATIONSHIP(SyncCategoryConstants.CATEGORY_RELATIONSHIP, Relationship.class),
COHORT(SyncCategoryConstants.CATEGORY_COHORT, Cohort.class),
VISIT_TYPE(SyncCategoryConstants.CATEGORY_VISIT_TYPE, VisitType.class),
USER(SyncCategoryConstants.CATEGORY_USER, User.class),
PROGRAM(SyncCategoryConstants.CATEGORY_PROGRAM, Program.class),
PRIVILEGE(SyncCategoryConstants.CATEGORY_PRIVILEGE, Privilege.class),
AUDIT_MESSAGE(SyncCategoryConstants.CATEGORY_AUDIT_MESSAGE, AuditMessage.class),
PERSON_ADDRESS(SyncCategoryConstants.CATEGORY_PERSON_ADDRESS, PersonAddress.class),
PERSON_NAME(SyncCategoryConstants.CATEGORY_PERSON_NAME, PersonName.class),
PATIENT_IDENTIFIER(SyncCategoryConstants.CATEGORY_PATIENT_IDENTIFIER, PatientIdentifier.class);

private static final Map<String, CategoryEnum> MAP;

Expand All @@ -64,27 +70,17 @@ public Class getClazz() {

static {
MAP = new HashMap<>();
MAP.put(LOCATION.getCategory(), LOCATION);
MAP.put(OBSERVATION.getCategory(), OBSERVATION);
MAP.put(ENCOUNTER.getCategory(), ENCOUNTER);
MAP.put(VISIT.getCategory(), VISIT);
MAP.put(PROVIDER.getCategory(), PROVIDER);
MAP.put(DRUG_ORDER.getCategory(), DRUG_ORDER);
MAP.put(TEST_ORDER.getCategory(), TEST_ORDER);
MAP.put(FORM.getCategory(), FORM);
MAP.put(PATIENT_PROGRAM.getCategory(), PATIENT_PROGRAM);
MAP.put(PERSON.getCategory(), PERSON);
MAP.put(PATIENT.getCategory(), PATIENT);
MAP.put(RELATIONSHIP.getCategory(), RELATIONSHIP);
MAP.put(COHORT.getCategory(), COHORT);
MAP.put(VISIT_TYPE.getCategory(), VISIT_TYPE);
MAP.put(USER.getCategory(), USER);
MAP.put(PROGRAM.getCategory(), PROGRAM);
MAP.put(PRIVILEGE.getCategory(), PRIVILEGE);
MAP.put(AUDIT_MESSAGE.getCategory(), AUDIT_MESSAGE);
for (CategoryEnum category : CategoryEnum.values()) {
MAP.put(category.getCategory(), category);
}
}

public static CategoryEnum getByCategory(String category) {
return MAP.get(category);
}

private static class Constants {


}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
package org.openmrs.module.sync2.api.model.enums;

import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_ALLERGY;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_AUDIT_MESSAGE;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_COHORT;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_DRUG_ORDER;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_ENCOUNTER;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_FORM;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_LOCATION;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_OBSERVATION;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_PATIENT;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_PERSON;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_PRIVILEGE;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_TEST_ORDER;
import static org.openmrs.module.sync2.SyncCategoryConstants.CATEGORY_VISIT;
import org.openmrs.module.sync2.SyncCategoryConstants;

public enum Resources {

ALL(""),
PATIENT(CATEGORY_PATIENT),
VISIT(CATEGORY_VISIT),
ENCOUNTER(CATEGORY_ENCOUNTER),
OBSERVATION(CATEGORY_OBSERVATION),
LOCATION(CATEGORY_LOCATION),
PRIVILEGE(CATEGORY_PRIVILEGE),
AUDIT_MESSAGE(CATEGORY_AUDIT_MESSAGE),
PERSON(CATEGORY_PERSON),
ALLERGY(CATEGORY_ALLERGY),
FORM(CATEGORY_FORM),
COHORT(CATEGORY_COHORT),
DRUG_ORDER(CATEGORY_DRUG_ORDER),
TEST_ORDER(CATEGORY_TEST_ORDER);
ALL(SyncCategoryConstants.ALL, SyncCategoryConstants.ALL_LABEL),
PATIENT(SyncCategoryConstants.CATEGORY_PATIENT, SyncCategoryConstants.PATIENT_LABEL),
VISIT(SyncCategoryConstants.CATEGORY_VISIT, SyncCategoryConstants.VISIT_LABEL),
ENCOUNTER(SyncCategoryConstants.CATEGORY_ENCOUNTER, SyncCategoryConstants.ENCOUNTER_LABEL),
OBSERVATION(SyncCategoryConstants.CATEGORY_OBSERVATION, SyncCategoryConstants.OBSERVATION_LABEL),
LOCATION(SyncCategoryConstants.CATEGORY_LOCATION, SyncCategoryConstants.LOCATION_LABEL),
PRIVILEGE(SyncCategoryConstants.CATEGORY_PRIVILEGE, SyncCategoryConstants.PRIVILEGE_LABEL),
AUDIT_MESSAGE(SyncCategoryConstants.CATEGORY_AUDIT_MESSAGE, SyncCategoryConstants.AUDIT_MESSAGE_LABEL),
PERSON(SyncCategoryConstants.CATEGORY_PERSON, SyncCategoryConstants.PERSON_LABEL),
ALLERGY(SyncCategoryConstants.CATEGORY_ALLERGY, SyncCategoryConstants.ALLERGY_LABEL),
FORM(SyncCategoryConstants.CATEGORY_FORM, SyncCategoryConstants.FORM_LABEL),
COHORT(SyncCategoryConstants.CATEGORY_COHORT, SyncCategoryConstants.COHORT_LABEL),
DRUG_ORDER(SyncCategoryConstants.CATEGORY_DRUG_ORDER, SyncCategoryConstants.DRUG_ORDER_LABEL),
TEST_ORDER(SyncCategoryConstants.CATEGORY_TEST_ORDER, SyncCategoryConstants.TEST_ORDER_LABEL),
PERSON_ADDRESS(SyncCategoryConstants.CATEGORY_PERSON_ADDRESS, SyncCategoryConstants.PERSON_ADDRESS_LABEL),
PROVIDER(SyncCategoryConstants.CATEGORY_PROVIDER, SyncCategoryConstants.PROVIDER_LABEL),
PATIENT_PROGRAM(SyncCategoryConstants.CATEGORY_PATIENT_PROGRAM, SyncCategoryConstants.PATIENT_PROGRAM_LABEL),
RELATIONSHIP(SyncCategoryConstants.CATEGORY_RELATIONSHIP, SyncCategoryConstants.RELATIONSHIP_LABEL),
VISIT_TYPE(SyncCategoryConstants.CATEGORY_VISIT_TYPE, SyncCategoryConstants.VISIT_TYPE_LABEL),
USER(SyncCategoryConstants.CATEGORY_USER, SyncCategoryConstants.USER_LABEL),
PROGRAM(SyncCategoryConstants.CATEGORY_PROGRAM, SyncCategoryConstants.PROGRAM_LABEL),
PERSON_NAME(SyncCategoryConstants.CATEGORY_PERSON_NAME, SyncCategoryConstants.PERSON_NAME_LABEL),
PATIENT_IDENTIFIER(SyncCategoryConstants.CATEGORY_PATIENT_IDENTIFIER, SyncCategoryConstants.PATIENT_IDENTIFIER_LABEL);

private final String name;

Resources(String name) {
private final String messageKey;

Resources(String name, String messageKey) {
this.name = name;
this.messageKey = messageKey;
}

public String getName() {
return this.name;
}

public String getMessageKey() {
return messageKey;
}

private static class Constants {


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import org.openmrs.module.sync2.api.model.SyncCategory;
import org.openmrs.module.sync2.api.model.configuration.EventConfiguration;

import java.util.Map;

public interface EventConfigurationService {

EventConfiguration getEventConfigurationByCategory(SyncCategory categoryEnum);

String extractUuidFromResourceLinks(Map<String, String> eventResourceLinks, String eventCategory, String preferredClient);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

public abstract class AbstractSynchronizationService {

private static final String VOIDED_KEY = "voided";

protected SyncClient syncClient = new SyncClient();

@Autowired
Expand Down Expand Up @@ -126,7 +128,8 @@ protected List<String> determineActions(Object objToUpdate, Object baseObj) {
}

protected boolean shouldSynchronize(SimpleObject oldObject, SimpleObject newObject, String action) {
if (isWrongUpdateOrDeleteAction(newObject, action) || isWrongCreateAction(oldObject, newObject, action)) {
if (isWrongUpdateOrDeleteAction(newObject, action) || isWrongCreateAction(oldObject, newObject, action) ||
isUpdateOnVoidedObject(oldObject, action)) {
return false;
}
return oldObject == null || newObject == null || areDifferentObjects(oldObject, newObject);
Expand All @@ -140,6 +143,11 @@ private boolean isWrongUpdateOrDeleteAction(SimpleObject newObject, String actio
return newObject == null && (SyncUtils.isDeleteAction(action) || SyncUtils.isUpdateAction(action));
}

private boolean isUpdateOnVoidedObject(SimpleObject object, String action) {
return SyncUtils.isUpdateAction(action) && object != null &&
object.containsKey(VOIDED_KEY) && (boolean) object.get(VOIDED_KEY);
}

private boolean areDifferentObjects(SimpleObject oldObject, SimpleObject newObject) {
String localHashCode = SyncHashcodeUtils.getHashcode(oldObject);
String pulledHashCode = SyncHashcodeUtils.getHashcode(newObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void pullAndSaveObjectsFromParent(SyncCategory category) throws SyncExcep
public AuditMessage pullAndSaveObjectFromParent(SyncCategory category, Map<String, String> resourceLinks,
String action) {
String clientName = SyncUtils.selectAppropriateClientName(resourceLinks, category.getCategory(), getOperation());
String uuid = extractUUIDFromResourceLinks(resourceLinks);
String uuid = extractUUIDFromResourceLinks(resourceLinks, category.getCategory(), clientName);
return pullAndSaveObjectFromParent(category, resourceLinks, action, clientName, uuid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected String getFailedSynchronizationMessage() {
public AuditMessage readAndPushObjectToParent(SyncCategory category, Map<String, String> resourceLinks,
String action) {
String clientName = SyncUtils.selectAppropriateClientName(resourceLinks, category.getCategory(), getOperation());
String uuid = extractUUIDFromResourceLinks(resourceLinks);
String uuid = extractUUIDFromResourceLinks(resourceLinks, category.getCategory(), clientName);
return readAndPushObjectToParent(category, resourceLinks, action, clientName, uuid);
}

Expand Down
Loading

0 comments on commit 127608f

Please sign in to comment.