Skip to content

Commit 33d146e

Browse files
committed
U4X-959: Revamp Viral Load Sync Jobs to enable users manually sync Individual Tests
1 parent 0473c40 commit 33d146e

File tree

10 files changed

+851
-328
lines changed

10 files changed

+851
-328
lines changed

api/src/main/java/org/openmrs/module/ugandaemrsync/api/UgandaEMRSyncService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
import org.springframework.transaction.annotation.Transactional;
2727

2828
import java.text.ParseException;
29-
import java.util.Collection;
30-
import java.util.Date;
31-
import java.util.List;
32-
import java.util.Properties;
29+
import java.util.*;
3330

3431
/**
3532
* The main service of this module, which is exposed for other modules. See
@@ -496,5 +493,12 @@ public Encounter addVLToEncounter(String vlQualitative, String vlQuantitative, S
496493
public List<JSONObject> generateDrugOrderToOtherSystem(Collection<Concept> conceptList);
497494

498495
public void sendPrescription();
496+
497+
498+
public List<Map<String, String>> generateAndSyncBulkViralLoadRequest();
499+
500+
public Map sendSingleViralLoadOrder(Order order);
501+
502+
public Date getDateFromString(String dateString, String format);
499503
}
500504

api/src/main/java/org/openmrs/module/ugandaemrsync/api/dao/UgandaEMRSyncDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public SyncTask getSyncTask(String syncTask) {
7979
}
8080

8181

82+
8283
/**
8384
* @see org.openmrs.module.ugandaemrsync.api.UgandaEMRSyncService#getSyncTasksBySyncTaskId(java.lang.String)
8485
*/

api/src/main/java/org/openmrs/module/ugandaemrsync/api/impl/UgandaEMRSyncServiceImpl.java

Lines changed: 274 additions & 55 deletions
Large diffs are not rendered by default.

api/src/main/java/org/openmrs/module/ugandaemrsync/server/SyncConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class SyncConstant {
4242
public static final String CARE_SETTING_UUID_OPD = "6f0c9a92-6f24-11e3-af88-005056821db0";
4343

4444
public static final String ORDER_TYPE_DRUG_UUID = "131168f4-15f5-102d-96e4-000c29c2a5d7";
45+
public static final String ORDER_TYPE_TEST_UUID = "52a447d3-a64a-11e3-9aeb-50e549534c5e";
4546

4647
public static final String SERVER_IP = "ugandaemrsync.serverIP";
4748

api/src/main/java/org/openmrs/module/ugandaemrsync/server/SyncFHIRRecord.java

Lines changed: 75 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public class SyncFHIRRecord {
8989

9090
SyncFhirCase syncFhirCase = null;
9191

92-
private SyncFhirProfile profile;
92+
private SyncFhirProfile profile = null;
9393
private List<PatientProgram> patientPrograms;
9494

9595
Map<String, Object> anyOtherObject = new HashMap<>();
@@ -728,7 +728,7 @@ private Collection<String> groupInBundles(String resourceType, Collection<IBaseR
728728
return resourceBundles;
729729
}
730730

731-
private Collection<String> groupInCaseBundle(String resourceType, Collection<IBaseResource> iBaseResources, String identifierTypeName) {
731+
public Collection<String> groupInCaseBundle(String resourceType, Collection<IBaseResource> iBaseResources, String identifierTypeName) {
732732

733733
Collection<String> resourceBundles = new ArrayList<>();
734734

@@ -752,7 +752,7 @@ private String encodeResourceToString(String resourceType, String identifierType
752752

753753
if (resourceType.equals("Patient") || resourceType.equals("Practitioner")) {
754754

755-
if (resourceType.equals("Patient") && profile.getKeepProfileIdentifierOnly()) {
755+
if (resourceType.equals("Patient") && profile != null && profile.getKeepProfileIdentifierOnly()) {
756756
try {
757757
jsonString = removeIdentifierExceptProfileId(jsonString, "identifier");
758758
jsonString = addCodingToIdentifier(jsonString, "identifier");
@@ -803,14 +803,19 @@ private String addUseOfficialToName(String payload, String attributeName) {
803803
}
804804

805805
private String removeIdentifierExceptProfileId(String payload, String attributeName) {
806-
JSONObject jsonObject = new JSONObject(payload);
807-
int objectCount = 0;
808-
for (int i = 0; i < jsonObject.getJSONArray(attributeName).length(); i++) {
809-
if (!jsonObject.getJSONArray("identifier").getJSONObject(i).getJSONObject("type").getJSONArray("coding").getJSONObject(0).get("code").toString().equals(profile.getPatientIdentifierType().getUuid())) {
810-
jsonObject.getJSONArray("identifier").remove(i);
806+
if (profile != null) {
807+
JSONObject jsonObject = new JSONObject(payload);
808+
int objectCount = 0;
809+
for (int i = 0; i < jsonObject.getJSONArray(attributeName).length(); i++) {
810+
if (!jsonObject.getJSONArray("identifier").getJSONObject(i).getJSONObject("type").getJSONArray("coding").getJSONObject(0).get("code").toString().equals(profile.getPatientIdentifierType().getUuid())) {
811+
jsonObject.getJSONArray("identifier").remove(i);
812+
}
811813
}
814+
815+
return jsonObject.toString();
816+
} else {
817+
return payload;
812818
}
813-
return jsonObject.toString();
814819
}
815820

816821
private String removeAttribute(String payload, String attributeName) {
@@ -963,19 +968,21 @@ private List<Person> getPersonsFromEncounterList(List<Encounter> encounters) {
963968
}
964969

965970

966-
private Collection<IBaseResource> getPatientResourceBundle(SyncFhirProfile syncFhirProfile, List<PatientIdentifier> patientIdentifiers, SyncFhirCase syncFhirCase) {
971+
public Collection<IBaseResource> getPatientResourceBundle(SyncFhirProfile syncFhirProfile, List<PatientIdentifier> patientIdentifiers, SyncFhirCase syncFhirCase) {
967972

968973
DateRangeParam lastUpdated = new DateRangeParam();
969974

970-
if (syncFhirProfile.getIsCaseBasedProfile()) {
971-
if (syncFhirCase != null && syncFhirCase.getLastUpdateDate() != null) {
972-
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(syncFhirCase.getLastUpdateDate());
973-
} else if (syncFhirCase != null) {
974-
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getDefaultLastSyncDate());
975-
}
976-
} else {
977-
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getLastSyncDate(syncFhirProfile, "Patient"));
975+
if (syncFhirProfile != null) {
976+
if (syncFhirProfile.getIsCaseBasedProfile()) {
977+
if (syncFhirCase != null && syncFhirCase.getLastUpdateDate() != null) {
978+
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(syncFhirCase.getLastUpdateDate());
979+
} else if (syncFhirCase != null) {
980+
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getDefaultLastSyncDate());
981+
}
982+
} else {
983+
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getLastSyncDate(syncFhirProfile, "Patient"));
978984

985+
}
979986
}
980987

981988

@@ -992,12 +999,14 @@ private Collection<IBaseResource> getPatientResourceBundle(SyncFhirProfile syncF
992999
return getApplicationContext().getBean(FhirPatientService.class).searchForPatients(patientSearchParams).getResources(0, Integer.MAX_VALUE);
9931000
}
9941001

995-
private Collection<IBaseResource> getPractitionerResourceBundle(SyncFhirProfile syncFhirProfile, List<Encounter> encounterList, List<Order> orders) {
1002+
public Collection<IBaseResource> getPractitionerResourceBundle(SyncFhirProfile syncFhirProfile, List<Encounter> encounterList, List<Order> orders) {
9961003
PractitionerSearchParams practitionerSearchParams = new PractitionerSearchParams();
9971004

998-
if (!syncFhirProfile.getIsCaseBasedProfile()) {
999-
DateRangeParam lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getLastSyncDate(syncFhirProfile, "Practitioner"));
1000-
practitionerSearchParams.setLastUpdated(lastUpdated);
1005+
if (syncFhirProfile != null) {
1006+
if (!syncFhirProfile.getIsCaseBasedProfile()) {
1007+
DateRangeParam lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getLastSyncDate(syncFhirProfile, "Practitioner"));
1008+
practitionerSearchParams.setLastUpdated(lastUpdated);
1009+
}
10011010
}
10021011
TokenAndListParam providerReference = new TokenAndListParam();
10031012
for (Encounter encounter : encounterList) {
@@ -1011,28 +1020,36 @@ private Collection<IBaseResource> getPractitionerResourceBundle(SyncFhirProfile
10111020
providerReference.addAnd(new TokenParam(order.getOrderer().getUuid()));
10121021
}
10131022

1014-
if (providerReference != null) {
1023+
if (providerReference.size()>0) {
10151024
practitionerSearchParams.setIdentifier(providerReference);
10161025
}
10171026

1018-
return getApplicationContext().getBean(FhirPractitionerService.class).searchForPractitioners(practitionerSearchParams).getResources(0, Integer.MAX_VALUE);
1027+
List<IBaseResource> iBaseResources = new ArrayList<>();
1028+
1029+
if (providerReference.size()>0) {
1030+
iBaseResources = getApplicationContext().getBean(FhirPractitionerService.class).searchForPractitioners(practitionerSearchParams).getResources(0, Integer.MAX_VALUE);
1031+
}
1032+
1033+
return iBaseResources;
10191034

10201035
}
10211036

1022-
private Collection<IBaseResource> getPersonResourceBundle(SyncFhirProfile syncFhirProfile, List<Person> personList, SyncFhirCase syncFhirCase) {
1037+
public Collection<IBaseResource> getPersonResourceBundle(SyncFhirProfile syncFhirProfile, List<Person> personList, SyncFhirCase syncFhirCase) {
10231038

10241039

10251040
DateRangeParam lastUpdated = new DateRangeParam();
10261041

1027-
if (syncFhirProfile.getIsCaseBasedProfile()) {
1028-
if (syncFhirCase != null && syncFhirCase.getLastUpdateDate() != null) {
1029-
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(syncFhirCase.getLastUpdateDate());
1042+
if (syncFhirProfile != null) {
1043+
if (syncFhirProfile.getIsCaseBasedProfile()) {
1044+
if (syncFhirCase != null && syncFhirCase.getLastUpdateDate() != null) {
1045+
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(syncFhirCase.getLastUpdateDate());
1046+
} else {
1047+
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getDefaultLastSyncDate());
1048+
}
10301049
} else {
1031-
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getDefaultLastSyncDate());
1032-
}
1033-
} else {
1034-
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getLastSyncDate(syncFhirProfile, "Patient"));
1050+
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getLastSyncDate(syncFhirProfile, "Patient"));
10351051

1052+
}
10361053
}
10371054

10381055
PersonSearchParams personSearchParams = new PersonSearchParams();
@@ -1052,7 +1069,7 @@ private Collection<IBaseResource> getPersonResourceBundle(SyncFhirProfile syncFh
10521069
}
10531070

10541071

1055-
private Collection<IBaseResource> getEncounterResourceBundle(List<Encounter> encounters) {
1072+
public Collection<IBaseResource> getEncounterResourceBundle(List<Encounter> encounters) {
10561073

10571074

10581075
Collection<String> encounterUUIDS = new ArrayList<>();
@@ -1072,39 +1089,41 @@ private Collection<IBaseResource> getEncounterResourceBundle(List<Encounter> enc
10721089
return iBaseResources;
10731090
}
10741091

1075-
private Collection<IBaseResource> getObservationResourceBundle(SyncFhirProfile syncFhirProfile, List<Encounter> encounterList, List<Person> personList) {
1076-
1077-
JSONObject searchParams = getSearchParametersInJsonObject("Observation", syncFhirProfile.getResourceSearchParameter());
1092+
public Collection<IBaseResource> getObservationResourceBundle(SyncFhirProfile syncFhirProfile, List<Encounter> encounterList, List<Person> personList) {
10781093

1079-
JSONArray codes = searchParams.getJSONArray("code");
10801094

10811095
List<Concept> conceptQuestionList = new ArrayList<>();
10821096

1083-
for (Object conceptUID : codes) {
1084-
try {
1097+
DateRangeParam lastUpdated = new DateRangeParam();
10851098

1086-
Concept concept = Context.getConceptService().getConcept(conceptUID.toString());
1087-
if (concept != null) {
1088-
conceptQuestionList.add(concept);
1089-
}
1099+
if (syncFhirProfile != null) {
1100+
JSONObject searchParams = getSearchParametersInJsonObject("Observation", syncFhirProfile.getResourceSearchParameter());
10901101

1091-
} catch (Exception e) {
1092-
log.error("Error while adding concept with uuid " + conceptUID, e);
1093-
}
1102+
JSONArray codes = searchParams.getJSONArray("code");
10941103

1095-
}
1104+
for (Object conceptUID : codes) {
1105+
try {
10961106

1097-
DateRangeParam lastUpdated = new DateRangeParam();
1107+
Concept concept = Context.getConceptService().getConcept(conceptUID.toString());
1108+
if (concept != null) {
1109+
conceptQuestionList.add(concept);
1110+
}
1111+
1112+
} catch (Exception e) {
1113+
log.error("Error while adding concept with uuid " + conceptUID, e);
1114+
}
10981115

1099-
if (syncFhirProfile.getIsCaseBasedProfile()) {
1100-
if (syncFhirCase != null && syncFhirCase.getLastUpdateDate() != null) {
1101-
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(syncFhirCase.getLastUpdateDate());
1102-
} else if (syncFhirCase != null) {
1103-
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getDefaultLastSyncDate());
11041116
}
1105-
} else {
1106-
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getLastSyncDate(syncFhirProfile, "Observation"));
1117+
if (syncFhirProfile.getIsCaseBasedProfile()) {
1118+
if (syncFhirCase != null && syncFhirCase.getLastUpdateDate() != null) {
1119+
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(syncFhirCase.getLastUpdateDate());
1120+
} else if (syncFhirCase != null) {
1121+
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getDefaultLastSyncDate());
1122+
}
1123+
} else {
1124+
lastUpdated = new DateRangeParam().setUpperBoundInclusive(new Date()).setLowerBoundInclusive(getLastSyncDate(syncFhirProfile, "Observation"));
11071125

1126+
}
11081127
}
11091128

11101129
List<Obs> observationList = Context.getObsService().getObservations(personList, encounterList, conceptQuestionList, null, null, null, null, null, null, getLastSyncDate(syncFhirProfile, "Observation"), new Date(), false);
@@ -1121,7 +1140,7 @@ private Collection<IBaseResource> getObservationResourceBundle(SyncFhirProfile s
11211140
}
11221141

11231142

1124-
private Collection<IBaseResource> getServiceRequestResourceBundle(List<Order> testOrders) {
1143+
public Collection<IBaseResource> getServiceRequestResourceBundle(List<Order> testOrders) {
11251144

11261145

11271146
Collection<String> testOrdersUUIDS = new ArrayList<>();

0 commit comments

Comments
 (0)