diff --git a/omod/pom.xml b/omod/pom.xml index 02e0e5b1..8806a080 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -73,6 +73,12 @@ ${m2SysVersion} provided + + org.openmrs.module + m2sys-biometrics + ${m2SysVersion} + provided + org.openmrs.module diff --git a/omod/src/main/java/org/openmrs/module/registrationapp/form/RegisterPatientFormBuilder.java b/omod/src/main/java/org/openmrs/module/registrationapp/form/RegisterPatientFormBuilder.java index a1e7d3ec..15767e9d 100644 --- a/omod/src/main/java/org/openmrs/module/registrationapp/form/RegisterPatientFormBuilder.java +++ b/omod/src/main/java/org/openmrs/module/registrationapp/form/RegisterPatientFormBuilder.java @@ -14,6 +14,7 @@ package org.openmrs.module.registrationapp.form; import org.apache.commons.lang.StringUtils; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codehaus.jackson.JsonNode; diff --git a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/RegisterPatientFragmentController.java b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/RegisterPatientFragmentController.java index 47793194..36a1335d 100644 --- a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/RegisterPatientFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/RegisterPatientFragmentController.java @@ -34,6 +34,7 @@ import org.openmrs.module.appui.UiSessionContext; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.idgen.EmptyIdentifierPoolException; + import org.openmrs.module.registrationapp.PropertiesUtil; import org.openmrs.module.registrationapp.RegistrationAppUiUtils; import org.openmrs.module.registrationapp.RegistrationAppUtils; @@ -47,6 +48,7 @@ import org.openmrs.module.registrationcore.api.RegistrationCoreService; import org.openmrs.module.registrationcore.api.biometrics.model.BiometricData; import org.openmrs.module.registrationcore.api.biometrics.model.BiometricSubject; +import org.openmrs.module.registrationcore.api.biometrics.model.Fingerprint; import org.openmrs.module.uicommons.util.InfoErrorMessageUtil; import org.openmrs.ui.framework.UiUtils; import org.openmrs.ui.framework.annotation.BindParams; @@ -61,6 +63,8 @@ import org.springframework.validation.ObjectError; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestParam; +//import org.openmrs.module.m2sysbiometrics.service.RegistrationService; +import org.openmrs.module.m2sysbiometrics.service.RegistrationService; import javax.servlet.http.HttpServletRequest; import java.text.ParseException; @@ -70,15 +74,18 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.UUID; public class RegisterPatientFragmentController { private final Log log = LogFactory.getLog(RegisterPatientFragmentController.class); private PatientService patientService; + //private RegistrationService registrationServicem2sys; public RegisterPatientFragmentController() { patientService = Context.getService(PatientService.class); + //registrationServicem2sys=Context.getService(RegistrationService.class); } class ObsGroupItem { @@ -127,6 +134,7 @@ public FragmentActionResult submit(UiSessionContext sessionContext, @RequestPara @RequestParam(value="patientIdentifier", required = false) String patientIdentifier, @RequestParam(value="localBiometricSubjectId", required = false) String localBiometricSubjectId, @RequestParam(value="nationalBiometricSubjectId", required = false) String nationalBiometricSubjectId, + @RequestParam(value="biometricXml", required = false) String biometricXml, HttpServletRequest request, @SpringBean("messageSourceService") MessageSourceService messageSourceService, @SpringBean("encounterService") EncounterService encounterService, @@ -182,6 +190,19 @@ public FragmentActionResult submit(UiSessionContext sessionContext, @RequestPara // Add any biometric data that was submitted Map fingerprintData = RegisterPatientFormBuilder.extractBiometricDataFields(formStructure, request.getParameterMap()); + BiometricSubject subject1=new BiometricSubject(); +if(StringUtils.isNotBlank(biometricXml)) { + subject1 = new BiometricSubject(); +UUID uuid = UUID.randomUUID(); +subject1.setSubjectId(uuid.toString()); +subject1.addFingerprint(new Fingerprint("DoubleCapture", "FP1", biometricXml)); +PatientIdentifierType identifierType1=patientService.getPatientIdentifierTypeByUuid("e26ca279-8f57-44a5-9ed8-8cc16e90e559"); +if (identifierType1 == null) { + throw new IllegalStateException("Invalid fingerprint configuration test. No patient identifier type with uuid [e26ca279-8f57-44a5-9ed8-8cc16e90e559] found."); +} +registrationData.addBiometricData(new BiometricData(subject1,identifierType1)); +} + for (Field fingerprintField : fingerprintData.keySet()) { BiometricSubject subject = fingerprintData.get(fingerprintField); PatientIdentifierType identifierType = patientService.getPatientIdentifierTypeByUuid(fingerprintField.getUuid()); @@ -189,9 +210,23 @@ public FragmentActionResult submit(UiSessionContext sessionContext, @RequestPara throw new IllegalStateException("Invalid fingerprint configuration. No patient identifier type with uuid [" + fingerprintField.getUuid() + "] found."); } registrationData.addBiometricData(new BiometricData(subject, identifierType)); - } + + } +/* + log.error(); +for (Field fingerprintField : fingerprintData.keySet()) { + //BiometricSubject subject = fingerprintData.get(fingerprintField); + BiometricSubject subject1 = new BiometricSubject(); + subject1.addFingerprint(new Fingerprint("DoubleCapture", "FP1", biometricXml)); + PatientIdentifierType identifierType = patientService.getPatientIdentifierTypeByUuid(fingerprintField.getUuid()); + if (identifierType == null) { + throw new IllegalStateException("Invalid fingerprint configuration. No patient identifier type with uuid [" + fingerprintField.getUuid() + "] found."); + } + registrationData.addBiometricData(new BiometricData(subject1, identifierType)); +} +*/ - if (StringUtils.isNotBlank(localBiometricSubjectId)) { + if (StringUtils.isNotBlank(localBiometricSubjectId)) { BiometricData biometricData = generateBiometricData(localBiometricSubjectId, RegistrationCoreConstants.GP_BIOMETRICS_PERSON_IDENTIFIER_TYPE_UUID); registrationData.getBiometrics().add(biometricData); @@ -204,26 +239,32 @@ public FragmentActionResult submit(UiSessionContext sessionContext, @RequestPara try { // if patientIdentifier is blank, the underlying registerPatient method should automatically generate one - patient = registrationService.registerPatient(registrationData); + patient = registrationService.registerPatient(registrationData); + + if(StringUtils.isNotBlank(biometricXml)) { + log.error("XML:"+subject1.getFingerprints().get(0).getTemplate()); + Context.getService(RegistrationService.class).registerLocally(subject1); + } + } catch (Exception ex) { - // TODO I remember getting into trouble if i called this validator before the above save method. // TODO Am therefore putting this here for: https://tickets.openmrs.org/browse/RA-232 patientValidator.validate(patient, errors); checkForIdentifierExceptions(ex, errors); if (!errors.hasErrors()) { - errors.reject(ex.getMessage()); + errors.reject(ex.getMessage()+" the test"); } return new FailureResult(createErrorMessage(errors, messageSourceService)); } - + // now create the registration encounter, if configured to do so Encounter registrationEncounter = buildRegistrationEncounter(patient, registrationDate, sessionContext, app, encounterService); if (registrationEncounter != null) { encounterService.saveEncounter(registrationEncounter); } + Map> obsGroupMap = new LinkedHashMap>(); // build any obs that are submitted diff --git a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/field/FingerprintM2sysFragmentController.java b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/field/FingerprintM2sysFragmentController.java index 1d953aa5..18b072e4 100644 --- a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/field/FingerprintM2sysFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/field/FingerprintM2sysFragmentController.java @@ -2,15 +2,23 @@ import java.util.ArrayList; import java.util.List; +import java.util.UUID; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.Location; import org.openmrs.Patient; import org.openmrs.PatientIdentifierType; import org.openmrs.api.APIException; import org.openmrs.api.AdministrationService; +import org.openmrs.api.LocationService; import org.openmrs.event.Event; import org.openmrs.event.EventMessage; +import org.openmrs.module.m2sysbiometrics.service.RegistrationService; import org.openmrs.module.registrationapp.PropertiesUtil; +import org.openmrs.module.registrationapp.fragment.controller.RegisterPatientFragmentController; +import org.openmrs.PatientIdentifier; import org.openmrs.api.PatientService; import org.openmrs.api.context.Context; @@ -24,19 +32,35 @@ import org.openmrs.module.registrationcore.api.biometrics.model.BiometricSubject; import org.openmrs.module.registrationcore.api.biometrics.model.EnrollmentResult; import org.openmrs.module.registrationcore.api.biometrics.model.EnrollmentStatus; +import org.openmrs.module.registrationcore.api.biometrics.model.Fingerprint; import org.openmrs.ui.framework.SimpleObject; import org.openmrs.ui.framework.annotation.SpringBean; +import org.openmrs.validator.PatientIdentifierValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +//import org.springframework.web.bind.annotation.RequestMapping; +//import org.springframework.stereotype.Controller; +//import org.springframework.web.bind.annotation.RequestMethod; +import org.openmrs.module.registrationcore.api.impl.IdentifierBuilder; + +import org.openmrs.module.m2sysbiometrics.service.UpdateService; + +//@Controller +//@RequestMapping("/FingerprintM2sys") public class FingerprintM2sysFragmentController { private static final Logger LOGGER = LoggerFactory.getLogger(FingerprintM2sysFragmentController.class); + private final Log log = LogFactory.getLog(RegisterPatientFragmentController.class); private BiometricEngine biometricEngine; private AdministrationService adminService; + + private LocationService locationService; private RegistrationCoreService registrationCoreService; @@ -49,6 +73,7 @@ public FingerprintM2sysFragmentController() { patientService = Context.getService(PatientService.class); } + public void controller() { } @@ -74,7 +99,8 @@ public SimpleObject enroll(@SpringBean("messageSourceService") MessageSourceServ } catch (Exception ex) { response.put("success", false); response.put("message", ex.getMessage()); - LOGGER.error("Fingerprints enrollment failed", ex); + LOGGER.error("Fingerprints enrollment failed:test1", ex.getMessage()); + //.error("Fingerprints enrollment failed:test1", ex); } return response; @@ -127,7 +153,7 @@ public SimpleObject enrollAndSave(@RequestParam("patientId") Integer patientId, } catch (Exception ex) { response.put("success", false); response.put("message", ex.getMessage()); - LOGGER.error("Fingerprints enrollment failed", ex); + //LOGGER.error("Fingerprints enrollment failed:test2", ex); } return response; @@ -147,6 +173,7 @@ public SimpleObject getStatus() { return result; } + /* public SimpleObject update(@RequestParam("id") String id, @SpringBean("messageSourceService") MessageSourceService messageSourceService) { SimpleObject response = new SimpleObject(); @@ -170,6 +197,48 @@ public SimpleObject update(@RequestParam("id") String id, return response; } + */ + + // @RequestMapping(value = {"", "/update"}, method = RequestMethod.GET) + public SimpleObject update(@RequestParam("patientId") Integer patientId,@RequestParam("biometricXml") String biometricXml,@RequestParam("identifierValue") String identifierValue, + @SpringBean("messageSourceService") MessageSourceService messageSourceService) { + SimpleObject response = new SimpleObject(); + BiometricSubject subject=new BiometricSubject(); + //log.error("this is a test for update fingerPrint >> "+identifierValue); + try { + if(identifierValue.length()>1) { + subject.setSubjectId(identifierValue); + subject.addFingerprint(new Fingerprint("DoubleCapture", "FP1", biometricXml)); + Context.getService(UpdateService.class).updateLocally(subject); + response.put("success", true); + response.put("message", subject.getSubjectId()); + } + else + { + UUID uuid = UUID.randomUUID(); + subject.setSubjectId(uuid.toString()); + subject.addFingerprint(new Fingerprint("DoubleCapture", "FP1", biometricXml)); + PatientIdentifierType identifierType=patientService.getPatientIdentifierTypeByUuid("e26ca279-8f57-44a5-9ed8-8cc16e90e559"); + Patient patient=patientService.getPatient(patientId); + PatientIdentifier identifier = new PatientIdentifier(uuid.toString(),identifierType,Context.getService(LocationService.class).getDefaultLocation()); + patient.addIdentifier(identifier); + patientService.savePatientIdentifier(identifier); + Context.getService(RegistrationService.class).registerLocally(subject); + response.put("success", true); + response.put("message", subject.getSubjectId()); + } + } catch (Exception ex) { + response.put("success", false); + response.put("message", ex.getMessage()); + LOGGER.error(ex.getMessage()); + } + return response; + } + + + + + public SimpleObject updateSubjectId(@RequestParam("oldId") String oldId, @RequestParam("newId") String newId) { if (!isBiometricEngineEnabled()) { @@ -238,4 +307,26 @@ private Patient findByLocalFpId(String subjectId) { } return patient; } + + public PatientIdentifier createIdentifier(String identifierTypeUuid, String identifierValue, Location location) { + location = getLocation(location); + PatientIdentifierType identifierType = patientService.getPatientIdentifierTypeByUuid(identifierTypeUuid); + PatientIdentifierValidator.validateIdentifier(identifierValue, identifierType); + + return new PatientIdentifier(identifierValue, identifierType, location); + } + + private Location getLocation(Location identifierLocation) { + if (identifierLocation == null) { + identifierLocation = locationService.getDefaultLocation(); + validateIdentifierLocation(identifierLocation); + } + return identifierLocation; + } + + private void validateIdentifierLocation(Location identifierLocation) { + if (identifierLocation == null) + throw new APIException("Failed to resolve location to associate to patient identifiers"); + } + } diff --git a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/search/M2SysSearchFragmentController.java b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/search/M2SysSearchFragmentController.java index 63654aad..e3c6987f 100644 --- a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/search/M2SysSearchFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/search/M2SysSearchFragmentController.java @@ -2,15 +2,22 @@ import javax.servlet.http.HttpSession; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.openmrs.Patient; import org.openmrs.PatientIdentifier; import org.openmrs.PatientIdentifierType; import org.openmrs.PersonName; +import org.openmrs.api.context.Context; import org.openmrs.module.m2sysbiometrics.model.TempFingerprint; +import org.openmrs.module.m2sysbiometrics.service.RegistrationService; +import org.openmrs.module.m2sysbiometrics.service.SearchService; import org.openmrs.module.m2sysbiometrics.service.TempFingerprintService; import org.openmrs.module.registrationapp.PropertiesUtil; +import org.openmrs.module.registrationapp.fragment.controller.RegisterPatientFragmentController; import org.openmrs.module.registrationcore.RegistrationCoreConstants; import org.openmrs.module.registrationcore.api.RegistrationCoreService; +import org.openmrs.module.registrationcore.api.biometrics.model.BiometricMatch; import org.openmrs.module.registrationcore.api.biometrics.model.BiometricSubject; import org.openmrs.module.registrationcore.api.biometrics.model.EnrollmentResult; import org.openmrs.module.registrationcore.api.search.PatientAndMatchQuality; @@ -37,6 +44,7 @@ public class M2SysSearchFragmentController { private static final Logger LOGGER = LoggerFactory.getLogger(M2SysSearchFragmentController.class); + private final Log log = LogFactory.getLog(M2SysSearchFragmentController.class); public void controller(FragmentModel model) { model.addAttribute("test", "testval"); @@ -49,6 +57,33 @@ public List getPatients(@SpringBean("registrationCoreService") Reg return simplify(ui, patients); } + + public SimpleObject search(@SpringBean("registrationCoreService") RegistrationCoreService registrationCoreService, + @RequestParam("biometricXml") String biometricXml, + @SpringBean("registrationCoreService") RegistrationCoreService registrationService) { + log.info("try to search "+biometricXml); + SimpleObject response = new SimpleObject(); + + try { + List results=Context.getService(SearchService.class).searchLocally(biometricXml); + + for (BiometricMatch result : results) { + Patient searchPatient = registrationService.findByPatientIdentifier(result.getSubjectId(),PropertiesUtil.getLocalFpType().getUuid()); + response.put("patientUuid", searchPatient.getUuid()); + // response.put("patient", searchPatient); + } + + //log.error("try to search "+results.toString()); + response.put("success", true); + + } + catch (Exception ex) { + log.error("try to search "+ex.getMessage()); + } + + return response; +} + public FragmentActionResult importMpiPatientWithCcd(@RequestParam("nationalFingerprintId") String nationalId, @SpringBean("registrationCoreService") RegistrationCoreService registrationService, @SpringBean("tempFingerprintService") TempFingerprintService tempFingerprintService, diff --git a/omod/src/main/webapp/fragments/field/fingerprintM2sys.gsp b/omod/src/main/webapp/fragments/field/fingerprintM2sys.gsp index 01bee6ff..f4f79f22 100644 --- a/omod/src/main/webapp/fragments/field/fingerprintM2sys.gsp +++ b/omod/src/main/webapp/fragments/field/fingerprintM2sys.gsp @@ -1,5 +1,6 @@ <% ui.includeJavascript("registrationapp", "field/fingerprintM2sys.js") + ui.includeJavascript("registrationapp", "field/m2sysnew.js") ui.includeJavascript("registrationapp", "fingerprintUtils.js") %> @@ -20,7 +21,7 @@

${ui.message("registrationapp.biometrics.m2sys.register.question")}

- @@ -28,6 +29,11 @@

+ + + + +