Skip to content

Commit

Permalink
Merge pull request #16 from IsantePlus/modify_finger
Browse files Browse the repository at this point in the history
Modify fingerprint code and functionality
  • Loading branch information
jamesfeshner authored Oct 26, 2020
2 parents 89fc589 + 09188de commit 30fcce8
Show file tree
Hide file tree
Showing 10 changed files with 358 additions and 45 deletions.
6 changes: 6 additions & 0 deletions omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
<version>${m2SysVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>m2sys-biometrics</artifactId>
<version>${m2SysVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -182,16 +190,43 @@ public FragmentActionResult submit(UiSessionContext sessionContext, @RequestPara

// Add any biometric data that was submitted
Map<Field, BiometricSubject> 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());
if (identifierType == null) {
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);
Expand All @@ -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<String, List<ObsGroupItem>> obsGroupMap = new LinkedHashMap<String, List<ObsGroupItem>>();
// build any obs that are submitted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -49,6 +73,7 @@ public FingerprintM2sysFragmentController() {
patientService = Context.getService(PatientService.class);
}


public void controller() {
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -147,6 +173,7 @@ public SimpleObject getStatus() {
return result;
}

/*
public SimpleObject update(@RequestParam("id") String id,
@SpringBean("messageSourceService") MessageSourceService messageSourceService) {
SimpleObject response = new SimpleObject();
Expand All @@ -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()) {
Expand Down Expand Up @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -49,6 +57,33 @@ public List<SimpleObject> 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<BiometricMatch> 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,
Expand Down
Loading

0 comments on commit 30fcce8

Please sign in to comment.