diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/MissingAllRegistrationIdentifiersCalculation.java b/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/MissingAllRegistrationIdentifiersCalculation.java new file mode 100644 index 0000000000..fa1867c92a --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/MissingAllRegistrationIdentifiersCalculation.java @@ -0,0 +1,68 @@ +/** + * 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.calculation.library; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.PatientIdentifier; +import org.openmrs.PatientIdentifierType; +import org.openmrs.api.PatientService; +import org.openmrs.api.context.Context; +import org.openmrs.calculation.patient.PatientCalculationContext; +import org.openmrs.calculation.result.CalculationResultMap; +import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation; +import org.openmrs.module.kenyacore.calculation.BooleanResult; +import org.openmrs.module.kenyacore.identifier.IdentifierManager; +import org.openmrs.module.kenyaemr.metadata.CommonMetadata; +import org.openmrs.module.metadatadeploy.MetadataUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * Missing all registration identifiers + * Registration identifiers are: + * ************************ + * Patient Clinic Number + * National ID Number + * Passport Number + * Huduma Number + * Birth Certificate Number + */ +public class MissingAllRegistrationIdentifiersCalculation extends AbstractPatientCalculation { + protected static final Log log = LogFactory.getLog(MissingAllRegistrationIdentifiersCalculation.class); + + @Override + public CalculationResultMap evaluate(Collection cohort, Map params, PatientCalculationContext context) { + + CalculationResultMap ret = new CalculationResultMap(); + for (Integer ptId : cohort) { + boolean missingAllIdentifiers = true; + PatientService patientService = Context.getPatientService(); + + PatientIdentifierType nationalID = MetadataUtils.existing(PatientIdentifierType.class, CommonMetadata._PatientIdentifierType.NATIONAL_ID); + PatientIdentifierType patientClinicNo = MetadataUtils.existing(PatientIdentifierType.class, CommonMetadata._PatientIdentifierType.PATIENT_CLINIC_NUMBER); + PatientIdentifierType passPortNo = MetadataUtils.existing(PatientIdentifierType.class, CommonMetadata._PatientIdentifierType.PASSPORT_NUMBER); + PatientIdentifierType hudumaNo = MetadataUtils.existing(PatientIdentifierType.class, CommonMetadata._PatientIdentifierType.HUDUMA_NUMBER); + PatientIdentifierType birthCertNo = MetadataUtils.existing(PatientIdentifierType.class, CommonMetadata._PatientIdentifierType.BIRTH_CERTIFICATE_NUMBER); + + List patientRegIdentifiers = patientService.getPatientIdentifiers(null, Arrays.asList(nationalID,patientClinicNo,passPortNo,hudumaNo,birthCertNo), null, Arrays.asList(patientService.getPatient(ptId)), false); + if(patientRegIdentifiers.size() > 0){ + missingAllIdentifiers = false; + } + ret.put(ptId, new BooleanResult(missingAllIdentifiers, this, context)); + } + + return ret; + } +} \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/kenyaemr/fragment/controller/patient/PatientSummaryFragmentController.java b/omod/src/main/java/org/openmrs/module/kenyaemr/fragment/controller/patient/PatientSummaryFragmentController.java index c944ee6625..9cf529e1b4 100755 --- a/omod/src/main/java/org/openmrs/module/kenyaemr/fragment/controller/patient/PatientSummaryFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/kenyaemr/fragment/controller/patient/PatientSummaryFragmentController.java @@ -18,6 +18,7 @@ import org.openmrs.module.kenyacore.calculation.CalculationUtils; import org.openmrs.module.kenyacore.form.FormDescriptor; import org.openmrs.module.kenyacore.form.FormManager; +import org.openmrs.module.kenyaemr.calculation.library.MissingAllRegistrationIdentifiersCalculation; import org.openmrs.module.kenyaemr.calculation.library.RecordedDeceasedCalculation; import org.openmrs.module.kenyaui.KenyaUiUtils; import org.openmrs.ui.framework.SimpleObject; @@ -52,6 +53,7 @@ public void controller(@FragmentParam("patient") Patient patient, model.addAttribute("patient", patient); model.addAttribute("recordedAsDeceased", hasBeenRecordedAsDeceased(patient)); + model.addAttribute("missingIdentifiers", hasNoRequiredRegistrationIdentifiers(patient)); model.addAttribute("forms", forms); } @@ -64,4 +66,19 @@ protected boolean hasBeenRecordedAsDeceased(Patient patient) { PatientCalculation calc = CalculationUtils.instantiateCalculation(RecordedDeceasedCalculation.class, null); return ResultUtil.isTrue(Context.getService(PatientCalculationService.class).evaluate(patient.getId(), calc)); } + /** + * Checks if a patient has been recorded required patient registration identifiers + * Patient Clinic Number + * National ID Number + * Passport Number + * Huduma Number + * Birth Certificate Number + * + * @param patient the patient + * @return true if patient has no recorded registration identifiers + */ + protected boolean hasNoRequiredRegistrationIdentifiers(Patient patient) { + PatientCalculation calc = CalculationUtils.instantiateCalculation(MissingAllRegistrationIdentifiersCalculation.class, null); + return ResultUtil.isTrue(Context.getService(PatientCalculationService.class).evaluate(patient.getId(), calc)); + } } \ No newline at end of file diff --git a/omod/src/main/webapp/fragments/patient/patientSummary.gsp b/omod/src/main/webapp/fragments/patient/patientSummary.gsp index 7555681f4d..1e23e6e917 100755 --- a/omod/src/main/webapp/fragments/patient/patientSummary.gsp +++ b/omod/src/main/webapp/fragments/patient/patientSummary.gsp @@ -8,6 +8,11 @@ Patient has been recorded as deceased in a program form. Please update the registration form. <% } %> + <% if (missingIdentifiers) { %> +
+ Patient has missing registration identifiers. +
+ <% } %>