diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/dataExchange/FacilityDetailsDataExchange.java b/api/src/main/java/org/openmrs/module/kenyaemr/dataExchange/FacilityDetailsDataExchange.java new file mode 100644 index 000000000..4fa8aca4a --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/dataExchange/FacilityDetailsDataExchange.java @@ -0,0 +1,473 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.kenyaemr.dataExchange; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; +import org.apache.http.util.EntityUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.openmrs.Location; +import org.openmrs.LocationAttribute; +import org.openmrs.LocationAttributeType; +import org.openmrs.api.LocationService; +import org.openmrs.api.context.Context; +import org.openmrs.module.kenyaemr.metadata.CommonMetadata; +import org.openmrs.module.kenyaemr.metadata.FacilityMetadata; +import org.openmrs.module.metadatadeploy.MetadataUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; + +import static org.openmrs.module.kenyaemr.util.EmrUtils.*; +import static org.openmrs.module.kenyaemr.util.EmrUtils.getGlobalPropertyValue; + +/** + * A scheduled task that automatically updates the facility status. + */ +public class FacilityDetailsDataExchange { + private static final Logger log = LoggerFactory.getLogger(FacilityDetailsDataExchange.class); + + private static final LocationService locationService = Context.getLocationService(); + + private static final String BASE_URL_KEY = CommonMetadata.GP_HIE_BASE_END_POINT_URL; + private static final String API_USER_KEY = CommonMetadata.GP_HIE_API_USER; + private static final String API_SECRET_KEY = CommonMetadata.GP_SHA_FACILITY_VERIFICATION_GET_API_SECRET; + + public static ResponseEntity getFacilityStatus() { + + String bearerToken = getBearerToken(); + if (bearerToken.isEmpty()) { + log.error("Bearer token is missing"); + return ResponseEntity.badRequest().contentType(MediaType.APPLICATION_JSON).body("{\"status\": \"Error\"}"); + } + + try { + CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(createSslConnectionFactory()).build(); + HttpGet getRequest = new HttpGet(getGlobalPropertyValue(BASE_URL_KEY) + "fhir/Organization?identifierType=mfl-code&identifier=" + getMFLCode()); + + getRequest.setHeader("Authorization", "Bearer " + bearerToken); + + HttpResponse response = httpClient.execute(getRequest); + + int responseCode = response.getStatusLine().getStatusCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(createSuccessResponse(response)); + } else { + log.error("Error: failed to connect: {}", responseCode); + return ResponseEntity.badRequest().contentType(MediaType.APPLICATION_JSON).body("{\"status\": \"Error\"}"); + } + } catch (Exception ex) { + log.error("Error fetching facility status: {}", ex.getMessage()); + return ResponseEntity.badRequest().contentType(MediaType.APPLICATION_JSON).body("{\"status\": \"Error\"}"); + } + } + + private static SSLConnectionSocketFactory createSslConnectionFactory() throws Exception { + return new SSLConnectionSocketFactory( + SSLContexts.createDefault(), + new String[]{"TLSv1.2"}, + null, + SSLConnectionSocketFactory.getDefaultHostnameVerifier() + ); + } + + private static String getBearerToken() { + String username = getGlobalPropertyValue(API_USER_KEY); + String secret = getGlobalPropertyValue(API_SECRET_KEY); + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpGet getRequest = new HttpGet(getGlobalPropertyValue(BASE_URL_KEY) + "hie-auth?key=" + username); + getRequest.setHeader("Content-Type", "application/x-www-form-urlencoded"); + getRequest.setHeader("Authorization", createBasicAuthHeader(username, secret)); + + try (CloseableHttpResponse response = httpClient.execute(getRequest)) { + + if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK) { + String responseString = EntityUtils.toString(response.getEntity()).trim(); + log.info("Bearer token retrieved successfully..."); + return responseString; + } else { + log.error("Failed to fetch Bearer Token. HTTP Status: {}", response.getStatusLine().getStatusCode()); + } + } + } catch (Exception e) { + log.error("Error retrieving Bearer Token: {}", e.getMessage()); + } + return ""; + } + + private static String createBasicAuthHeader(String username, String password) { + String credentials = username + ":" + password; + return "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.UTF_8)); + } + + private static Map extractFacilityStatus(String organizationResourceResponse) { + Map statusMap = new HashMap<>(); + statusMap.put("operationalStatus", "--"); + statusMap.put("kephLevel", "--"); + statusMap.put("approved", "--"); + statusMap.put("shaFacilityExpiryDate", "--"); + statusMap.put("shaFacilityId", "--"); + statusMap.put("shaFacilityLicenseNumber", "--"); + statusMap.put("shaFacilityReferencePayload", "--"); + + try { + JSONObject jsonResponse = new JSONObject(organizationResourceResponse); + log.info("JSON Response: {}", jsonResponse.toString(2)); + + statusMap.put("shaFacilityReferencePayload", organizationResourceResponse); + + JSONArray entries = jsonResponse.optJSONArray("entry"); + if (entries != null && !entries.isEmpty()) { + JSONObject resource = entries.getJSONObject(0).optJSONObject("resource"); + if (resource != null && "Organization".equals(resource.optString("resourceType"))) { + // Extract "id" + String resourceId = resource.optString("id", "--"); + statusMap.put("shaFacilityId", resourceId); + + JSONArray extensions = resource.optJSONArray("extension"); + if (extensions != null) { + for (int i = 0; i < extensions.length(); i++) { + + JSONObject extension = extensions.optJSONObject(i); + String url = extension.optString("url"); + + switch (url) { + case "https://fr-kenyahie/StructureDefinition/license-status": + statusMap.put("operationalStatus", extension.optString("valueString", "--")); + break; + + case "https://fr-kenyahie/StructureDefinition/keph-level": + JSONObject valueCodeableConcept = extension.optJSONObject("valueCodeableConcept"); + if (valueCodeableConcept != null) { + JSONArray coding = valueCodeableConcept.optJSONArray("coding"); + if (coding != null && !coding.isEmpty()) { + statusMap.put("kephLevel", coding.getJSONObject(0).optString("display", "--")); + } + } + break; + //TODO: Get url for SHA accreditation. + case "https://shr.tiberbuapps.com/fhir/StructureDefinition/approved": + JSONObject valueCoding = extension.optJSONObject("valueCoding"); + if (valueCoding != null) { + statusMap.put("approved", valueCoding.optString("display", "--")); + } + break; + } + } + } + JSONArray identifiers = resource.optJSONArray("identifier"); + if (identifiers != null) { + for (int i = 0; i < identifiers.length(); i++) { + JSONObject identifier = identifiers.getJSONObject(i); + + // Check for "license-number" + JSONArray codingArray = identifier.optJSONObject("type") + .optJSONArray("coding"); + if (codingArray != null) { + for (int j = 0; j < codingArray.length(); j++) { + JSONObject coding = codingArray.getJSONObject(j); + String code = coding.optString("code"); + + if ("license-number".equals(code)) { + statusMap.put("shaFacilityLicenseNumber", identifier.optString("value", "--")); + } + } + } + // Check for "end" in "period" + JSONObject period = identifier.optJSONObject("period"); + if (period != null) { + String end = period.optString("end", "--"); + statusMap.put("shaFacilityExpiryDate", end); + break; + } + } + } + } + } + return statusMap; + + } catch (JSONException e) { + log.error("Error parsing facility status JSON: {}", e.getMessage()); + logDiagnostics(organizationResourceResponse); + } + return statusMap; + } + + private static void logDiagnostics(String response) { + try { + JSONObject jsonObject = new JSONObject(response); + JSONArray issueArray = jsonObject.optJSONArray("issue"); + + if (issueArray != null && !issueArray.isEmpty()) { + String diagnostics = issueArray.getJSONObject(0).optString("diagnostics", "mlf code not found"); + log.error("Diagnostics: {}", diagnostics); + } + } catch (JSONException e) { + log.error("Failed to parse JSON diagnostics: {}", e.getMessage()); + } + } + + private static String createSuccessResponse(HttpResponse response) { + try { + return EntityUtils.toString(response.getEntity()); + } catch (IOException e) { + throw new RuntimeException("Error parsing response", e); + } + } + + public static void saveFacilityStatus() { + try { + ResponseEntity responseEntity = getFacilityStatus(); + if (responseEntity.getStatusCode().is2xxSuccessful()) { + Map facilityStatus = extractFacilityStatus(responseEntity.getBody()); + + String operationalStatus = facilityStatus.getOrDefault("operationalStatus", "--"); + String kephLevel = facilityStatus.getOrDefault("kephLevel", "--"); + String approved = facilityStatus.getOrDefault("approved", "--"); + String shaFacilityExpiryDate = facilityStatus.getOrDefault("shaFacilityExpiryDate", "--"); + String shaFacilityLicenseNumber = facilityStatus.getOrDefault("shaFacilityLicenseNumber", "--"); + String shaFacilityId = facilityStatus.getOrDefault("shaFacilityId", "--"); + String shaFacilityReferencePayload = facilityStatus.getOrDefault("shaFacilityReferencePayload", "--"); + + final Location location = locationService.getLocation(LOCATION_ID); + + // Handle SHA Accreditation Attribute + handleSHAAccreditationAttribute(location, operationalStatus); + + // Handle KMPDC facility classification Attribute + handleKephLevelAttribute(location, kephLevel); + + // Handle SHA Facility Attribute + handleSHAFacilityAttribute(location, approved); + + //Handle SHA facility expiry date + handleSHAFacilityLicenseExpiryDateAttribute(location, shaFacilityExpiryDate); + + //Handle SHA facility License number + handleSHAFacilityLicenseNumberAttribute(location, shaFacilityLicenseNumber); + + //Handle SHA facility id + handleSHAFacilityIdAttribute(location, shaFacilityId); + + // Handle SHA Facility reference payload attribute + handleFacilityReferencePayloadAttribute(location, shaFacilityReferencePayload); + } else { + log.error("Failed to save facility status: {}", responseEntity.getBody()); + } + } catch (Exception e) { + log.error("Error in saving Facility Status: ", e); + throw e; + } + } + + private static void handleFacilityReferencePayloadAttribute(Location location, String shaFacilityReferencePayload) { + LocationAttributeType shaFacilityReferencePayloadType = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_HIE_FHIR_REFERENCE); + + LocationAttribute shaFacilityReferencePayloadAttribute = location.getActiveAttributes(shaFacilityReferencePayloadType) + .stream() + .filter(attr -> attr.getAttributeType().equals(shaFacilityReferencePayloadType)) + .findFirst() + .orElse(null); + + if (shaFacilityReferencePayloadAttribute == null) { + shaFacilityReferencePayloadAttribute = new LocationAttribute(); + shaFacilityReferencePayloadAttribute.setAttributeType(shaFacilityReferencePayloadType); + shaFacilityReferencePayloadAttribute.setValue(shaFacilityReferencePayload); + location.addAttribute(shaFacilityReferencePayloadAttribute); + log.info("New Facility reference payload attribute created: {}", shaFacilityReferencePayload); + } else { + if (!shaFacilityReferencePayload.equals(shaFacilityReferencePayloadAttribute.getValue())) { + shaFacilityReferencePayloadAttribute.setValue(shaFacilityReferencePayload); + log.info("SHA Facility reference payload attribute updated to new value: {}", shaFacilityReferencePayload); + } else { + log.info("No update needed. Facility reference payload attribute value is the same: {}", shaFacilityReferencePayload); + } + } + locationService.saveLocation(location); + log.info("Facility status for MFL Code {} saved successfully: Facility reference payload: {}", getMFLCode(), shaFacilityReferencePayload); + } + + private static void handleKephLevelAttribute(Location location, String kephLevel) { + LocationAttributeType shaKephLevelType = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_KEPH_LEVEL); + + LocationAttribute shaKephLevelAttribute = location.getActiveAttributes(shaKephLevelType) + .stream() + .filter(attr -> attr.getAttributeType().equals(shaKephLevelType)) + .findFirst() + .orElse(null); + + if (shaKephLevelAttribute == null) { + shaKephLevelAttribute = new LocationAttribute(); + shaKephLevelAttribute.setAttributeType(shaKephLevelType); + shaKephLevelAttribute.setValue(kephLevel); + location.addAttribute(shaKephLevelAttribute); + log.info("New Keph Level attribute created: {}", kephLevel); + } else { + if (!kephLevel.equals(shaKephLevelAttribute.getValue())) { + shaKephLevelAttribute.setValue(kephLevel); + log.info("SHA Keph Level attribute updated to new value: {}", kephLevel); + } else { + log.info("No update needed. Keph Level value is the same: {}", kephLevel); + } + } + locationService.saveLocation(location); + log.info("Keph Level for MFL Code {} saved successfully: Keph Level: {}", getMFLCode(), kephLevel); + } + + public static void handleSHAAccreditationAttribute(Location location, String operationalStatus) { + LocationAttributeType shaAccreditationType = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.SHA_ACCREDITATION); + + LocationAttribute shaAccreditationAttribute = location.getActiveAttributes(shaAccreditationType) + .stream() + .filter(attr -> attr.getAttributeType().equals(shaAccreditationType)) + .findFirst() + .orElse(null); + + if (shaAccreditationAttribute == null) { + shaAccreditationAttribute = new LocationAttribute(); + shaAccreditationAttribute.setAttributeType(shaAccreditationType); + shaAccreditationAttribute.setValue(operationalStatus); + location.addAttribute(shaAccreditationAttribute); + log.info("New SHA Accreditation attribute created and set: {}", operationalStatus); + } else { + if (!operationalStatus.equals(shaAccreditationAttribute.getValue())) { + shaAccreditationAttribute.setValue(operationalStatus); + log.info("SHA Accreditation attribute updated to new value: {}", operationalStatus); + } else { + log.info("No update needed. SHA Accreditation attribute value is the same: {}", operationalStatus); + } + } + locationService.saveLocation(location); + log.info("Facility status for MFL Code {} saved successfully: Operational Status: {}", getMFLCode(), operationalStatus); + } + + public static void handleSHAFacilityAttribute(Location location, String approved) { + LocationAttributeType isSHAFacility = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.SHA_CONTRACTED_FACILITY); + + LocationAttribute isSHAFacilityAttribute = location.getActiveAttributes(isSHAFacility) + .stream() + .filter(attr -> attr.getAttributeType().equals(isSHAFacility)) + .findFirst() + .orElse(null); + + if (isSHAFacilityAttribute == null) { + isSHAFacilityAttribute = new LocationAttribute(); + isSHAFacilityAttribute.setAttributeType(isSHAFacility); + isSHAFacilityAttribute.setValue(approved); + location.addAttribute(isSHAFacilityAttribute); + log.info("New SHA Facility attribute created and set: {}", approved); + } else { + if (!approved.equals(isSHAFacilityAttribute.getValue())) { + isSHAFacilityAttribute.setValue(approved); + log.info("SHA Facility attribute updated to new value: {}", approved); + } else { + log.info("No update needed. SHA Facility attribute value is the same: {}", approved); + } + } + locationService.saveLocation(location); + log.info("Facility status for MFL Code {} saved successfully: , Approved: {}", getMFLCode(), approved); + } + + public static void handleSHAFacilityLicenseExpiryDateAttribute(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: {}", getMFLCode(), facilityExpiryDate); + } + + public static void handleSHAFacilityIdAttribute(Location location, String facilityId) { + LocationAttributeType facilityIdAttributeType = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_REGISTRY_CODE); + + LocationAttribute facilityIdAttribute = location.getActiveAttributes(facilityIdAttributeType) + .stream() + .filter(attr -> attr.getAttributeType().equals(facilityIdAttributeType)) + .findFirst() + .orElse(null); + + if (facilityIdAttribute == null) { + facilityIdAttribute = new LocationAttribute(); + facilityIdAttribute.setAttributeType(facilityIdAttributeType); + facilityIdAttribute.setValue(facilityId); + location.addAttribute(facilityIdAttribute); + log.info("Facility Id attribute updated to new value: {}", facilityId); + } else { + if (!facilityId.equals(facilityIdAttribute.getValue())) { + facilityIdAttribute.setValue(facilityId); + log.info("Facility Id updated to new value: {}", facilityId); + } else { + log.info("No update needed. Facility Id is the same: {}", facilityId); + } + } + locationService.saveLocation(location); + log.info("Facility Id for MFL Code {} saved successfully: , Facility Id: {}", getMFLCode(), facilityId); + } + + public static void handleSHAFacilityLicenseNumberAttribute(Location location, String facilityLicenseNumber) { + LocationAttributeType facilityLicenseNumberAttributeType = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_LICENSE_NUMBER); + + LocationAttribute facilityLicenseNumberAttribute = location.getActiveAttributes(facilityLicenseNumberAttributeType) + .stream() + .filter(attr -> attr.getAttributeType().equals(facilityLicenseNumberAttributeType)) + .findFirst() + .orElse(null); + + if (facilityLicenseNumberAttribute == null) { + facilityLicenseNumberAttribute = new LocationAttribute(); + facilityLicenseNumberAttribute.setAttributeType(facilityLicenseNumberAttributeType); + facilityLicenseNumberAttribute.setValue(facilityLicenseNumber); + location.addAttribute(facilityLicenseNumberAttribute); + log.info("License number attribute updated to new value: {}", facilityLicenseNumber); + } else { + if (!facilityLicenseNumber.equals(facilityLicenseNumberAttribute.getValue())) { + facilityLicenseNumberAttribute.setValue(facilityLicenseNumber); + log.info("Facility license number updated to new value: {}", facilityLicenseNumber); + } else { + log.info("No update needed.SHA Facility License number is the same: {}", facilityLicenseNumber); + } + } + locationService.saveLocation(location); + log.info("Facility License number for MFL Code {} saved successfully: , License number: {}", getMFLCode(), facilityLicenseNumber); + } +} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/metadata/CommonMetadata.java b/api/src/main/java/org/openmrs/module/kenyaemr/metadata/CommonMetadata.java index 6a62923b9..445d5d126 100755 --- a/api/src/main/java/org/openmrs/module/kenyaemr/metadata/CommonMetadata.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/metadata/CommonMetadata.java @@ -45,8 +45,8 @@ public class CommonMetadata extends AbstractMetadataBundle { public static final String GP_CLIENT_VERIFICATION_EMR_VERIFICATION_PROXY_URL = "kenyaemr.client.registry.emr.verification.proxy.url"; public static final String GP_CLIENT_VERIFICATION_GET_END_POINT = "kenyaemr.client.registry.get.api"; public static final String GP_SHA_CLIENT_VERIFICATION_GET_END_POINT = "kenyaemr.sha.registry.get.api"; - public static final String GP_SHA_FACILITY_VERIFICATION_GET_END_POINT = "kenyaemr.sha.facilityregistry.get.api"; - public static final String GP_SHA_FACILITY_VERIFICATION_GET_API_USER = "kenyaemr.sha.facilityregistry.get.api.user"; + public static final String GP_HIE_BASE_END_POINT_URL = "kenyaemr.sha.facilityregistry.get.api"; + public static final String GP_HIE_API_USER = "kenyaemr.sha.facilityregistry.get.api.user"; public static final String GP_SHA_FACILITY_VERIFICATION_GET_API_SECRET = "kenyaemr.sha.facilityregistry.get.api.secret"; public static final String GP_SHA_HEALTH_WORKER_VERIFICATION_GET_END_POINT = "kenyaemr.sha.healthworker.registry.get.api"; public static final String GP_SHA_HEALTH_WORKER_VERIFICATION_GET_API_USER = "kenyaemr.sha.healthworker.get.api.user"; @@ -426,11 +426,11 @@ public void install() { if(administrationService.getGlobalPropertyObject(CommonMetadata.GP_SHA_CLIENT_VERIFICATION_GET_END_POINT) == null) { install(globalProperty(GP_SHA_CLIENT_VERIFICATION_GET_END_POINT, "A GET API for getting SHA client information from the client registry", "http://127.0.0.1:9342/api/shaPatientResource")); } - if(administrationService.getGlobalPropertyObject(CommonMetadata.GP_SHA_FACILITY_VERIFICATION_GET_END_POINT) == null) { - install(globalProperty(GP_SHA_FACILITY_VERIFICATION_GET_END_POINT, "A GET API for getting SHA Facility status information from the registry", "https://sandbox.tiberbu.health/api/v4/")); + if(administrationService.getGlobalPropertyObject(CommonMetadata.GP_HIE_BASE_END_POINT_URL) == null) { + install(globalProperty(GP_HIE_BASE_END_POINT_URL, "A GET API for HIE registry", "https://api.dha.go.ke/v1/")); } if(administrationService.getGlobalPropertyObject(CommonMetadata.GP_SHA_HEALTH_WORKER_VERIFICATION_GET_END_POINT) == null) { - install(globalProperty(GP_SHA_HEALTH_WORKER_VERIFICATION_GET_END_POINT, "A GET API for getting SHA Health Worker information from Healthcare Worker registry", "https://sandbox.tiberbu.health/api/v4")); + install(globalProperty(GP_SHA_HEALTH_WORKER_VERIFICATION_GET_END_POINT, "A GET API for getting SHA Health Worker information from Healthcare Worker registry", "https://api.dha.go.ke/v1/")); } if(administrationService.getGlobalPropertyObject(CommonMetadata.GP_SHA_HEALTH_WORKER_VERIFICATION_GET_API_USER) == null) { install(globalProperty(GP_SHA_HEALTH_WORKER_VERIFICATION_GET_API_USER, "API user for for connecting to the SHA provider registry", "")); @@ -445,8 +445,8 @@ public void install() { if(administrationService.getGlobalPropertyObject(CommonMetadata.GP_SHA_CLIENT_VERIFICATION_GET_API_SECRET) == null) { install(globalProperty(GP_SHA_CLIENT_VERIFICATION_GET_API_SECRET, "API secret token for for connecting to the SHA client registry", "")); } - if(administrationService.getGlobalPropertyObject(CommonMetadata.GP_SHA_FACILITY_VERIFICATION_GET_API_USER) == null) { - install(globalProperty(GP_SHA_FACILITY_VERIFICATION_GET_API_USER, "API user for for connecting to the SHA Facility registry", "")); + if(administrationService.getGlobalPropertyObject(CommonMetadata.GP_HIE_API_USER) == null) { + install(globalProperty(GP_HIE_API_USER, "API user for for connecting to the SHA Facility registry", "")); } if(administrationService.getGlobalPropertyObject(CommonMetadata.GP_SHA_FACILITY_VERIFICATION_GET_API_SECRET) == null) { install(globalProperty(GP_SHA_FACILITY_VERIFICATION_GET_API_SECRET, "API secret token for for connecting to the SHA facility registry", "")); diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/metadata/FacilityMetadata.java b/api/src/main/java/org/openmrs/module/kenyaemr/metadata/FacilityMetadata.java index cb270d0af..562ef2ab7 100755 --- a/api/src/main/java/org/openmrs/module/kenyaemr/metadata/FacilityMetadata.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/metadata/FacilityMetadata.java @@ -50,6 +50,8 @@ public static final class _LocationAttributeType { public static final String SHA_FACILITY_EXPIRY_DATE = "8e1ec5d4-4810-466a-9c90-b801bae9d063"; public static final String FACILITY_KEPH_LEVEL = "0233ba94-22d2-4658-81c3-2cf00fca382d"; public static final String FACILITY_HIE_FHIR_REFERENCE = "682f0a48-a642-491b-aa6d-41084bee0ee0"; + public static final String FACILITY_REGISTRY_CODE = "1d1e2531-6a4a-4ed9-ab0a-02663e82379c"; + public static final String FACILITY_LICENSE_NUMBER = "5f719dc5-3a70-48e5-8404-90bbcc35b36e"; } /** @@ -95,6 +97,17 @@ public void install() throws Exception { _LocationAttributeType.FACILITY_HIE_FHIR_REFERENCE )); + install(locationAttributeType( + "Facility License Number", "Facility License Number", + FreeTextDatatype.class, "", 0, 1, + _LocationAttributeType.FACILITY_LICENSE_NUMBER + )); + + install(locationAttributeType( + "Facility Registry Code", "Facility Registry Code", + FreeTextDatatype.class, "", 0, 1, + _LocationAttributeType.FACILITY_REGISTRY_CODE + )); } /** diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/task/FacilityStatusTask.java b/api/src/main/java/org/openmrs/module/kenyaemr/task/FacilityStatusTask.java deleted file mode 100644 index 8c35f7ebb..000000000 --- a/api/src/main/java/org/openmrs/module/kenyaemr/task/FacilityStatusTask.java +++ /dev/null @@ -1,308 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.kenyaemr.task; - -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContexts; -import org.apache.http.util.EntityUtils; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.openmrs.GlobalProperty; -import org.openmrs.Location; -import org.openmrs.LocationAttribute; -import org.openmrs.LocationAttributeType; -import org.openmrs.api.AdministrationService; -import org.openmrs.api.LocationService; -import org.openmrs.api.context.Context; -import org.openmrs.module.kenyaemr.api.KenyaEmrService; -import org.openmrs.module.kenyaemr.metadata.CommonMetadata; -import org.openmrs.module.kenyaemr.metadata.FacilityMetadata; -import org.openmrs.module.metadatadeploy.MetadataUtils; -import org.openmrs.scheduler.tasks.AbstractTask; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; - -/** - * A scheduled task that automatically updates the facility status. - */ -public class FacilityStatusTask extends AbstractTask { - private static final Logger log = LoggerFactory.getLogger(FacilityStatusTask.class); - private static final AdministrationService administrationService = Context.getAdministrationService(); - private static final LocationService locationService = Context.getLocationService(); - private static final Integer LOCATION_ID = Integer.parseInt(administrationService.getGlobalProperty("kenyaemr.defaultLocation")); - private static final String GP_MFL_CODE = administrationService.getGlobalProperty("facility.mflcode").trim(); - private static final String BASE_URL_KEY = CommonMetadata.GP_SHA_FACILITY_VERIFICATION_GET_END_POINT; - private static final String API_USER_KEY = CommonMetadata.GP_SHA_FACILITY_VERIFICATION_GET_API_USER; - private static final String API_SECRET_KEY = CommonMetadata.GP_SHA_FACILITY_VERIFICATION_GET_API_SECRET; - private static final String DEFAULT_BASE_URL = "https://sandbox.tiberbu.health/api/v4"; - private static final String DEFAULT_MFL_CODE = Context.getService(KenyaEmrService.class).getDefaultLocationMflCode().trim(); - - @Override - public void execute() { - if (!isExecuting) { - log.debug("Starting Facility Status Task..."); - startExecuting(); - try { - saveFacilityStatus(); - } catch (Exception e) { - log.error("Error during facility status update", e); - } finally { - stopExecuting(); - } - } - } - - public static ResponseEntity getFacilityStatus() { - String auth = getAuthCredentials(); - - if (auth.isEmpty()) { - log.error("Configure authentication credentials"); - return ResponseEntity.badRequest().contentType(MediaType.APPLICATION_JSON).body("{\"status\": \"Error\"}"); - } - - try { - CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(createSslConnectionFactory()).build(); - HttpGet getRequest = new HttpGet(getBaseUrl() + "/Organization?facility-code=" + getMFLCode()); - getRequest.setHeader("Authorization", "Basic " + auth); - - HttpResponse response = httpClient.execute(getRequest); - - int responseCode = response.getStatusLine().getStatusCode(); - if (responseCode == HttpURLConnection.HTTP_OK) { - return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(createSuccessResponse(response)); - } else { - log.error("Error: failed to connect: {}", responseCode); - return ResponseEntity.badRequest().contentType(MediaType.APPLICATION_JSON).body("{\"status\": \"Error\"}"); - } - } catch (Exception ex) { - log.error("Error fetching facility status: {}", ex.getMessage()); - return ResponseEntity.badRequest().contentType(MediaType.APPLICATION_JSON).body("{\"status\": \"Error\"}"); - } - } - - private static SSLConnectionSocketFactory createSslConnectionFactory() throws Exception { - return new SSLConnectionSocketFactory( - SSLContexts.createDefault(), - new String[]{"TLSv1.2"}, - null, - SSLConnectionSocketFactory.getDefaultHostnameVerifier() - ); - } - - private static String getBaseUrl() { - GlobalProperty globalGetUrl = administrationService.getGlobalPropertyObject(BASE_URL_KEY); - return globalGetUrl.getPropertyValue() != null ? globalGetUrl.getPropertyValue().trim() : DEFAULT_BASE_URL.trim(); - } - private static String getMFLCode() { - return GP_MFL_CODE != null ? GP_MFL_CODE : DEFAULT_MFL_CODE; - } - - private static String getAuthCredentials() { - String username = administrationService.getGlobalPropertyObject(API_USER_KEY).getPropertyValue(); - String password = administrationService.getGlobalPropertyObject(API_SECRET_KEY).getPropertyValue(); - return Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); - } - - private static Map extractFacilityStatus(String response) { - Map statusMap = new HashMap<>(); - 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.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; - } - - private static void logDiagnostics(String response) { - try { - JSONObject jsonObject = new JSONObject(response); - JSONArray issueArray = jsonObject.optJSONArray("issue"); - - if (issueArray != null && !issueArray.isEmpty()) { - String diagnostics = issueArray.getJSONObject(0).optString("diagnostics", "mlf code not found"); - log.error("Diagnostics: {}", diagnostics); - } - } catch (JSONException e) { - log.error("Failed to parse JSON diagnostics: {}", e.getMessage()); - } - } - - private static String createSuccessResponse(HttpResponse response) { - try { - return EntityUtils.toString(response.getEntity()); - } catch (IOException e) { - throw new RuntimeException("Error parsing response", e); - } - } - - public void saveFacilityStatus() { - try { - ResponseEntity responseEntity = getFacilityStatus(); - if (responseEntity.getStatusCode().is2xxSuccessful()) { - Map facilityStatus = extractFacilityStatus(responseEntity.getBody()); - - String operationalStatus = facilityStatus.getOrDefault("operationalStatus", "--"); - String approved = facilityStatus.getOrDefault("approved", "--"); - String facilityExpiryDate = facilityStatus.getOrDefault("facilityExpiryDate", "--"); - - final Location LOCATION = locationService.getLocation(LOCATION_ID); - - // Handle SHA Accreditation Attribute - handleSHAAccreditationAttribute(LOCATION, operationalStatus); - - // 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()); - } - } catch (Exception e) { - log.error("Error in saving Facility Status: ", e); - throw e; - } - } - - public void handleSHAAccreditationAttribute(Location LOCATION, String operationalStatus) { - LocationAttributeType shaAccreditationType = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.SHA_ACCREDITATION); - - LocationAttribute shaAccreditationAttribute = LOCATION.getActiveAttributes(shaAccreditationType) - .stream() - .filter(attr -> attr.getAttributeType().equals(shaAccreditationType)) - .findFirst() - .orElse(null); - - if (shaAccreditationAttribute == null) { - shaAccreditationAttribute = new LocationAttribute(); - shaAccreditationAttribute.setAttributeType(shaAccreditationType); - shaAccreditationAttribute.setValue(operationalStatus); - LOCATION.addAttribute(shaAccreditationAttribute); - log.info("New SHA Accreditation attribute created and set: {}", operationalStatus); - } else { - if (!operationalStatus.equals(shaAccreditationAttribute.getValue())) { - shaAccreditationAttribute.setValue(operationalStatus); - log.info("SHA Accreditation attribute updated to new value: {}", operationalStatus); - } else { - log.info("No update needed. SHA Accreditation attribute value is the same: {}", operationalStatus); - } - } - locationService.saveLocation(LOCATION); - log.info("Facility status for MFL Code {} saved successfully: Operational Status: {}", getMFLCode(), operationalStatus); - } - - public void handleSHAFacilityAttribute(Location LOCATION, String approved) { - LocationAttributeType isSHAFacility = MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.SHA_CONTRACTED_FACILITY); - - LocationAttribute isSHAFacilityAttribute = LOCATION.getActiveAttributes(isSHAFacility) - .stream() - .filter(attr -> attr.getAttributeType().equals(isSHAFacility)) - .findFirst() - .orElse(null); - - if (isSHAFacilityAttribute == null) { - isSHAFacilityAttribute = new LocationAttribute(); - isSHAFacilityAttribute.setAttributeType(isSHAFacility); - isSHAFacilityAttribute.setValue(approved); - LOCATION.addAttribute(isSHAFacilityAttribute); - log.info("New SHA Facility attribute created and set: {}", approved); - } else { - if (!approved.equals(isSHAFacilityAttribute.getValue())) { - isSHAFacilityAttribute.setValue(approved); - log.info("SHA Facility attribute updated to new value: {}", approved); - } else { - log.info("No update needed. SHA Facility attribute value is the same: {}", approved); - } - } - locationService.saveLocation(LOCATION); - log.info("Facility status for MFL Code {} saved successfully: , Approved: {}", getMFLCode(), 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: {}", getMFLCode(), facilityExpiryDate); - } -} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/util/EmrUtils.java b/api/src/main/java/org/openmrs/module/kenyaemr/util/EmrUtils.java index 8f4ad3922..e18d60b7e 100755 --- a/api/src/main/java/org/openmrs/module/kenyaemr/util/EmrUtils.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/util/EmrUtils.java @@ -27,14 +27,13 @@ import org.openmrs.OrderType; import org.openmrs.Patient; import org.openmrs.Person; -import org.openmrs.PersonAttribute; -import org.openmrs.PersonAttributeType; import org.openmrs.Provider; import org.openmrs.User; +import org.openmrs.api.AdministrationService; import org.openmrs.api.EncounterService; import org.openmrs.api.context.Context; import org.openmrs.module.kenyaemr.Dictionary; -import org.openmrs.module.kenyaemr.metadata.CommonMetadata; +import org.openmrs.module.kenyaemr.api.KenyaEmrService; import org.openmrs.util.PrivilegeConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -60,7 +59,9 @@ public class EmrUtils { protected static final Log log = LogFactory.getLog(EmrUtils.class); public static String GP_2X_FORMS_WHITELIST = "kenyaemr.2.x.forms.whitelist"; - + private static final String DEFAULT_GLOBAL_PROPERTY_KEY = "facility.mflcode"; + private static final AdministrationService administrationService = Context.getAdministrationService(); + public static final Integer LOCATION_ID = Integer.parseInt(administrationService.getGlobalProperty("kenyaemr.defaultLocation")); /** * Checks whether a date has any time value * @param date the date @@ -378,4 +379,38 @@ public static String formatListWithQuotes(ArrayList list) { return joiner.toString(); } + /** + * Helper method for getting mfl code for a facility + * @return + */ + public static String getMFLCode() { + + KenyaEmrService kenyaEmrService = Context.getService(KenyaEmrService.class); + String defaultMflCode = null; + String globalPropertyMflCode = null; + + try { + // Fetch the default MFL code from the KenyaEmrService + defaultMflCode = kenyaEmrService != null ? kenyaEmrService.getDefaultLocationMflCode() : null; + if (defaultMflCode != null) { + defaultMflCode = defaultMflCode.trim(); + } + + // Fetch the global property for the MFL code + globalPropertyMflCode = Context.getAdministrationService().getGlobalProperty(DEFAULT_GLOBAL_PROPERTY_KEY); + if (globalPropertyMflCode != null) { + globalPropertyMflCode = globalPropertyMflCode.trim(); + } + } catch (Exception e) { + log.error("Error retrieving MFL Code: {}", e); + } + + // Return the global property MFL code if available, otherwise fallback to default + return globalPropertyMflCode != null ? globalPropertyMflCode : defaultMflCode; + } + + public static String getGlobalPropertyValue(String value) { + GlobalProperty result = administrationService.getGlobalPropertyObject(value); + return result.getPropertyValue() != null ? result.getPropertyValue().trim() : ""; + } } \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java b/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java index d2b22a32e..ea7ef8e63 100644 --- a/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java +++ b/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java @@ -8,8 +8,6 @@ * graphic logo is a trademark of OpenMRS Inc. */ package org.openmrs.module.kenyaemr.web.controller; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -26,6 +24,7 @@ import org.openmrs.calculation.patient.PatientCalculationContext; import org.openmrs.calculation.result.ListResult; import org.openmrs.module.kenyaemr.metadata.*; +import org.openmrs.module.kenyaemr.dataExchange.FacilityDetailsDataExchange; import org.openmrs.module.metadatadeploy.MetadataUtils; import org.openmrs.module.kenyaemrorderentry.util.Utils; import org.openmrs.module.kenyaemr.calculation.library.tb.TbDiseaseClassificationCalculation; @@ -107,13 +106,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContexts; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; import org.codehaus.jackson.node.ArrayNode; import org.codehaus.jackson.node.JsonNodeFactory; import org.codehaus.jackson.node.ObjectNode; @@ -132,8 +124,6 @@ import java.io.PrintStream; import java.net.HttpURLConnection; import java.net.URL; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.ArrayList; @@ -142,7 +132,6 @@ import org.joda.time.Years; import java.util.HashSet; import java.util.Set; -import java.util.stream.Collectors; import java.util.Collections; import java.util.Locale; import java.util.Comparator; @@ -481,6 +470,9 @@ public Object getRegimenHistory(@RequestParam("patientUuid") String patientUuid, @RequestMapping(method = RequestMethod.GET, value = "/default-facility") @ResponseBody public Object getDefaultConfiguredFacility() { + + FacilityDetailsDataExchange.saveFacilityStatus(); + GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(EmrConstants.GP_DEFAULT_LOCATION); if (gp == null) { @@ -507,14 +499,33 @@ public Object getDefaultConfiguredFacility() { .findFirst() .orElse(null); + LocationAttribute shaKephLevelAttribute = location.getActiveAttributes(MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_KEPH_LEVEL)) + .stream() + .filter(attr -> attr.getAttributeType().equals(MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_KEPH_LEVEL))) + .findFirst() + .orElse(null); + + LocationAttribute shaFacilityIdAttribute = location.getActiveAttributes(MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_REGISTRY_CODE)) + .stream() + .filter(attr -> attr.getAttributeType().equals(MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_REGISTRY_CODE))) + .findFirst() + .orElse(null); + + LocationAttribute shaFacilityLicenseNumberAttribute = location.getActiveAttributes(MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_LICENSE_NUMBER)) + .stream() + .filter(attr -> attr.getAttributeType().equals(MetadataUtils.existing(LocationAttributeType.class, FacilityMetadata._LocationAttributeType.FACILITY_LICENSE_NUMBER))) + .findFirst() + .orElse(null); ObjectNode locationNode = JsonNodeFactory.instance.objectNode(); locationNode.put("locationId", location.getLocationId()); locationNode.put("uuid", location.getUuid()); locationNode.put("display", location.getName()); locationNode.put("operationalStatus", operationalStatusAttribute != null ? operationalStatusAttribute.getValue().toString() : "--"); - locationNode.put("operationalStatus", operationalStatusAttribute != null ? operationalStatusAttribute.getValue().toString() : "--"); + locationNode.put("shaKephLevel", shaKephLevelAttribute != null ? shaKephLevelAttribute.getValue().toString() : "--"); locationNode.put("shaContracted", isSHAFacilityAttribute != null ? isSHAFacilityAttribute.getValue().toString() : "--" ); + locationNode.put("shaFacilityId", shaFacilityIdAttribute != null ? shaFacilityIdAttribute.getValue().toString() : "--" ); + locationNode.put("shaFacilityLicenseNumber", shaFacilityLicenseNumberAttribute != null ? shaFacilityLicenseNumberAttribute.getValue().toString() : "--" ); locationNode.put("shaFacilityExpiryDate", shaFacilityExpiryDate != null ? shaFacilityExpiryDate.getValue().toString() : "--" ); return locationNode.toString(); diff --git a/omod/src/main/resources/liquibase.xml b/omod/src/main/resources/liquibase.xml index f7c397646..03f0a8b15 100755 --- a/omod/src/main/resources/liquibase.xml +++ b/omod/src/main/resources/liquibase.xml @@ -277,43 +277,6 @@ - - - - SELECT COUNT(*) FROM scheduler_task_config - WHERE schedulable_class = 'org.openmrs.module.kenyaemr.task.FacilityStatusTask' - And name = 'Get Facility status from the Registry' - - - Inserting Facility status Task into 'schedule_task_config' table - - - - - - - - - - - - - - - - - - - SELECT COUNT(*) FROM scheduler_task_config - WHERE schedulable_class = 'org.openmrs.module.kenyaemr.task.FacilityStatusTask' - And name = 'Get Facility status from the Registry' - - - Deleting Facility status Task from 'schedule_task_config' table - - schedulable_class='org.openmrs.module.kenyaemr.task.FacilityStatusTask' - -