<commit_before>package org.rippleosi.patient.contacts.store;

import java.util.HashMap;
import java.util.Map;

import org.apache.camel.Consume;
import org.rippleosi.common.service.AbstractOpenEhrService;
import org.rippleosi.common.service.CreateStrategy;
import org.rippleosi.common.service.DefaultStoreStrategy;
import org.rippleosi.common.service.UpdateStrategy;
import org.rippleosi.patient.contacts.model.ContactDetails;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 */
@Service
public class OpenEHRContactStore extends AbstractOpenEhrService implements ContactStore {

    @Value("${openehr.contactsTemplate}")
    private String contactsTemplate;

    private static final String CONTACT_PREFIX = "relevant_contacts/relevant_contacts:0/relevant_contact:0";

    @Override
    @Consume(uri = "activemq:Consumer.OpenEHR.VirtualTopic.Ripple.Contacts.Create")
    public void create(String patientId, ContactDetails contact) {

        Map<String,Object> content = createFlatJsonContent(contact);

        CreateStrategy createStrategy = new DefaultStoreStrategy(patientId, contactsTemplate, content);

        createData(createStrategy);
    }

    @Override
    @Consume(uri = "activemq:Consumer.OpenEHR.VirtualTopic.Ripple.Contacts.Update")
    public void update(String patientId, ContactDetails contact) {

        Map<String,Object> content = createFlatJsonContent(contact);

        UpdateStrategy updateStrategy = new DefaultStoreStrategy(contact.getSourceId(), patientId, contactsTemplate, content);

        updateData(updateStrategy);
    }

    private Map<String,Object> createFlatJsonContent(ContactDetails contact) {

        Map<String, Object> content = new HashMap<>();

        content.put("ctx/language", "en");
        content.put("ctx/territory", "GB");

        content.put(CONTACT_PREFIX + "/personal_details/person_name/unstructured_name", contact.getName());
        content.put(CONTACT_PREFIX + "/personal_details/telecom_details/unstuctured_telcoms", contact.getContactInformation());
        content.put(CONTACT_PREFIX + "/relationship", contact.getRelationship());
        content.put(CONTACT_PREFIX + "/relationship_category|" + contact.getRelationshipCode(), Boolean.TRUE);
        content.put(CONTACT_PREFIX + "/relationship_category|value", contact.getRelationshipType());
        content.put(CONTACT_PREFIX + "/relationship_category|code", contact.getRelationshipCode());
        content.put(CONTACT_PREFIX + "/relationship_category|terminology", contact.getRelationshipTerminology());
        content.put(CONTACT_PREFIX + "/is_next_of_kin", contact.isNextOfKin());
        content.put(CONTACT_PREFIX + "/note", contact.getNotes());

        return content;
    }
}<commit_msg>Fixed problem where false values have to be converted to "null"<commit_after>package org.rippleosi.patient.contacts.store;

import java.util.HashMap;
import java.util.Map;

import org.apache.camel.Consume;
import org.rippleosi.common.service.AbstractOpenEhrService;
import org.rippleosi.common.service.CreateStrategy;
import org.rippleosi.common.service.DefaultStoreStrategy;
import org.rippleosi.common.service.UpdateStrategy;
import org.rippleosi.patient.contacts.model.ContactDetails;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 */
@Service
public class OpenEHRContactStore extends AbstractOpenEhrService implements ContactStore {

    @Value("${openehr.contactsTemplate}")
    private String contactsTemplate;

    private static final String CONTACT_PREFIX = "relevant_contacts/relevant_contacts:0/relevant_contact:0";

    @Override
    @Consume(uri = "activemq:Consumer.OpenEHR.VirtualTopic.Ripple.Contacts.Create")
    public void create(String patientId, ContactDetails contact) {

        Map<String,Object> content = createFlatJsonContent(contact);

        CreateStrategy createStrategy = new DefaultStoreStrategy(patientId, contactsTemplate, content);

        createData(createStrategy);
    }

    @Override
    @Consume(uri = "activemq:Consumer.OpenEHR.VirtualTopic.Ripple.Contacts.Update")
    public void update(String patientId, ContactDetails contact) {

        Map<String,Object> content = createFlatJsonContent(contact);

        UpdateStrategy updateStrategy = new DefaultStoreStrategy(contact.getSourceId(), patientId, contactsTemplate, content);

        updateData(updateStrategy);
    }

    private Map<String,Object> createFlatJsonContent(ContactDetails contact) {

        Map<String, Object> content = new HashMap<>();

        content.put("ctx/language", "en");
        content.put("ctx/territory", "GB");

        Boolean nextOfKin = contact.isNextOfKin() ? Boolean.TRUE : null;

        content.put(CONTACT_PREFIX + "/personal_details/person_name/unstructured_name", contact.getName());
        content.put(CONTACT_PREFIX + "/personal_details/telecom_details/unstuctured_telcoms", contact.getContactInformation());
        content.put(CONTACT_PREFIX + "/relationship", contact.getRelationship());
        content.put(CONTACT_PREFIX + "/relationship_category|" + contact.getRelationshipCode(), Boolean.TRUE);
        content.put(CONTACT_PREFIX + "/relationship_category|value", contact.getRelationshipType());
        content.put(CONTACT_PREFIX + "/relationship_category|code", contact.getRelationshipCode());
        content.put(CONTACT_PREFIX + "/relationship_category|terminology", contact.getRelationshipTerminology());
        content.put(CONTACT_PREFIX + "/is_next_of_kin", nextOfKin);
        content.put(CONTACT_PREFIX + "/note", contact.getNotes());

        return content;
    }
}
{'fraction_non_alphanumeric': 0.10944659851956291, 'fraction_numerical': 0.0007049700387733521, 'mean_word_length': 4.929989550679206, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5742007', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1541, 'n_words': 259}