use of net.ihe.gazelle.hl7v3.datatypes.TS in project ipf by oehf.
the class PixV3QueryResponseTransformer method fromPrpa.
/**
* Transforms a full PRPA response into the simplified model. Data loss can occur, as the simplified model is not
* complete.
*
* @param response The full PRPA response to transform.
* @return the simplified response or {@code null} if the input was {@code null}.
*/
public PixV3QueryResponse fromPrpa(final PRPAIN201310UV02Type response) {
if (response == null) {
return null;
}
final PixV3QueryResponse simpleResponse = new PixV3QueryResponse();
simpleResponse.setMessageId(response.getId());
simpleResponse.setSender(this.fromSender(response.getSender()));
if (!response.getReceiver().isEmpty()) {
simpleResponse.setReceiver(this.fromReceiver(response.getReceiver().get(0)));
}
simpleResponse.setCreationTime(Optional.ofNullable(response.getCreationTime()).map(TS::getValue).map(value -> {
try {
return HL7DTM.toZonedDateTime(value);
} catch (final DataTypeException e) {
return null;
}
}).orElse(null));
if (!response.getAcknowledgement().isEmpty()) {
final MCCIMT000300UV01Acknowledgement acknowledgement = response.getAcknowledgement().get(0);
simpleResponse.setAcknowledgementTypeCode(acknowledgement.getTypeCode().getCode());
if (acknowledgement.getTargetMessage() != null) {
simpleResponse.setTargetMessageId(acknowledgement.getTargetMessage().getId());
}
simpleResponse.getAcknowledgementDetails().addAll(acknowledgement.getAcknowledgementDetail());
}
if (response.getControlActProcess() == null) {
return simpleResponse;
}
final PRPAIN201310UV02MFMIMT700711UV01ControlActProcess controlActProcess = response.getControlActProcess();
if (controlActProcess.getQueryByParameter() == null) {
return simpleResponse;
}
final PRPAMT201307UV02QueryByParameter queryByParameter = controlActProcess.getQueryByParameter();
simpleResponse.setQueryId(queryByParameter.getQueryId());
if (queryByParameter.getParameterList() == null) {
return simpleResponse;
}
final PRPAMT201307UV02ParameterList parameterList = queryByParameter.getParameterList();
if (!parameterList.getPatientIdentifier().isEmpty()) {
final List<II> patientIds = parameterList.getPatientIdentifier().get(0).getValue();
if (!patientIds.isEmpty()) {
simpleResponse.setQueryPatientId(patientIds.get(0));
}
}
for (final PRPAMT201307UV02DataSource dataSource : parameterList.getDataSource()) {
if (!dataSource.getValue().isEmpty()) {
simpleResponse.getDataSourceOids().add(dataSource.getValue().get(0).getRoot());
}
}
final MFMIMT700711UV01QueryAck queryAck = controlActProcess.getQueryAck();
if (queryAck != null) {
simpleResponse.setQueryResponseCode(queryAck.getQueryResponseCode().getCode());
}
if (controlActProcess.getSubject().isEmpty()) {
return simpleResponse;
}
final PRPAIN201310UV02MFMIMT700711UV01RegistrationEvent registrationEvent = Optional.ofNullable(controlActProcess.getSubject().get(0).getRegistrationEvent()).orElse(null);
if (registrationEvent == null) {
return simpleResponse;
}
simpleResponse.setCustodianOid(Optional.ofNullable(registrationEvent.getCustodian()).map(MFMIMT700711UV01Custodian::getAssignedEntity).map(COCTMT090003UV01AssignedEntity::getId).map(list -> list.isEmpty() ? null : list.get(0)).map(II::getRoot).orElse(null));
final PRPAMT201304UV02Patient patient = Optional.ofNullable(registrationEvent.getSubject1()).map(PRPAIN201310UV02MFMIMT700711UV01Subject2::getPatient).orElse(null);
if (patient == null) {
return simpleResponse;
}
simpleResponse.setProviderOrganization(Optional.ofNullable(patient.getProviderOrganization()).orElse(null));
if (!patient.getId().isEmpty()) {
simpleResponse.getPatientIds().addAll(patient.getId());
}
if (patient.getPatientPerson() != null) {
if (!patient.getPatientPerson().getName().isEmpty()) {
simpleResponse.setPersonName(patient.getPatientPerson().getName().get(0));
}
simpleResponse.getPersonIds().addAll(patient.getPatientPerson().getId());
simpleResponse.getAsOtherIDs().addAll(patient.getPatientPerson().getAsOtherIDs());
}
return simpleResponse;
}
use of net.ihe.gazelle.hl7v3.datatypes.TS in project ipf by oehf.
the class PixV3QueryResponseTransformer method toPrpa.
/**
* Transforms a simplified response into the full PRPA model.
*
* @param simpleResponse The simplified response to transform.
* @return the PRPA model response or {@code null} if the input was {@code null}.
*/
public PRPAIN201310UV02Type toPrpa(final PixV3QueryResponse simpleResponse) {
if (simpleResponse == null) {
return null;
}
// Prepare response with fixed values
final PRPAIN201310UV02Type response = new PRPAIN201310UV02Type();
response.setITSVersion("XML_1.0");
response.setInteractionId(new II("2.16.840.1.113883.1.6", "PRPA_IN201310UV02"));
response.setProcessingCode(new CS("P", null, null));
response.setProcessingModeCode(new CS("T", null, null));
response.setAcceptAckCode(new CS("NE", null, null));
final MCCIMT000300UV01Acknowledgement acknowledgement = new MCCIMT000300UV01Acknowledgement();
response.getAcknowledgement().add(acknowledgement);
final PRPAIN201310UV02MFMIMT700711UV01ControlActProcess controlActProcess = new PRPAIN201310UV02MFMIMT700711UV01ControlActProcess();
controlActProcess.setClassCode(ActClassControlAct.CACT);
controlActProcess.setMoodCode(XActMoodIntentEvent.EVN);
controlActProcess.setCode(new CD("PRPA_TE201310UV02", null, null));
response.setControlActProcess(controlActProcess);
final MFMIMT700711UV01QueryAck queryAck = new MFMIMT700711UV01QueryAck();
controlActProcess.setQueryAck(queryAck);
final PRPAMT201307UV02QueryByParameter queryByParameter = new PRPAMT201307UV02QueryByParameter();
queryByParameter.setStatusCode(new CS("new", null, null));
queryByParameter.setResponsePriorityCode(new CS("I", null, null));
queryByParameter.setParameterList(new PRPAMT201307UV02ParameterList());
controlActProcess.setQueryByParameter(queryByParameter);
// Fill response with given data
response.setCreationTime(new TS());
response.getCreationTime().setValue(HL7DTM.toSimpleString(simpleResponse.getCreationTime()));
response.setId(simpleResponse.getMessageId());
response.setReceiver(List.of(toReceiver(simpleResponse.getReceiver())));
response.setSender(toSender(simpleResponse.getSender()));
queryByParameter.setQueryId(simpleResponse.getQueryId());
final PRPAMT201307UV02PatientIdentifier patientIdentifier = new PRPAMT201307UV02PatientIdentifier();
patientIdentifier.setValue(List.of(simpleResponse.getQueryPatientId()));
patientIdentifier.setSemanticsText(new ST());
patientIdentifier.getSemanticsText().mixed = List.of("Patient.id");
queryByParameter.getParameterList().setPatientIdentifier(List.of(patientIdentifier));
for (final String dataSourceOid : simpleResponse.getDataSourceOids()) {
final PRPAMT201307UV02DataSource dataSource = new PRPAMT201307UV02DataSource();
dataSource.setValue(List.of(new II(dataSourceOid, null)));
dataSource.setSemanticsText(new ST());
dataSource.getSemanticsText().mixed = List.of("DataSource.id");
queryByParameter.getParameterList().getDataSource().add(dataSource);
}
acknowledgement.setTypeCode(new CS(simpleResponse.getAcknowledgementTypeCode(), null, null));
acknowledgement.setTargetMessage(new MCCIMT000300UV01TargetMessage());
acknowledgement.getTargetMessage().setId(simpleResponse.getTargetMessageId());
acknowledgement.getAcknowledgementDetail().addAll(simpleResponse.getAcknowledgementDetails());
queryAck.setQueryId(simpleResponse.getQueryId());
queryAck.setQueryResponseCode(new CS(simpleResponse.getQueryResponseCode(), null, null));
queryAck.setStatusCode(new CS("deliveredResponse", null, null));
if (!"OK".equals(simpleResponse.getQueryResponseCode())) {
// If the query response code is not OK, no RegistrationEvent shall be returned
return response;
}
final PRPAIN201310UV02MFMIMT700711UV01Subject1 subject = new PRPAIN201310UV02MFMIMT700711UV01Subject1();
subject.setTypeCode("SUBJ");
controlActProcess.getSubject().add(subject);
final PRPAIN201310UV02MFMIMT700711UV01RegistrationEvent registrationEvent = new PRPAIN201310UV02MFMIMT700711UV01RegistrationEvent();
registrationEvent.setStatusCode(new CS("ACTIVE", null, null));
registrationEvent.setClassCode(ActClass.REG);
registrationEvent.setMoodCode(ActMood.EVN);
subject.setRegistrationEvent(registrationEvent);
final PRPAIN201310UV02MFMIMT700711UV01Subject2 subject1 = new PRPAIN201310UV02MFMIMT700711UV01Subject2();
subject1.setTypeCode(ParticipationTargetSubject.SBJ);
registrationEvent.setSubject1(subject1);
final PRPAMT201304UV02Patient patient = new PRPAMT201304UV02Patient();
patient.setClassCode("PAT");
patient.setStatusCode(new CS("ACTIVE", null, null));
patient.setId(simpleResponse.getPatientIds());
patient.setProviderOrganization(simpleResponse.getProviderOrganization());
subject1.setPatient(patient);
final PRPAMT201304UV02Person person = new PRPAMT201304UV02Person();
person.setClassCode(EntityClass.PSN);
person.setDeterminerCode(EntityDeterminer.INSTANCE);
if (simpleResponse.getPersonName() != null) {
person.getName().add(simpleResponse.getPersonName());
}
person.getId().addAll(simpleResponse.getPersonIds());
person.getAsOtherIDs().addAll(simpleResponse.getAsOtherIDs());
patient.setPatientPerson(person);
final MFMIMT700711UV01Custodian custodian = new MFMIMT700711UV01Custodian();
custodian.setTypeCode(ParticipationType.CST);
registrationEvent.setCustodian(custodian);
final COCTMT090003UV01AssignedEntity assignedEntity = new COCTMT090003UV01AssignedEntity();
assignedEntity.setClassCode(RoleClassAssignedEntity.ASSIGNED);
assignedEntity.getId().add(new II(simpleResponse.getCustodianOid(), null));
custodian.setAssignedEntity(assignedEntity);
return response;
}
use of net.ihe.gazelle.hl7v3.datatypes.TS in project ipf by oehf.
the class PixV3QueryRequestTransformer method fromPrpa.
/**
* Transforms a full PRPA query into the simplified model. Data loss can occur, as the simplified model is not
* complete.
*
* @param query The full PRPA query to transform.
* @return the simplified query or {@code null} if the input was {@code null}.
*/
public PixV3QueryRequest fromPrpa(final PRPAIN201309UV02Type query) {
if (query == null) {
return null;
}
final PixV3QueryRequest simpleQuery = new PixV3QueryRequest();
simpleQuery.setMessageId(query.getId());
simpleQuery.setSender(this.fromSender(query.getSender()));
if (!query.getReceiver().isEmpty()) {
simpleQuery.setReceiver(this.fromReceiver(query.getReceiver().get(0)));
}
simpleQuery.setCreationTime(Optional.ofNullable(query.getCreationTime()).map(TS::getValue).map(value -> {
try {
return HL7DTM.toZonedDateTime(value);
} catch (final DataTypeException e) {
return null;
}
}).orElse(null));
if (query.getControlActProcess() == null) {
return simpleQuery;
}
final PRPAIN201309UV02QUQIMT021001UV01ControlActProcess controlActProcess = query.getControlActProcess();
if (controlActProcess.getQueryByParameter() == null) {
return simpleQuery;
}
final PRPAMT201307UV02QueryByParameter queryByParameter = controlActProcess.getQueryByParameter();
simpleQuery.setQueryId(queryByParameter.getQueryId());
if (queryByParameter.getParameterList() == null) {
return simpleQuery;
}
final PRPAMT201307UV02ParameterList parameterList = queryByParameter.getParameterList();
if (!parameterList.getPatientIdentifier().isEmpty()) {
final List<II> patientIds = parameterList.getPatientIdentifier().get(0).getValue();
if (!patientIds.isEmpty()) {
simpleQuery.setQueryPatientId(patientIds.get(0));
}
}
for (final PRPAMT201307UV02DataSource dataSource : parameterList.getDataSource()) {
if (!dataSource.getValue().isEmpty()) {
simpleQuery.getDataSourceOids().add(dataSource.getValue().get(0).getRoot());
}
}
return simpleQuery;
}
use of net.ihe.gazelle.hl7v3.datatypes.TS in project MobileAccessGateway by i4mi.
the class Iti104UpdateRequestConverter method doUpdate.
public String doUpdate(Patient in, Identifier identifier) throws JAXBException {
PRPAIN201302UV02Type resultMsg = new PRPAIN201302UV02Type();
resultMsg.setITSVersion("XML_1.0");
// String UUID.randomUUID().toString();
resultMsg.setId(new II(config.getPixQueryOid(), uniqueId()));
// Now
resultMsg.setCreationTime(new TS(Timestamp.now().toHL7()));
resultMsg.setProcessingCode(new CS("T", null, null));
resultMsg.setProcessingModeCode(new CS("T", null, null));
resultMsg.setInteractionId(new II("2.16.840.1.113883.1.18", "PRPA_IN201302UV02"));
resultMsg.setAcceptAckCode(new CS("AL", null, null));
MCCIMT000100UV01Receiver receiver = new MCCIMT000100UV01Receiver();
resultMsg.addReceiver(receiver);
receiver.setTypeCode(CommunicationFunctionType.RCV);
MCCIMT000100UV01Device receiverDevice = new MCCIMT000100UV01Device();
receiver.setDevice(receiverDevice);
receiverDevice.setClassCode(EntityClassDevice.DEV);
receiverDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
receiverDevice.setId(Collections.singletonList(new II(config.getPixReceiverOid(), null)));
MCCIMT000100UV01Sender sender = new MCCIMT000100UV01Sender();
resultMsg.setSender(sender);
sender.setTypeCode(CommunicationFunctionType.SND);
MCCIMT000100UV01Device senderDevice = new MCCIMT000100UV01Device();
sender.setDevice(senderDevice);
senderDevice.setClassCode(EntityClassDevice.DEV);
senderDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
senderDevice.setId(Collections.singletonList(new II(config.getPixMySenderOid(), null)));
PRPAIN201302UV02MFMIMT700701UV01ControlActProcess controlActProcess = new PRPAIN201302UV02MFMIMT700701UV01ControlActProcess();
resultMsg.setControlActProcess(controlActProcess);
controlActProcess.setClassCode(ActClassControlAct.CACT);
controlActProcess.setMoodCode(XActMoodIntentEvent.EVN);
controlActProcess.setCode(new CD("PRPA_TE201302UV02", "2.16.840.1.113883.1.18", null));
PRPAIN201302UV02MFMIMT700701UV01Subject1 subject = new PRPAIN201302UV02MFMIMT700701UV01Subject1();
controlActProcess.addSubject(subject);
subject.setTypeCode("SUBJ");
// ???
subject.setContextConductionInd(false);
PRPAIN201302UV02MFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201302UV02MFMIMT700701UV01RegistrationEvent();
subject.setRegistrationEvent(registrationEvent);
registrationEvent.setClassCode(ActClass.REG);
registrationEvent.setMoodCode(ActMood.EVN);
// ???
registrationEvent.setStatusCode(new CS("active", null, null));
PRPAIN201302UV02MFMIMT700701UV01Subject2 subject1 = new PRPAIN201302UV02MFMIMT700701UV01Subject2();
registrationEvent.setSubject1(subject1);
subject1.setTypeCode(ParticipationTargetSubject.SBJ);
PRPAMT201302UV02Patient patient = new PRPAMT201302UV02Patient();
subject1.setPatient(patient);
patient.setClassCode("PAT");
PRPAMT201302UV02PatientStatusCode statusCode = new PRPAMT201302UV02PatientStatusCode();
statusCode.setCode("active");
// ???
patient.setStatusCode(statusCode);
PRPAMT201302UV02PatientPatientPerson patientPerson = new PRPAMT201302UV02PatientPatientPerson();
patient.setPatientPerson(patientPerson);
patientPerson.setClassCode(EntityClass.PSN);
patientPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
patientPerson.setAsOtherIDs(new ArrayList());
List<II> orgIds = new ArrayList<II>();
Set<String> mainIds = new HashSet<String>();
Organization managingOrg = getManagingOrganization(in);
// NULL POINTER CHECK
if (managingOrg != null) {
for (Identifier id : managingOrg.getIdentifier()) {
orgIds.add(new II(getScheme(id.getSystem()), null));
mainIds.add(id.getSystem());
}
} else {
Reference org = in.getManagingOrganization();
if (org != null && org.getIdentifier() != null) {
orgIds.add(new II(getScheme(org.getIdentifier().getSystem()), null));
mainIds.add(org.getIdentifier().getSystem());
}
}
// TODO How is the correct mapping done?
for (Identifier id : in.getIdentifier()) {
boolean isOwn = mainIds.contains(id.getSystem());
if (isOwn)
patient.addId(patientIdentifierUpd(id));
else {
PRPAMT201302UV02OtherIDs asOtherIDs = new PRPAMT201302UV02OtherIDs();
PRPAMT201302UV02OtherIDsId id2 = new PRPAMT201302UV02OtherIDsId();
id2.setRoot(getScheme(id.getSystem()));
id2.setExtension(id.getValue());
asOtherIDs.setClassCode("PAT");
asOtherIDs.setId(Collections.singletonList(id2));
COCTMT150002UV01Organization scopingOrganization = new COCTMT150002UV01Organization();
scopingOrganization.setClassCode(EntityClassOrganization.ORG);
scopingOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
List<II> scopeOrgIds = new ArrayList<II>();
scopeOrgIds.add(new II(getScheme(id.getSystem()), null));
scopingOrganization.setId(scopeOrgIds);
asOtherIDs.setScopingOrganization(scopingOrganization);
patientPerson.addAsOtherIDs(asOtherIDs);
}
}
for (HumanName name : in.getName()) {
patientPerson.addName(transform(name));
}
patientPerson.setBirthTime(transform(in.getBirthDateElement()));
if (in.hasGender()) {
switch(in.getGender()) {
case MALE:
patientPerson.setAdministrativeGenderCode(new CE("M", "Male", "2.16.840.1.113883.12.1"));
break;
case FEMALE:
patientPerson.setAdministrativeGenderCode(new CE("F", "Female", "2.16.840.1.113883.12.1"));
break;
case OTHER:
patientPerson.setAdministrativeGenderCode(new CE("A", "Ambiguous", "2.16.840.1.113883.12.1"));
break;
case UNKNOWN:
patientPerson.setAdministrativeGenderCode(new CE("U", "Unknown", "2.16.840.1.113883.12.1"));
break;
}
}
if (in.hasAddress())
patientPerson.setAddr(new ArrayList<AD>());
for (Address address : in.getAddress()) {
patientPerson.addAddr(transform(address));
}
for (ContactPoint contactPoint : in.getTelecom()) {
patientPerson.addTelecom(transform(contactPoint));
}
if (in.hasDeceasedBooleanType()) {
patientPerson.setDeceasedInd(new BL(in.getDeceasedBooleanType().getValue()));
}
if (in.hasDeceasedDateTimeType()) {
patientPerson.setDeceasedTime(transform(in.getDeceasedDateTimeType()));
}
if (in.hasMultipleBirthBooleanType()) {
patientPerson.setMultipleBirthInd(new BL(in.getMultipleBirthBooleanType().getValue()));
}
if (in.hasMultipleBirthIntegerType()) {
patientPerson.setMultipleBirthOrderNumber(new INT(in.getMultipleBirthIntegerType().getValue()));
}
if (in.hasMaritalStatus()) {
patientPerson.setMaritalStatusCode(transform(in.getMaritalStatus()));
}
if (in.hasCommunication()) {
for (PatientCommunicationComponent pcc : in.getCommunication()) {
PRPAMT201302UV02LanguageCommunication languageCommunication = new PRPAMT201302UV02LanguageCommunication();
languageCommunication.setLanguageCode(transform(pcc.getLanguage()));
if (pcc.hasPreferred())
languageCommunication.setPreferenceInd(new BL(pcc.getPreferred()));
patientPerson.addLanguageCommunication(languageCommunication);
}
}
COCTMT150003UV03Organization providerOrganization = new COCTMT150003UV03Organization();
patient.setProviderOrganization(providerOrganization);
providerOrganization.setClassCode(EntityClassOrganization.ORG);
providerOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
providerOrganization.setId(orgIds);
ON name = null;
if (managingOrg.hasName()) {
name = new ON();
name.setMixed(Collections.singletonList(managingOrg.getName()));
providerOrganization.setName(Collections.singletonList(name));
}
COCTMT150003UV03ContactParty contactParty = new COCTMT150003UV03ContactParty();
contactParty.setClassCode(RoleClassContact.CON);
for (ContactPoint contactPoint : managingOrg.getTelecom()) {
contactParty.addTelecom(transform(contactPoint));
}
if (managingOrg.hasAddress())
contactParty.setAddr(new ArrayList<AD>());
for (Address address : managingOrg.getAddress()) {
contactParty.addAddr(transform(address));
}
if (managingOrg.hasContact()) {
OrganizationContactComponent occ = managingOrg.getContactFirstRep();
COCTMT150003UV03Person contactPerson = new COCTMT150003UV03Person();
contactPerson.setClassCode(EntityClass.PSN);
contactPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
if (occ.hasName())
contactPerson.setName(Collections.singletonList(transform(occ.getName())));
contactParty.setContactPerson(contactPerson);
}
providerOrganization.setContactParty(Collections.singletonList(contactParty));
MFMIMT700701UV01Custodian custodian = new MFMIMT700701UV01Custodian();
registrationEvent.setCustodian(custodian);
custodian.setTypeCode(ParticipationType.CST);
COCTMT090003UV01AssignedEntity assignedEntity = new COCTMT090003UV01AssignedEntity();
custodian.setAssignedEntity(assignedEntity);
assignedEntity.setClassCode(RoleClassAssignedEntity.ASSIGNED);
List<II> custIds = new ArrayList<II>();
custIds.add(new II(getScheme(config.getCustodianOid()), null));
assignedEntity.setId(custIds);
// assignedEntity.setId(orgIds);
COCTMT090003UV01Organization assignedOrganization = new COCTMT090003UV01Organization();
assignedEntity.setAssignedOrganization(assignedOrganization);
assignedOrganization.setClassCode(EntityClassOrganization.ORG);
assignedOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
if (managingOrg.hasName()) {
assignedOrganization.setName(Collections.singletonList(name));
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
HL7V3Transformer.marshallMessage(PRPAIN201302UV02Type.class, out, resultMsg);
String outArray = new String(out.toByteArray());
return outArray;
}
use of net.ihe.gazelle.hl7v3.datatypes.TS in project MobileAccessGateway by i4mi.
the class Iti78RequestConverter method iti78ToIti47Converter.
public String iti78ToIti47Converter(@Header("FhirRequestParameters") Iti78SearchParameters parameters) throws JAXBException {
PRPAIN201305UV02Type resultMsg = new PRPAIN201305UV02Type();
resultMsg.setITSVersion("XML_1.0");
resultMsg.setId(new II(config.getPixQueryOid(), uniqueId()));
// Now
resultMsg.setCreationTime(new TS(Timestamp.now().toHL7()));
resultMsg.setProcessingCode(new CS("T", null, null));
resultMsg.setProcessingModeCode(new CS("T", null, null));
resultMsg.setInteractionId(new II("2.16.840.1.113883.1.6", "PRPA_IN201305UV02"));
resultMsg.setAcceptAckCode(new CS("AL", null, null));
MCCIMT000100UV01Receiver receiver = new MCCIMT000100UV01Receiver();
resultMsg.addReceiver(receiver);
receiver.setTypeCode(CommunicationFunctionType.RCV);
MCCIMT000100UV01Device receiverDevice = new MCCIMT000100UV01Device();
receiver.setDevice(receiverDevice);
receiverDevice.setClassCode(EntityClassDevice.DEV);
receiverDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
receiverDevice.setId(Collections.singletonList(new II(config.getPixReceiverOid(), null)));
MCCIMT000100UV01Sender sender = new MCCIMT000100UV01Sender();
resultMsg.setSender(sender);
sender.setTypeCode(CommunicationFunctionType.SND);
MCCIMT000100UV01Device senderDevice = new MCCIMT000100UV01Device();
sender.setDevice(senderDevice);
senderDevice.setClassCode(EntityClassDevice.DEV);
senderDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
senderDevice.setId(Collections.singletonList(new II(config.getPixMySenderOid(), null)));
PRPAIN201305UV02QUQIMT021001UV01ControlActProcess controlActProcess = new PRPAIN201305UV02QUQIMT021001UV01ControlActProcess();
resultMsg.setControlActProcess(controlActProcess);
controlActProcess.setClassCode(ActClassControlAct.CACT);
controlActProcess.setMoodCode(XActMoodIntentEvent.EVN);
controlActProcess.setCode(new CD("PRPA_TE201305UV02", "2.16.840.1.113883.1.6", null));
PRPAMT201306UV02QueryByParameter queryByParameter = new PRPAMT201306UV02QueryByParameter();
controlActProcess.setQueryByParameter(queryByParameter);
queryByParameter.setQueryId(new II(config.getPixQueryOid(), uniqueId()));
queryByParameter.setStatusCode(new CS("new", null, null));
queryByParameter.setResponsePriorityCode(new CS("I", null, null));
queryByParameter.setResponseModalityCode(new CS("R", null, null));
PRPAMT201306UV02ParameterList parameterList = new PRPAMT201306UV02ParameterList();
queryByParameter.setParameterList(parameterList);
TokenParam id = parameters.get_id();
if (id != null) {
String v = id.getValue();
int idx = v.indexOf("-");
if (idx > 0) {
PRPAMT201306UV02LivingSubjectId livingSubjectId = new PRPAMT201306UV02LivingSubjectId();
livingSubjectId.addValue(new II(v.substring(0, idx), v.substring(idx + 1)));
livingSubjectId.setSemanticsText(ST("LivingSubject.id"));
parameterList.addLivingSubjectId(livingSubjectId);
}
}
// active -> patientStatusCode
TokenParam active = parameters.getActive();
if (active != null) {
String activeCode = "active";
PRPAMT201306UV02PatientStatusCode patientStatusCode = new PRPAMT201306UV02PatientStatusCode();
patientStatusCode.setValue(new CS(activeCode, null, null));
parameterList.addPatientStatusCode(patientStatusCode);
}
// patientAddress
StringParam postalCode = parameters.getPostalCode();
StringParam state = parameters.getState();
StringParam city = parameters.getCity();
StringParam country = parameters.getCountry();
StringParam address = parameters.getAddress();
if (postalCode != null || state != null || city != null || country != null || address != null) {
PRPAMT201306UV02PatientAddress patientAddress = new PRPAMT201306UV02PatientAddress();
AD ad = new AD();
if (postalCode != null)
ad.addPostalCode(element(AdxpPostalCode.class, postalCode.getValue()));
if (state != null)
ad.addState(element(AdxpState.class, state.getValue()));
if (city != null)
ad.addCity(element(AdxpCity.class, city.getValue()));
if (country != null)
ad.addCountry(element(AdxpCountry.class, country.getValue()));
// TODO How to support address filter?
patientAddress.addValue(ad);
patientAddress.setSemanticsText(ST("Patient.addr"));
parameterList.addPatientAddress(patientAddress);
}
// livingSubjectBirthTime
DateAndListParam birthdate = parameters.getBirthDate();
if (birthdate != null) {
IVLTS ivlts = new IVLTS();
for (DateOrListParam birthdateOr : birthdate.getValuesAsQueryTokens()) {
for (DateParam birthdateParam : birthdateOr.getValuesAsQueryTokens()) {
Date lDate = null;
Date hDate = null;
TemporalPrecisionEnum precision = birthdateParam.getPrecision();
ParamPrefixEnum prefix = birthdateParam.getPrefix();
if (prefix == null)
prefix = ParamPrefixEnum.EQUAL;
Calendar cal = Calendar.getInstance();
cal.setTime(birthdateParam.getValue());
switch(precision) {
case SECOND:
cal.set(Calendar.MILLISECOND, 0);
lDate = cal.getTime();
cal.set(Calendar.MILLISECOND, 1000);
hDate = cal.getTime();
break;
case MINUTE:
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
lDate = cal.getTime();
cal.add(Calendar.MINUTE, 1);
hDate = cal.getTime();
break;
case DAY:
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.HOUR_OF_DAY, 0);
lDate = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH, 1);
hDate = cal.getTime();
break;
case MONTH:
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
cal.set(year, month, 1, 0, 0, 0);
lDate = cal.getTime();
cal.add(Calendar.MONTH, 1);
hDate = cal.getTime();
break;
case YEAR:
year = cal.get(Calendar.YEAR);
cal.set(year, 0, 1, 0, 0, 0);
lDate = cal.getTime();
cal.add(Calendar.YEAR, 1);
hDate = cal.getTime();
break;
case MILLI:
default:
lDate = cal.getTime();
cal.add(Calendar.MILLISECOND, 1);
hDate = cal.getTime();
break;
}
switch(prefix) {
case GREATERTHAN:
ivlts.setLow(transformTest(hDate));
break;
case LESSTHAN:
ivlts.setHigh(transformTest(lDate));
break;
case GREATERTHAN_OR_EQUALS:
ivlts.setLow(transformTest(lDate));
break;
case LESSTHAN_OR_EQUALS:
ivlts.setHigh(transformTest(hDate));
break;
case STARTS_AFTER:
ivlts.setLow(transformTest(hDate));
break;
case ENDS_BEFORE:
ivlts.setHigh(transformTest(lDate));
break;
case EQUAL:
case APPROXIMATE:
ivlts.setLow(transformTest(lDate));
ivlts.setHigh(transformTest(hDate));
ivlts.setCenter(transform(lDate));
break;
//
default:
throw new InvalidRequestException("Date operation not supported.");
}
}
}
PRPAMT201306UV02LivingSubjectBirthTime livingSubjectBirthTime = new PRPAMT201306UV02LivingSubjectBirthTime();
livingSubjectBirthTime.addValue(ivlts);
livingSubjectBirthTime.setSemanticsText(ST("LivingSubject.birthTime"));
parameterList.addLivingSubjectBirthTime(livingSubjectBirthTime);
}
// given, family -> livingSubjectName
StringAndListParam given = parameters.getGiven();
StringAndListParam family = parameters.getFamily();
StringParam givenElem = given != null ? given.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0) : null;
StringParam familyElem = family != null ? family.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0) : null;
if (givenElem != null || familyElem != null) {
PRPAMT201306UV02LivingSubjectName livingSubjectName = new PRPAMT201306UV02LivingSubjectName();
livingSubjectName.setSemanticsText(ST("Patient.name"));
EN name = new EN();
if (familyElem != null) {
name.addFamily(element(EnFamily.class, familyElem.getValue()));
if (!familyElem.isExact())
name.setUse("SRCH");
}
if (givenElem != null) {
name.addGiven(element(EnGiven.class, givenElem.getValue()));
if (!givenElem.isExact())
name.setUse("SRCH");
}
livingSubjectName.addValue(name);
livingSubjectName.setSemanticsText(ST("LivingSubject.name"));
parameterList.addLivingSubjectName(livingSubjectName);
}
// gender -> livingSubjectAdministrativeGender
TokenParam gender = parameters.getGender();
if (gender != null) {
PRPAMT201306UV02LivingSubjectAdministrativeGender livingSubjectAdministrativeGender = new PRPAMT201306UV02LivingSubjectAdministrativeGender();
switch(gender.getValue().toUpperCase()) {
case "MALE":
livingSubjectAdministrativeGender.addValue(new CE("M", "Male", "2.16.840.1.113883.12.1"));
break;
case "FEMALE":
livingSubjectAdministrativeGender.addValue(new CE("F", "Female", "2.16.840.1.113883.12.1"));
break;
case "OTHER":
livingSubjectAdministrativeGender.addValue(new CE("A", "Ambiguous", "2.16.840.1.113883.12.1"));
break;
case "UNKNOWN":
livingSubjectAdministrativeGender.addValue(new CE("U", "Unknown", "2.16.840.1.113883.12.1"));
break;
default:
throw new InvalidRequestException("Unknown gender query parameter value");
}
livingSubjectAdministrativeGender.setSemanticsText(ST("LivingSubject.administrativeGender"));
parameterList.addLivingSubjectAdministrativeGender(livingSubjectAdministrativeGender);
}
// identifiers -> livingSubjectId or otherIDsScopingOrganization
TokenAndListParam identifiers = parameters.getIdentifiers();
if (identifiers != null) {
for (TokenOrListParam idOr : identifiers.getValuesAsQueryTokens()) {
for (TokenParam identifier : idOr.getValuesAsQueryTokens()) {
if (identifier.getValue() == null || identifier.getValue().length() == 0) {
PRPAMT201306UV02OtherIDsScopingOrganization otherIDsScopingOrganization = new PRPAMT201306UV02OtherIDsScopingOrganization();
otherIDsScopingOrganization.addValue(new II(getScheme(identifier.getSystem()), null));
otherIDsScopingOrganization.setSemanticsText(ST("OtherIDs.scopingOrganization.id"));
parameterList.addOtherIDsScopingOrganization(otherIDsScopingOrganization);
} else {
PRPAMT201306UV02LivingSubjectId livingSubjectId = new PRPAMT201306UV02LivingSubjectId();
livingSubjectId.addValue(new II(getScheme(identifier.getSystem()), identifier.getValue()));
livingSubjectId.setSemanticsText(ST("LivingSubject.id"));
parameterList.addLivingSubjectId(livingSubjectId);
}
}
}
}
// mothersMaidenName -> mothersMaidenName
StringParam mmn = parameters.getMothersMaidenName();
if (mmn != null) {
PRPAMT201306UV02MothersMaidenName mothersMaidenName = new PRPAMT201306UV02MothersMaidenName();
PN mothersMaidenNamePN = new PN();
mothersMaidenNamePN.addGiven(element(EnGiven.class, mmn.getValue()));
mothersMaidenName.addValue(mothersMaidenNamePN);
mothersMaidenName.setSemanticsText(ST("Person.MothersMaidenName"));
parameterList.addMothersMaidenName(mothersMaidenName);
}
// telecom -> patientTelecom
StringParam telecom = parameters.getTelecom();
if (telecom != null) {
PRPAMT201306UV02PatientTelecom patientTelecom = new PRPAMT201306UV02PatientTelecom();
TEL tel = new TEL();
tel.setValue(telecom.getValue());
patientTelecom.addValue(tel);
parameterList.addPatientTelecom(patientTelecom);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
HL7V3Transformer.marshallMessage(PRPAIN201305UV02Type.class, out, resultMsg);
String outArray = new String(out.toByteArray());
return outArray;
}
Aggregations