[507] | 1 | /*
|
---|
| 2 | * To change this template, choose Tools | Templates
|
---|
| 3 | * and open the template in the editor.
|
---|
| 4 | */
|
---|
| 5 | package gov.hhs.fha.nhinc.adaptercomponentmpi;
|
---|
| 6 |
|
---|
| 7 | import gov.hhs.fha.nhinc.adaptercomponentmpi.hl7parsers.HL7Parser201305;
|
---|
| 8 | import gov.hhs.fha.nhinc.adaptercomponentmpi.hl7parsers.HL7Parser201306;
|
---|
| 9 | import gov.hhs.fha.nhinc.mpilib.*;
|
---|
| 10 | import org.apache.commons.logging.Log;
|
---|
| 11 | import org.apache.commons.logging.LogFactory;
|
---|
| 12 | import org.hl7.v3.*;
|
---|
| 13 |
|
---|
| 14 | /**
|
---|
| 15 | *
|
---|
| 16 | * @author Jon Hoppesch
|
---|
| 17 | */
|
---|
| 18 | public class PatientChecker {
|
---|
| 19 |
|
---|
| 20 | private static Log log = LogFactory.getLog(PatientChecker.class);
|
---|
| 21 |
|
---|
| 22 | public static PRPAIN201306UV FindPatient(PRPAIN201305UV query) {
|
---|
| 23 | log.debug("Entering PatientChecker.FindPatient method...");
|
---|
| 24 | PRPAIN201306UV result = null;
|
---|
| 25 |
|
---|
| 26 | PRPAMT201306UVParameterList queryParams = HL7Parser201305.ExtractHL7QueryParamsFromMessage(query);
|
---|
| 27 |
|
---|
| 28 | if (queryParams == null) {
|
---|
| 29 | log.error("no query parameters were supplied");
|
---|
| 30 | } else {
|
---|
| 31 | Patient sourcePatient = HL7Parser201305.ExtractMpiPatientFromQueryParams(queryParams);
|
---|
| 32 | log.info("perform patient lookup in mpi");
|
---|
| 33 |
|
---|
| 34 | log.info("source patient check 1 [" + sourcePatient.getName().getLastName() + "]");
|
---|
| 35 | Patients searchResults = MpiDataAccess.LookupPatients(sourcePatient);
|
---|
| 36 | if (CommonChecks.isZeroSearchResult(searchResults)) {
|
---|
| 37 | log.info("patient not found in MPI");
|
---|
| 38 | result = null;
|
---|
| 39 | } else if (CommonChecks.isMultipleSearchResult(searchResults)) {
|
---|
| 40 | log.info("multiple patients found in MPI [searchResults.size()=" + searchResults.size() + "]");
|
---|
| 41 | result = null;
|
---|
| 42 | } else {
|
---|
| 43 | log.info("single patient found in MPI");
|
---|
| 44 | Patient searchResultPatient = searchResults.get(0);
|
---|
| 45 | log.info("Found patient " + searchResultPatient.getName().getFirstName() + " " + searchResultPatient.getName().getLastName());
|
---|
| 46 |
|
---|
| 47 | result = HL7Parser201306.BuildMessageFromMpiPatient (searchResultPatient, query);
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | log.debug("Exiting PatientChecker.FindPatient method...");
|
---|
| 52 | return result;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|