Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -752,13 +752,16 @@ private String encodeResourceToString(String resourceType, String identifierType

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

if (resourceType.equals("Patient") && profile != null && profile.getKeepProfileIdentifierOnly()) {
try {
jsonString = removeIdentifierExceptProfileId(jsonString, "identifier");
jsonString = addCodingToIdentifier(jsonString, "identifier");
jsonString = addCodingToSystemToPrimaryIdentifier(jsonString, "identifier");
} catch (Exception exception) {
log.error(exception);
if (resourceType.equals("Patient")) {
jsonString = correctEstimatedDOB(jsonString);
if (profile != null && profile.getKeepProfileIdentifierOnly()) {
try {
jsonString = removeIdentifierExceptProfileId(jsonString, "identifier");
jsonString = addCodingToIdentifier(jsonString, "identifier");
jsonString = addCodingToSystemToPrimaryIdentifier(jsonString, "identifier");
} catch (Exception exception) {
log.error(exception);
}
}
}
jsonString = addAttributeToObject(jsonString, "telecom", "system", "phone");
Expand Down Expand Up @@ -833,16 +836,27 @@ public String addCodingToIdentifier(String payload, String attributeName) {
for (Object jsonObject1 : jsonObject.getJSONArray(attributeName)) {
JSONObject jsonObject2 = new JSONObject(jsonObject1.toString());
PatientIdentifier patientIdentifier = Context.getPatientService().getPatientIdentifierByUuid(jsonObject2.get("id").toString());
if (patientIdentifier.getPatient().getBirthdateEstimated()) {
jsonObject.put("birthDate", patientIdentifier.getPatient().getBirthdate().toString().replace(" 00:00:00.0", ""));
}
jsonObject.getJSONArray(attributeName).getJSONObject(identifierCount).getJSONObject("type").put("coding", new JSONArray().put(new JSONObject().put("system", "UgandaEMR").put("code", patientIdentifier.getIdentifierType().getUuid())));
identifierCount++;
}
}
return jsonObject.toString();
}

private String correctEstimatedDOB(String payload) {
JSONObject jsonObject = new JSONObject(payload);

if (!jsonObject.has("id"))
return payload;

Patient patient = Context.getPatientService().getPatientByUuid(jsonObject.getString("id"));
if (patient.getBirthdateEstimated()) {
jsonObject.put("birthDate", patient.getBirthdate().toString().replace(" 00:00:00.0", ""));
}

return jsonObject.toString();
}

private String addAttributeToObject(String payload, String targetObject, String attributeName, String attributeValue) {
JSONObject jsonObject = new JSONObject(payload);
if (jsonObject.has(targetObject) && jsonObject.getJSONArray(targetObject).length() > 0) {
Expand Down Expand Up @@ -1096,7 +1110,7 @@ public Collection<IBaseResource> getObservationResourceBundle(SyncFhirProfile sy

JSONArray codes = searchParams.getJSONArray("code");

lastSyncDate=getLastSyncDate(syncFhirProfile, "Observation");
lastSyncDate = getLastSyncDate(syncFhirProfile, "Observation");
for (Object conceptUID : codes) {
try {

Expand Down Expand Up @@ -1366,7 +1380,7 @@ private Collection<IBaseResource> getDiagnosticReportResourceBundle(SyncFhirCase

}
}

if (!searchParams.isEmpty() && searchParams.has("code")) {
JSONArray codes = searchParams.getJSONArray("code");
for (Object conceptUID : codes) {
Expand All @@ -1381,7 +1395,7 @@ private Collection<IBaseResource> getDiagnosticReportResourceBundle(SyncFhirCase
}

ReferenceAndListParam patientReference = new ReferenceAndListParam();
if(syncFhirCase!=null) {
if (syncFhirCase != null) {
patientReference.addValue(new ReferenceOrListParam().add(new ReferenceParam(SP_IDENTIFIER, syncFhirCase.getPatient().getPatientIdentifier().getIdentifier())));
}

Expand Down