PatientCorrelationOrchImpl implements PatientCorrelationOrch { @Override public AddPatientCorrelationResponseType addPatientCorrelation(PRPAIN201301UV02 addPatientCorrelationRequest, AssertionType assertion) { PRPAMT201301UV02Patient patient = PRPAIN201301UVParser .parseHL7PatientPersonFrom201301Message(addPatientCorrelationRequest); String patientId; String patientAssigningAuthId; String correlatedPatientId; String correlatedPatientAssigningAuthId; if (patient == null) { LOG.warn("Patient was null"); return null; } List<II> ids = patient.getId(); if (ids.get(0) == null) { LOG.warn("id(0) was null"); return null; } if (ids.get(1) == null) { LOG.warn("id(1) was null"); return null; } patientId = ids.get(0).getExtension(); if (patientId != null && !patientId.isEmpty()) { } else { LOG.warn("patient id was not supplied"); return null; } patientAssigningAuthId = ids.get(0).getRoot(); if (patientAssigningAuthId != null && !patientAssigningAuthId.isEmpty()) { LOG.warn("patientAssigningAuthId: " + patientAssigningAuthId); } else { LOG.warn("patient assigning authority was not supplied"); return null; } correlatedPatientId = ids.get(1).getExtension(); if (correlatedPatientId == null || correlatedPatientId.isEmpty()) { LOG.warn("correlatedPatientId was not supplied"); return null; } correlatedPatientAssigningAuthId = ids.get(1).getRoot(); if (correlatedPatientAssigningAuthId != null && !correlatedPatientAssigningAuthId.isEmpty()) { LOG.warn("correlatedPatientAssigningAuthId: " + correlatedPatientAssigningAuthId); } else { LOG.warn("correlatedPatientId assigning authority was not supplied"); return null; } Date newExpirationDate = calculateCorrelationExpirationDate(correlatedPatientAssigningAuthId); CorrelatedIdentifiers correlatedIdentifers = new CorrelatedIdentifiers(); correlatedIdentifers.setCorrelatedPatientAssigningAuthorityId(correlatedPatientAssigningAuthId); correlatedIdentifers.setCorrelatedPatientId(correlatedPatientId); correlatedIdentifers.setPatientId(patientId); correlatedIdentifers.setPatientAssigningAuthorityId(patientAssigningAuthId); correlatedIdentifers.setCorrelationExpirationDate(newExpirationDate); dao.addPatientCorrelation(correlatedIdentifers); AddPatientCorrelationResponseType result = new AddPatientCorrelationResponseType(); result.setMCCIIN000002UV01(AckBuilder.buildAck(addPatientCorrelationRequest)); return result; } PatientCorrelationOrchImpl(CorrelatedIdentifiersDao dao); @Override RetrievePatientCorrelationsResponseType retrievePatientCorrelations(
        PRPAIN201309UV02 retrievePatientCorrelationsRequest, AssertionType assertion); @Override AddPatientCorrelationResponseType addPatientCorrelation(PRPAIN201301UV02 addPatientCorrelationRequest,
        AssertionType assertion); static Date calculateCorrelationExpirationDate(String assigningAuthority); static Date calculateCorrelationExpirationDate(Expiration config); @Override void addPatientCorrelationPLQ(PatientLocationQueryResponseType plqRecords,
        AssertionType assertion);  }
@Test public void addPatientCorrelation() { PatientCorrelationOrchImpl orchImpl = new PatientCorrelationOrchImpl(dao); AddPatientCorrelationResponseType result = orchImpl.addPatientCorrelation(createPRPAIN201301UV02(), createAssertion()); assertEquals(result.getMCCIIN000002UV01().getReceiver().get(0).getDevice().getId() .get(0).getAssigningAuthorityName(), "CONNECT"); }
@Test public void addPatientCorrelationWhenPatientNull() { PatientCorrelationOrchImpl orchImpl = new PatientCorrelationOrchImpl(dao); assertNull(orchImpl.addPatientCorrelation(createPRPAIN201301UV02NullConditions(), createAssertion())); }
@Test public void addPatientCorrelationWhenPatientId0Null() { PatientCorrelationOrchImpl orchImpl = new PatientCorrelationOrchImpl(dao); assertNull(orchImpl.addPatientCorrelation(createPRPAIN201301UV02Id0Null(), createAssertion())); }
@Test public void addPatientCorrelationWhenPatientId1Null() { PatientCorrelationOrchImpl orchImpl = new PatientCorrelationOrchImpl(dao); assertNull(orchImpl.addPatientCorrelation(createPRPAIN201301UV02Id1Null() , createAssertion())); }
@Test public void addPatientCorrelationWhenPatientId0AANull() { PatientCorrelationOrchImpl orchImpl = new PatientCorrelationOrchImpl(dao); assertNull(orchImpl.addPatientCorrelation(createPRPAIN201301UV02Id0AANull() , createAssertion())); }
@Test public void addPatientCorrelationWhenPatientId1AANull() { PatientCorrelationOrchImpl orchImpl = new PatientCorrelationOrchImpl(dao); assertNull(orchImpl.addPatientCorrelation(createPRPAIN201301UV02Id1AANull() , createAssertion())); }