Examples of PersonResponse


Examples of ke.go.moh.oec.PersonResponse

     *
     * @param req Request containing the search terms to look for.
     * @return The response data to the request.
     */
    public Object find(PersonRequest req) {
        PersonResponse resp = new PersonResponse();
        Person p = req.getPerson();
        if (p == null) {
            Logger.getLogger(PersonList.class.getName()).log(Level.SEVERE, "FIND PERSON called with no person data.");
            return resp;
        }
        PersonMatch searchTerms = new PersonMatch(p);
        CandidateSet candidateSet = new CandidateSet();
        Set<SiteCandidate> siteCandidateSet = siteList.findIfNeeded(searchTerms);
        searchTerms.setSiteCandidateSet(siteCandidateSet);
        DateMatch.setToday();
        //
        // Make a special case if we are searching by GUID and not trying to match fingerprints.
        // In this case, just look to see if we have person matching the GUID search term.
        // If we do, then we are done. If not, then we test for matching the usual way...
        //
        PersonMatch guidMatch = null;
        if (p.getPersonGuid() != null
                && (p.getFingerprintList() == null || p.getFingerprintList().isEmpty())) {
            guidMatch = this.get(p.getPersonGuid());
            //TODO: Fix logic.
            if (guidMatch != null) {
                final double GUID_MATCH_SCORE = 1.0;
                final double GUID_MATCH_WEIGHT = 1.0;
                Scorecard s = new Scorecard();
                s.addScore(GUID_MATCH_SCORE, GUID_MATCH_WEIGHT);
                candidateSet.add(guidMatch, s);
                if (Mediator.testLoggerLevel(Level.FINEST)) {
                    Mediator.getLogger(PersonList.class.getName()).log(Level.FINEST,
                            "Score {0},{1} total {2},{3} comparing GUID {4} with {5}",
                            new Object[]{GUID_MATCH_SCORE, GUID_MATCH_WEIGHT, s.getTotalScore(), s.getTotalWeight(),
                                p.getPersonGuid(), guidMatch.getPerson().getPersonGuid()});
                }
            }
        }
        int personMatchCount = personList.size();
        if (guidMatch == null && personMatchCount > 0) { // Skip if matched already, or if MPI is empty
            int threadCount = Mpi.getMaxThreadCount();
            if (threadCount > personMatchCount) {
                threadCount = personMatchCount;
            }
            int countPerThread = (personMatchCount + threadCount - 1) / threadCount;
            long startTime = System.currentTimeMillis();
            List<Thread> threadArray = new ArrayList<Thread>();
            for (int i = 0; i < threadCount; i++) {
                int startIndex = countPerThread * i;
                int endIndex = (countPerThread * (i + 1)) - 1;
                if (endIndex >= personMatchCount) {
                    endIndex = personMatchCount - 1;
                }
                FindPersonThread fpt = new FindPersonThread(this, searchTerms, candidateSet, startIndex, endIndex);
                Thread t = new Thread(fpt);
                threadArray.add(t);
                t.start();
            }
            for (Thread t : threadArray) {
                try {
                    t.join();
                } catch (InterruptedException ex) {
                    Logger.getLogger(PersonList.class.getName()).log(Level.SEVERE, "Error joining FindPersonThread", ex);
                }
            }
            double timeInterval = (System.currentTimeMillis() - startTime);
            Mediator.getLogger(PersonList.class.getName()).log(Level.FINE,
                    "Searched {0} entries in {1} milliseconds.",
                    new Object[]{personMatchCount, timeInterval});
        }
        List<Person> candidateList = candidateSet.export();
        resp.setPersonList(candidateList);
        resp.setSuccessful(true);
        SearchHistory.create(req);
        return resp;
    }
View Full Code Here

Examples of ke.go.moh.oec.PersonResponse

     * Creates a new person in the database and our in-memory list.
     *
     * @param PersonRequest person search parameters to be stored
     */
    public Object create(PersonRequest req) {
        PersonResponse returnData = null;
        if (req.isResponseRequested()) {    // Has the client requested a response?
            returnData = new PersonResponse();
            returnData.setSuccessful(false); // Until we succeed, assume that we failed.
        }
        Person p = req.getPerson().clone(); // Clone because we may modify our copy below.
        if (p == null) {
            Logger.getLogger(PersonList.class.getName()).log(Level.SEVERE, "CREATE PERSON called with no person data.");
            return returnData;
        }
        //Check to see if this person's hdssid, if available, already exists in the mpi. Log error if it does.
        String existingId = null;
        if (p.getPersonIdentifierList() != null
                && !p.getPersonIdentifierList().isEmpty()) {
            for (PersonIdentifier personIdentifier : p.getPersonIdentifierList()) {
                if (personIdentifier.getIdentifierType() == PersonIdentifier.Type.kisumuHdssId) {
                    String pi = personIdentifier.getIdentifier();
                    if (pi != null && !pi.isEmpty()) {
                        if (hdssIdMap.containsKey(pi)) {
                            existingId = pi;
                            break;
                        }
                    }
                }
            }
        }
        if (existingId != null) {
            Logger.getLogger(PersonList.class.getName()).log(Level.SEVERE,
                    "CREATE PERSON called with existing kisumuhdssid person identifier {0}.", existingId);
            return returnData;
        }
        Connection conn = Sql.connect();
        ResultSet rs = Sql.query(conn, "SELECT UUID() AS uuid");
        String guid = null;
        try {
            rs.next();
            guid = rs.getString("uuid");
            Sql.close(rs);
        } catch (SQLException ex) { // Won't happen
            Logger.getLogger(PersonList.class.getName()).log(Level.SEVERE, null, ex);
        }
        p.setPersonGuid(guid);

        String sex = ValueMap.SEX.getDb().get(p.getSex());
        String villageId = Sql.getVillageId(conn, p.getVillageName());
        String maritalStatusId = Sql.getMaritalStatusId(conn, p.getMaritalStatus());
        String consentSigned = ValueMap.CONSENT_SIGNED.getDb().get(p.getConsentSigned());
        String sql = "INSERT INTO person (person_guid, first_name, middle_name, last_name,\n"
                + "       other_name, clan_name, sex, birthdate, deathdate,\n"
                + "       mothers_first_name, mothers_middle_name, mothers_last_name,\n"
                + "       fathers_first_name, fathers_middle_name, fathers_last_name,\n"
                + "       compoundhead_first_name, compoundhead_middle_name, compoundhead_last_name,\n"
                + "       village_id, marital_status, consent_signed, date_created) values (\n   "
                + Sql.quote(guid) + ", "
                + Sql.quote(p.getFirstName()) + ", "
                + Sql.quote(p.getMiddleName()) + ", "
                + Sql.quote(p.getLastName()) + ",\n   "
                + Sql.quote(p.getOtherName()) + ", "
                + Sql.quote(p.getClanName()) + ", "
                + Sql.quote(sex) + ", "
                + Sql.quote(p.getBirthdate()) + ", "
                + Sql.quote(p.getDeathdate()) + ",\n   "
                + Sql.quote(p.getMothersFirstName()) + ", "
                + Sql.quote(p.getMothersMiddleName()) + ", "
                + Sql.quote(p.getMothersLastName()) + ",\n   "
                + Sql.quote(p.getFathersFirstName()) + ", "
                + Sql.quote(p.getFathersMiddleName()) + ", "
                + Sql.quote(p.getFathersLastName()) + ",\n   "
                + Sql.quote(p.getCompoundHeadFirstName()) + ", "
                + Sql.quote(p.getCompoundHeadMiddleName()) + ", "
                + Sql.quote(p.getCompoundHeadLastName()) + ",\n   "
                + villageId + ", "
                + maritalStatusId + ", "
                + consentSigned + ", "
                + "NOW()"
                + ");";
        Sql.startTransaction(conn);
        boolean successful = Sql.execute(conn, sql);
        if (successful) {
            int dbPersonId = Integer.parseInt(Sql.getLastInsertId(conn));
            PersonIdentifierList.update(conn, dbPersonId, p.getPersonIdentifierList(), null);
            FingerprintList.update(conn, dbPersonId, p.getFingerprintList(), null);
            VisitList.update(conn, Sql.REGULAR_VISIT_TYPE_ID, dbPersonId, p.getLastRegularVisit());
            VisitList.update(conn, Sql.ONE_OFF_VISIT_TYPE_ID, dbPersonId, p.getLastOneOffVisit());
            PersonMatch newPer = new PersonMatch(p.clone()); // Clone to protect from unit test modifications.
            newPer.setDbPersonId(dbPersonId);
            this.add(newPer);
            SearchHistory.update(req, null, null); // Update search history showing that no candidate was selected.
        }
        Sql.commit(conn);
        Sql.close(conn);
        if (returnData != null) {
            List<Person> returnList = new ArrayList<Person>();
            returnList.add(p);
            returnData.setPersonList(returnList);
            returnData.setSuccessful(successful); // We have succeeded.
        }
        return returnData;
    }
View Full Code Here

Examples of ke.go.moh.oec.PersonResponse

     * Modifies a person entry in the database and in our in-memory list.
     *
     * @param req The modify request.
     */
    public Object modify(PersonRequest req) {
        PersonResponse returnData = null;
        if (req.isResponseRequested()) {    // Has the client requested a response?
            returnData = new PersonResponse();
            returnData.setSuccessful(false); // Until we succeed, assume that we failed.
        }
        Person newPerson = req.getPerson();//person containing modified data
        if (newPerson == null) {
            Logger.getLogger(PersonList.class.getName()).log(Level.SEVERE, "MODIFY PERSON called with no person data.");
            return returnData;
        }
        // For modify, we should have either a local person GUID or a HDSSID to reference the existing (old) entry.
        PersonMatch oldPersonMatch = null;
        String personGuid = newPerson.getPersonGuid();
        if (personGuid != null) {
            oldPersonMatch = this.get(personGuid);
            if (oldPersonMatch == null) {
                Logger.getLogger(PersonList.class.getName()).log(Level.SEVERE, "MODIFY PERSON GUID {0} not found.", personGuid);
                return returnData;
            }
        } else {
            List<PersonIdentifier> piList = newPerson.getPersonIdentifierList();
            if (piList != null && !piList.isEmpty()) {
                for (PersonIdentifier pi : piList) {
                    if (pi.getIdentifierType() == PersonIdentifier.Type.kisumuHdssId) {
                        String hdssId = pi.getIdentifier();
                        if (hdssId != null && !hdssId.isEmpty()) {
                            oldPersonMatch = hdssIdMap.get(hdssId);
                            if (oldPersonMatch != null) {
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (oldPersonMatch == null) {
            Logger.getLogger(PersonList.class.getName()).log(Level.SEVERE, "MODIFY PERSON called with no person GUID or matching HDSSID.");
            return returnData;
        }
        SearchHistory.update(req, oldPersonMatch, newPerson); // Log the search result (if any) BEFORE modifying the person.
        int dbPersonId = oldPersonMatch.getDbPersonId();
        Person oldPerson = oldPersonMatch.getPerson();
        Connection conn = Sql.connect();
        String sex = ValueMap.SEX.getDb().get(newPerson.getSex());
        String villageId = Sql.getVillageId(conn, newPerson.getVillageName());
        String maritalStatusId = Sql.getMaritalStatusId(conn, newPerson.getMaritalStatus());
        String consentSigned = ValueMap.CONSENT_SIGNED.getDb().get(newPerson.getConsentSigned());
        int columnCount = 0;
        String sql = "UPDATE person SET\n";
        if (newPerson.getFirstName() != null) {
            if (newPerson.getFirstName().isEmpty()) {
                sql += (separate(columnCount) + "first_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "first_name = " + Sql.quote(newPerson.getFirstName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getMiddleName() != null) {
            if (newPerson.getMiddleName().isEmpty()) {
                sql += (separate(columnCount) + "middle_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "middle_name = " + Sql.quote(newPerson.getMiddleName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getLastName() != null) {
            if (newPerson.getLastName().isEmpty()) {
                sql += (separate(columnCount) + "last_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "last_name = " + Sql.quote(newPerson.getLastName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getOtherName() != null) {
            if (newPerson.getOtherName().isEmpty()) {
                sql += (separate(columnCount) + "other_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "other_name = " + Sql.quote(newPerson.getOtherName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getClanName() != null) {
            if (newPerson.getClanName().isEmpty()) {
                sql += (separate(columnCount) + "clan_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "clan_name = " + Sql.quote(newPerson.getClanName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getSex() != null) {
            sql += (separate(columnCount) + "sex = " + Sql.quote(sex) + "\n");
            columnCount++;
        }
        if (newPerson.getBirthdate() != null) {
            sql += (separate(columnCount) + "birthdate = " + Sql.quote(newPerson.getBirthdate()) + "\n");
            columnCount++;
        }
        if (newPerson.getDeathdate() != null) {
            sql += (separate(columnCount) + "deathdate = " + Sql.quote(newPerson.getDeathdate()) + "\n");
            columnCount++;
        }
        if (newPerson.getMothersFirstName() != null) {
            if (newPerson.getMothersFirstName().isEmpty()) {
                sql += (separate(columnCount) + "mothers_first_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "mothers_first_name = " + Sql.quote(newPerson.getMothersFirstName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getMothersMiddleName() != null) {
            if (newPerson.getMothersMiddleName().isEmpty()) {
                sql += (separate(columnCount) + "mothers_middle_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "mothers_middle_name = " + Sql.quote(newPerson.getMothersMiddleName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getMothersLastName() != null) {
            if (newPerson.getMothersLastName().isEmpty()) {
                sql += (separate(columnCount) + "mothers_last_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "mothers_last_name = " + Sql.quote(newPerson.getMothersLastName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getFathersFirstName() != null) {
            if (newPerson.getFathersFirstName().isEmpty()) {
                sql += (separate(columnCount) + "fathers_first_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "fathers_first_name = " + Sql.quote(newPerson.getFathersFirstName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getFathersMiddleName() != null) {
            if (newPerson.getFathersMiddleName().isEmpty()) {
                sql += (separate(columnCount) + "fathers_middle_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "fathers_middle_name = " + Sql.quote(newPerson.getFathersMiddleName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getFathersLastName() != null) {
            if (newPerson.getFathersLastName().isEmpty()) {
                sql += (separate(columnCount) + "fathers_last_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "fathers_last_name = " + Sql.quote(newPerson.getFathersLastName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getCompoundHeadFirstName() != null) {
            if (newPerson.getCompoundHeadFirstName().isEmpty()) {
                sql += (separate(columnCount) + "compoundhead_first_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "compoundhead_first_name = " + Sql.quote(newPerson.getCompoundHeadFirstName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getCompoundHeadMiddleName() != null) {
            if (newPerson.getCompoundHeadMiddleName().isEmpty()) {
                sql += (separate(columnCount) + "compoundhead_middle_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "compoundhead_middle_name = " + Sql.quote(newPerson.getCompoundHeadMiddleName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getCompoundHeadLastName() != null) {
            if (newPerson.getCompoundHeadLastName().isEmpty()) {
                sql += (separate(columnCount) + "compoundhead_last_name = NULL\n");
            } else {
                sql += (separate(columnCount) + "compoundhead_last_name = " + Sql.quote(newPerson.getCompoundHeadLastName()) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getVillageName() != null) {
            if (newPerson.getVillageName().isEmpty()) {
                sql += (separate(columnCount) + "village_id = NULL\n");
            } else {
                sql += (separate(columnCount) + "village_id = " + Sql.quote(villageId) + "\n");
            }
            columnCount++;
        }
        if (newPerson.getMaritalStatus() != null) {
            sql += (separate(columnCount) + "marital_status = " + Sql.quote(maritalStatusId) + "\n");
            columnCount++;
        }
        if (newPerson.getConsentSigned() != null) {
            sql += (separate(columnCount) + "consent_signed = " + Sql.quote(consentSigned) + "\n");
            columnCount++;
        }
        sql += " WHERE person_id = " + dbPersonId;
        if (columnCount != 0) {//some 'real' mpi data has changed and needs to be updated
            Sql.startTransaction(conn);
            Sql.execute(conn, sql);
            List<PersonIdentifier> pList = PersonIdentifierList.update(conn, dbPersonId, newPerson.getPersonIdentifierList(), oldPerson.getPersonIdentifierList());
            newPerson.setPersonIdentifierList(pList);
            List<Fingerprint> fList = FingerprintList.update(conn, dbPersonId, newPerson.getFingerprintList(), oldPerson.getFingerprintList());
            newPerson.setFingerprintList(fList);
            VisitList.update(conn, Sql.REGULAR_VISIT_TYPE_ID, dbPersonId, newPerson.getLastRegularVisit());
            VisitList.update(conn, Sql.ONE_OFF_VISIT_TYPE_ID, dbPersonId, newPerson.getLastOneOffVisit());
            if (newPerson.getLastRegularVisit() == null) {
                newPerson.setLastRegularVisit(oldPerson.getLastRegularVisit());
            }
            if (newPerson.getLastOneOffVisit() == null) {
                newPerson.setLastOneOffVisit(oldPerson.getLastOneOffVisit());
            }
            Sql.commit(conn);
        }
        Sql.close(conn);
        if (newPerson.getLastMoveDate() != null) {
            newPerson.setPreviousVillageName(oldPerson.getVillageName());
        }
        Person mergedPerson = merge(newPerson, oldPersonMatch.getPerson());//merge old and new person
        PersonMatch newPersonMatch = new PersonMatch(mergedPerson);
        newPersonMatch.setDbPersonId(dbPersonId);
        this.remove(oldPersonMatch); // Remove old person from our in-memory list.
        this.add(newPersonMatch); // Add new person to our in-memory list.
        Notifier.notify(mergedPerson);
        if (returnData != null) {
            List<Person> returnList = new ArrayList<Person>();
            returnList.add(mergedPerson);
            returnData.setPersonList(returnList);
            returnData.setSuccessful(true); // We have succeeded.
        }
        return returnData;
    }
View Full Code Here

Examples of ke.go.moh.oec.PersonResponse

                    m.getMessageData().getClass().getName());
            return doc;
        }
        if (m.getXml() == null) { // Skip the following if we have pre-formed XML:
            Person p = null;
            PersonResponse personResponse = (PersonResponse) m.getMessageData();
            List<Person> personList = personResponse.getPersonList();
            if (personList != null && !personList.isEmpty()) { // Are we responding with person data?
                p = personResponse.getPersonList().get(0)// Yes, get the person data to return.
            } else {
                p = new Person();   // No, return an empty person (needed to clear the default template values.)
            }
            packPerson(personNode, p);
        }
View Full Code Here

Examples of ke.go.moh.oec.PersonResponse

            Logger.getLogger(XmlPacker.class.getName()).log(Level.SEVERE,
                    "packFindPersonResponseMessage() - Expected data class PersonResponse, got {0}",
                    m.getMessageData().getClass().getName());
        }
        if (m.getXml() == null) { // Skip the following if we have pre-formed XML:
            PersonResponse pr = (PersonResponse) m.getMessageData();
            List<Person> personList = pr.getPersonList();
            /*
             * Find the <subject> subtree in the template. If there are no person results returned, remove it.
             * If there is one result, pack it into the template. If there are more than one results,
             * clone the <subject> subtree so we will have one to pack for each result.
             *
 
View Full Code Here

Examples of ke.go.moh.oec.PersonResponse

     *
     * @param m the message contents to fill in
     * @param e root node of the person message <code>Document</code> parsed from XML
     */
    private void unpackGenericPersonResponseMessage(Message m, Element e) {
        PersonResponse personResponse = new PersonResponse();
        m.setMessageData(personResponse);
        List<Person> personList = new ArrayList<Person>();
        personResponse.setPersonList(personList);
        Person p = new Person();
        personList.add(p);
        unpackHl7Header(m, e);
        Element ePerson = (Element) e.getElementsByTagName("patient").item(0);
        unpackPerson(p, ePerson);
View Full Code Here

Examples of ke.go.moh.oec.PersonResponse

     *
     * @param m the message contents to fill in
     * @param e root of the person message <code>Document</code> parsed from XML
     */
    private void unpackFindPersonResponseMessage(Message m, Element e) {
        PersonResponse personResponse = new PersonResponse();
        m.setMessageData(personResponse);
        unpackHl7Header(m, e);
        NodeList nodeList = e.getElementsByTagName("subject");
        int personCount = nodeList.getLength();
        if (personCount != 0) {
            List<Person> personList = new ArrayList<Person>(personCount);
            personResponse.setPersonList(personList);
            for (int i = 0; i < personCount; i++) {
                Person p = new Person();
                Element el = (Element) nodeList.item(i);
                unpackCandidate(p, el);
                personList.add(p);
View Full Code Here

Examples of ke.go.moh.oec.PersonResponse

                case modifyPerson:
                    //added above two lines in place of the two below  to specify the message
                    //templates that expect a response
//                case createPersonAccepted:
//                case modifyPersonAccepted:
                    PersonResponse personResponse;
                    if (responseMessage != null) {
                        returnData = responseMessage.getMessageData();
                        personResponse = (PersonResponse) returnData;
                        personResponse.setSuccessful(true);
                    } else {
                        personResponse = new PersonResponse();
                        personResponse.setSuccessful(false);
                    }
                    break;

                default:
                    Logger.getLogger(Mediator.class.getName()).log(Level.SEVERE,
View Full Code Here

Examples of ke.go.moh.oec.PersonResponse

                        req.setSourceAddress(m.getSourceAddress());
                        req.setSourceName(m.getSourceName());
                        req.setRequestReference(m.getMessageId());
                        req.setXml(m.getXml()); // Return raw XML through the API in case it is wanted.
                    } else if (m.getMessageData().getClass() == PersonResponse.class) {
                        PersonResponse rsp = (PersonResponse) m.getMessageData();
                        rsp.setSuccessful(true);
                        rsp.setRequestReference(m.getMessageId());
                    }
                    boolean responseDelivered = pendingQueue.findRequest(m);
                    if (responseDelivered) { // Was the message a response to a request that we just delivered?
                        if (Mediator.testLoggerLevel(Level.FINE)) {
                            Mediator.getLogger(Mediator.class.getName()).log(Level.FINE,
View Full Code Here

Examples of ke.go.moh.oec.PersonResponse

        }
        System.out.println(log);
        Object result = mediator.getData(RequestTypeId.FIND_PERSON_MPI, personRequest);
        assertNotNull(result);
        assertSame(PersonResponse.class, result.getClass());
        PersonResponse personResponse = (PersonResponse) result;
        assertTrue(personResponse.isSuccessful());
        List<Person> pList = personResponse.getPersonList();
        if (pList == null || pList.isEmpty()) {
            System.out.println("No persons returned.");
        } else {
            for (Person person : pList) {
                log = "guid: " + person.getPersonGuid()
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.