Skip to content

Commit

Permalink
Merge pull request #1986 from njorocs/hie-accreditation
Browse files Browse the repository at this point in the history
Hie accreditation
  • Loading branch information
patryllus authored Aug 24, 2024
2 parents 7b63676 + 6bde1eb commit 0e6e190
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static final class _LocationAttributeType {
public static final String TELEPHONE_FAX = "29e1e758-d03e-4e84-a55e-288fa63d533a";
public static final String SHA_ACCREDITATION = "7dbbfe5d-8a5a-4b24-897d-0cc5299c3dbb";
public static final String SHA_CONTRACTED_FACILITY = "68d9200e-a469-482f-8cc8-9d0953a3c917";
public static final String SHA_FACILITY_EXPIRY_DATE = "8e1ec5d4-4810-466a-9c90-b801bae9d063";
}

/**
Expand All @@ -73,6 +74,13 @@ public void install() throws Exception {
FreeTextDatatype.class, "", 0, 1,
_LocationAttributeType.SHA_CONTRACTED_FACILITY
));

install(locationAttributeType(
"Facility Expiry Date", "Expiry date for SHA contracted Facility",
FreeTextDatatype.class, "", 0, 1,
_LocationAttributeType.SHA_FACILITY_EXPIRY_DATE
));

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,52 @@ private static String getAuthCredentials() {

private static Map<String, String> extractFacilityStatus(String response) {
Map<String, String> statusMap = new HashMap<>();
statusMap.put("operationalStatus", "Unknown");
statusMap.put("approved", "Unknown");
statusMap.put("operationalStatus", "--");
statusMap.put("approved", "--");
statusMap.put("shaFacilityExpiryDate", "--");

try {
JSONObject jsonResponse = new JSONObject(response);
log.info("JSON Response: {}", jsonResponse.toString(2));

JSONArray extensions = jsonResponse.optJSONArray("extension");
if (extensions != null) {
for (int i = 0; i < extensions.length(); i++) {
JSONObject extension = extensions.optJSONObject(i);
if (extension != null) {
String url = extension.getString("url");
if ("https://shr.tiberbuapps.com/fhir/StructureDefinition/operational-status".equals(url)) {
statusMap.put("operationalStatus", extension.getJSONObject("valueCoding").getString("display"));
} else if ("https://shr.tiberbuapps.com/fhir/StructureDefinition/approved".equals(url)) {
statusMap.put("approved", extension.getJSONObject("valueCoding").getString("display"));
String url = extension.optString("url", "");
log.debug("Processing extension URL: {}", url);

switch (url) {
case "https://shr.tiberbuapps.com/fhir/StructureDefinition/operational-status":
statusMap.put("operationalStatus", extension.getJSONObject("valueCoding").optString("display", "--"));
break;

case "https://shr.tiberbuapps.com/fhir/StructureDefinition/approved":
statusMap.put("approved", extension.getJSONObject("valueCoding").optString("display", "--"));
break;

case "https://shr.tiberbuapps.com/fhir/StructureDefinition/facility-license-info":
JSONArray licenseExtensions = extension.optJSONArray("extension");
if (licenseExtensions != null) {
for (int j = 0; j < licenseExtensions.length(); j++) {
JSONObject licenseExtension = licenseExtensions.optJSONObject(j);
if (licenseExtension != null &&
"https://shr.tiberbuapps.com/fhir/StructureDefinition/last-expiry-date".equals(licenseExtension.optString("url", ""))) {
statusMap.put("shaFacilityExpiryDate", licenseExtension.optString("valueString", "--"));
}
}
}
break;
}
}
}
}
} catch (JSONException e) {
log.error("Error parsing facility status JSON: {}", e.getMessage());
logDiagnostics(response);
}

return statusMap;
}

Expand Down Expand Up @@ -173,8 +197,9 @@ public void saveFacilityStatus() {
if (responseEntity.getStatusCode().is2xxSuccessful()) {
Map<String, String> facilityStatus = extractFacilityStatus(responseEntity.getBody());

String operationalStatus = facilityStatus.getOrDefault("operationalStatus", "Unknown");
String approved = facilityStatus.getOrDefault("approved", "Unknown");
String operationalStatus = facilityStatus.getOrDefault("operationalStatus", "--");
String approved = facilityStatus.getOrDefault("approved", "--");
String facilityExpiryDate = facilityStatus.getOrDefault("facilityExpiryDate", "--");

final Location LOCATION = locationService.getLocation(LOCATION_ID);

Expand All @@ -184,6 +209,8 @@ public void saveFacilityStatus() {
// Handle SHA Facility Attribute
handleSHAFacilityAttribute(LOCATION, approved);

//Handle SHA facility expiry date
handleSHAFacilityExpiryDateAttribute(LOCATION, facilityExpiryDate);
} else {
log.error("Failed to save facility status: {}", responseEntity.getBody());
}
Expand Down Expand Up @@ -246,4 +273,31 @@ public void handleSHAFacilityAttribute(Location LOCATION, String approved) {
locationService.saveLocation(LOCATION);
log.info("Facility status for MFL Code {} saved successfully: , Approved: {}", MFL_CODE, approved);
}

public void handleSHAFacilityExpiryDateAttribute(Location LOCATION, String facilityExpiryDate) {
LocationAttributeType facilityExpiryDateAttributeType = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.SHA_FACILITY_EXPIRY_DATE);

LocationAttribute facilityExpiryDateAttribute = LOCATION.getActiveAttributes(facilityExpiryDateAttributeType)
.stream()
.filter(attr -> attr.getAttributeType().equals(facilityExpiryDateAttributeType))
.findFirst()
.orElse(null);

if (facilityExpiryDateAttribute == null) {
facilityExpiryDateAttribute = new LocationAttribute();
facilityExpiryDateAttribute.setAttributeType(facilityExpiryDateAttributeType);
facilityExpiryDateAttribute.setValue(facilityExpiryDate);
LOCATION.addAttribute(facilityExpiryDateAttribute);
log.info("SHA License expiry date attribute updated to new value: {}", facilityExpiryDate);
} else {
if (!facilityExpiryDate.equals(facilityExpiryDateAttribute.getValue())) {
facilityExpiryDateAttribute.setValue(facilityExpiryDate);
log.info("SHA Facility attribute updated to new value: {}", facilityExpiryDate);
} else {
log.info("No update needed.SHA Facility License expiry date attribute value is the same: {}", facilityExpiryDate);
}
}
locationService.saveLocation(LOCATION);
log.info("Facility SHA License expiry date for MFL Code {} saved successfully: , License expiry date: {}", MFL_CODE, facilityExpiryDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ public Object getDefaultConfiguredFacility() {
.findFirst()
.orElse(null);

LocationAttribute shaFacilityExpiryDate = location.getActiveAttributes(MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.SHA_FACILITY_EXPIRY_DATE))
.stream()
.filter(attr -> attr.getAttributeType().equals(MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.SHA_FACILITY_EXPIRY_DATE)))
.findFirst()
.orElse(null);

ObjectNode locationNode = JsonNodeFactory.instance.objectNode();

locationNode.put("locationId", location.getLocationId());
Expand All @@ -437,6 +443,7 @@ public Object getDefaultConfiguredFacility() {
locationNode.put("operationalStatus", operationalStatusAttribute != null ? operationalStatusAttribute.getValue().toString() : "--");
locationNode.put("operationalStatus", operationalStatusAttribute != null ? operationalStatusAttribute.getValue().toString() : "--");
locationNode.put("shaContracted", isSHAFacilityAttribute != null ? isSHAFacilityAttribute.getValue().toString() : "--" );
locationNode.put("shaFacilityExpiryDate", shaFacilityExpiryDate != null ? shaFacilityExpiryDate.getValue().toString() : "--" );

return locationNode.toString();

Expand Down

0 comments on commit 0e6e190

Please sign in to comment.